[11] | 1 | ' Classes/System/Drawing/RectangleF.ab
|
---|
| 2 |
|
---|
| 3 | #ifndef __SYSTEM_DRAWING_RECTANGLEF_AB__
|
---|
| 4 | #define __SYSTEM_DRAWING_RECTANGLEF_AB__
|
---|
| 5 |
|
---|
[335] | 6 | '#include <Classes/System/Math.ab>
|
---|
[11] | 7 | #include <Classes/System/Drawing/PointF.ab>
|
---|
| 8 | #include <Classes/System/Drawing/SizeF.ab>
|
---|
| 9 |
|
---|
| 10 | Class RectangleF
|
---|
| 11 | Public
|
---|
| 12 | Sub RectangleF()
|
---|
| 13 | x = 0
|
---|
| 14 | y = 0
|
---|
| 15 | width = 0
|
---|
| 16 | height = 0
|
---|
| 17 | End Sub
|
---|
| 18 |
|
---|
| 19 | Sub RectangleF(x As Single, y As Single, width As Single, height As Single)
|
---|
| 20 | x = x
|
---|
| 21 | y = y
|
---|
| 22 | width = width
|
---|
| 23 | height = height
|
---|
| 24 | End Sub
|
---|
| 25 |
|
---|
| 26 | Sub RectangleF(location As PointF, size As SizeF)
|
---|
| 27 | x = location.X
|
---|
[32] | 28 | y = location.Y
|
---|
[11] | 29 | width = size.Height
|
---|
[32] | 30 | height = size.Height
|
---|
[11] | 31 | End Sub
|
---|
| 32 |
|
---|
[212] | 33 | Sub RectangleF(rc As RectangleF)
|
---|
[11] | 34 | x = rc.x
|
---|
| 35 | y = rc.y
|
---|
[32] | 36 | width = rc.width
|
---|
[11] | 37 | height = rc.height
|
---|
| 38 | End Sub
|
---|
| 39 |
|
---|
| 40 | Function Location() As PointF
|
---|
| 41 | Dim pt As PointF(x, y)
|
---|
| 42 | Return pt
|
---|
| 43 | End Function
|
---|
| 44 |
|
---|
[212] | 45 | Sub Location(point As PointF)
|
---|
[11] | 46 | x = point.X
|
---|
| 47 | y = point.Y
|
---|
| 48 | End Sub
|
---|
| 49 |
|
---|
| 50 | Function Size() As SizeF
|
---|
| 51 | Dim size As SizeF(width, height)
|
---|
| 52 | End Function
|
---|
| 53 |
|
---|
[212] | 54 | Sub Size(size As SizeF)
|
---|
[11] | 55 | width = size.Width
|
---|
| 56 | height = size.Height
|
---|
| 57 | End Sub
|
---|
| 58 |
|
---|
| 59 | Function X() As Single
|
---|
| 60 | Return x
|
---|
| 61 | End Function
|
---|
| 62 |
|
---|
| 63 | Sub X(value As Single)
|
---|
| 64 | x = value
|
---|
| 65 | End Sub
|
---|
| 66 |
|
---|
| 67 | Function Y() As Single
|
---|
| 68 | Return y
|
---|
| 69 | End Function
|
---|
| 70 |
|
---|
| 71 | Sub Y(value As Single)
|
---|
| 72 | y = value
|
---|
| 73 | End Sub
|
---|
| 74 |
|
---|
| 75 | Function Width() As Single
|
---|
| 76 | Return width
|
---|
| 77 | End Function
|
---|
| 78 |
|
---|
| 79 | Sub Width(value As Single)
|
---|
| 80 | width = value
|
---|
| 81 | End Sub
|
---|
| 82 |
|
---|
| 83 | Function Height() As Single
|
---|
| 84 | Return height
|
---|
| 85 | End Function
|
---|
| 86 |
|
---|
| 87 | Sub Height(value As Single)
|
---|
| 88 | height = value
|
---|
| 89 | End Sub
|
---|
| 90 |
|
---|
| 91 | Function Left() As Single
|
---|
| 92 | Return X
|
---|
| 93 | End Function
|
---|
| 94 |
|
---|
| 95 | Function Top() As Single
|
---|
| 96 | Return Y
|
---|
| 97 | End Function
|
---|
| 98 |
|
---|
| 99 | Function Right() As Single
|
---|
| 100 | Return X + Width
|
---|
| 101 | End Function
|
---|
| 102 |
|
---|
| 103 | Function Bottom() As Single
|
---|
| 104 | Return Y + Height
|
---|
| 105 | End Function
|
---|
| 106 |
|
---|
[104] | 107 | Function IsEmpty() As Boolean
|
---|
[303] | 108 | Return Width <= 0 Or Height <= 0
|
---|
[11] | 109 | End Function
|
---|
[303] | 110 |
|
---|
| 111 | Function Operator ==(rc As RectangleF) As Boolean
|
---|
[11] | 112 | Return Equals(rc)
|
---|
| 113 | End Function
|
---|
| 114 |
|
---|
[303] | 115 | Function Operator <>(rc As RectangleF) As Boolean
|
---|
[11] | 116 | Return Not Equals(rc)
|
---|
| 117 | End Function
|
---|
| 118 |
|
---|
[212] | 119 | Function Equals(rc As RectangleF) As Boolean
|
---|
[303] | 120 | Equals = (X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height)
|
---|
[11] | 121 | End Function
|
---|
| 122 |
|
---|
[166] | 123 | Override Function GetHashCode() As Long
|
---|
| 124 | Return GetDWord(VarPtr(x)) Xor _System_BSwap(GetDWord(VarPtr(y))) Xor GetDWord(VarPtr(width)) Xor _System_BSwap(GetDWord(VarPtr(height)))
|
---|
| 125 | End Function
|
---|
| 126 |
|
---|
[11] | 127 | Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As RectangleF
|
---|
[212] | 128 | return New RectangleF(l, t, r - l, b - t)
|
---|
[11] | 129 | End Function
|
---|
| 130 |
|
---|
[104] | 131 | Function Contains(x As Single, y As Single) As Boolean
|
---|
[303] | 132 | Contains = (x >= X And x < X + Width And y >= Y And y < Y + Height)
|
---|
[11] | 133 | End Function
|
---|
| 134 |
|
---|
[212] | 135 | Function Contains(pt As PointF) As Boolean
|
---|
| 136 | Return Contains(pt.X, pt.Y)
|
---|
[11] | 137 | End Function
|
---|
| 138 |
|
---|
[212] | 139 | Function Contains(rc As RectangleF) As Boolean
|
---|
[303] | 140 | Contains = (X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom)
|
---|
[11] | 141 | End Function
|
---|
| 142 |
|
---|
| 143 | Sub Inflate(dx As Single, dy As Single)
|
---|
[303] | 144 | x -= dx
|
---|
| 145 | y -= dy
|
---|
| 146 | width += dx + dx
|
---|
| 147 | height += dy + dy
|
---|
[11] | 148 | End Sub
|
---|
| 149 |
|
---|
| 150 | Sub Inflate(sz As SizeF)
|
---|
| 151 | Inflate(sz.Width, sz.Height)
|
---|
| 152 | End Sub
|
---|
| 153 |
|
---|
[212] | 154 | Static Function Inflate(rc As RectangleF, x As Single, y As Single) As RectangleF
|
---|
[303] | 155 | Inflate = New RectangleF(rc.X, rc.Y, rc.Width, rc.Height)
|
---|
[11] | 156 | Inflate.Inflate(x, y)
|
---|
| 157 | End Function
|
---|
| 158 |
|
---|
[212] | 159 | Sub Intersect(rect As RectangleF)
|
---|
[303] | 160 | Dim r = RectangleF.Intersect(This, rect)
|
---|
| 161 | x = r.x
|
---|
| 162 | y = r.y
|
---|
| 163 | width = r.width
|
---|
| 164 | height = r.height
|
---|
[32] | 165 | End Sub
|
---|
| 166 |
|
---|
[212] | 167 | Static Function Intersect(a As RectangleF, b As RectangleF) As RectangleF
|
---|
[11] | 168 | Dim right As Single, bottom As Single, left As Single, top As Single
|
---|
[303] | 169 | right = System.Math.Min(a.Right, b.Right)
|
---|
| 170 | bottom = System.Math.Min(a.Bottom, b.Bottom)
|
---|
| 171 | left = System.Math.Min(a.Left, b.Left)
|
---|
| 172 | top = System.Math.Min(a.Top, b.Top)
|
---|
[11] | 173 | Return FromLTRB(left, top, right, bottom)
|
---|
| 174 | End Function
|
---|
| 175 |
|
---|
[212] | 176 | Function IntersectsWith(rc As RectangleF) As Boolean
|
---|
[11] | 177 | If Left < rc.Right And _
|
---|
| 178 | Top < rc.Bottom And _
|
---|
| 179 | Right > rc.Left And _
|
---|
| 180 | Bottom > rc.Top Then
|
---|
[303] | 181 | IntersectsWith = True
|
---|
[11] | 182 | Else
|
---|
[303] | 183 | IntersectsWith = False
|
---|
[11] | 184 | End If
|
---|
| 185 | End Function
|
---|
| 186 |
|
---|
[212] | 187 | Static Function Union(a As RectangleF, b As RectangleF) As RectangleF
|
---|
[11] | 188 | Dim right As Single, bottom As Single, left As Single, top As Single
|
---|
[303] | 189 | right = System.Math.Max(a.Right(), b.Right())
|
---|
| 190 | bottom = System.Math.Max(a.Bottom(), b.Bottom())
|
---|
| 191 | left = System.Math.Max(a.Left(), b.Left())
|
---|
| 192 | top = System.Math.Max(a.Top(), b.Top())
|
---|
[11] | 193 | Return FromLTRB(left, top, right, bottom)
|
---|
| 194 | End Function
|
---|
| 195 |
|
---|
| 196 | Sub Offset(pt As PointF)
|
---|
| 197 | Offset(pt.X, pt.Y)
|
---|
| 198 | End Sub
|
---|
| 199 |
|
---|
| 200 | Sub Offset(dx As Single, dy As Single)
|
---|
[303] | 201 | x += dx
|
---|
| 202 | y += dy
|
---|
[11] | 203 | End Sub
|
---|
| 204 |
|
---|
| 205 | Public
|
---|
| 206 | x As Single
|
---|
| 207 | y As Single
|
---|
| 208 | width As Single
|
---|
| 209 | height As Single
|
---|
| 210 | End Class
|
---|
| 211 |
|
---|
| 212 | #endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
|
---|