[11] | 1 | ' Classes/System/Drawing/RectangleF.ab
|
---|
| 2 |
|
---|
| 3 | #ifndef __SYSTEM_DRAWING_RECTANGLEF_AB__
|
---|
| 4 | #define __SYSTEM_DRAWING_RECTANGLEF_AB__
|
---|
| 5 |
|
---|
| 6 | #include <Classes/System/Math.ab>
|
---|
| 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 |
|
---|
| 33 | Sub RectangleF(ByRef rc As RectangleF)
|
---|
| 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 |
|
---|
| 45 | Sub Location(ByRef point As PointF)
|
---|
| 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 |
|
---|
| 54 | Sub Size(ByRef size As SizeF)
|
---|
| 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
|
---|
[32] | 108 | If Width <= 0 Or Height <= 0 Then
|
---|
| 109 | IsEmpty = _System_TRUE
|
---|
[11] | 110 | Else
|
---|
[32] | 111 | IsEmpty = _System_FALSE
|
---|
[11] | 112 | End If
|
---|
| 113 | End Function
|
---|
| 114 |
|
---|
| 115 | Function Operator = (ByRef rc As RectangleF)
|
---|
| 116 | With rc
|
---|
| 117 | x = .x
|
---|
| 118 | y = .y
|
---|
| 119 | width = .width
|
---|
| 120 | height = .height
|
---|
| 121 | End With
|
---|
| 122 | End Function
|
---|
| 123 |
|
---|
| 124 | Function Operator == (ByRef rc As RectangleF)
|
---|
| 125 | Return Equals(rc)
|
---|
| 126 | End Function
|
---|
| 127 |
|
---|
| 128 | Function Operator <> (ByRef rc As RectangleF)
|
---|
| 129 | Return Not Equals(rc)
|
---|
| 130 | End Function
|
---|
| 131 |
|
---|
[104] | 132 | Function Equals(ByRef rc As RectangleF) As Boolean
|
---|
[11] | 133 | If X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height Then
|
---|
| 134 | Equals = _System_TRUE
|
---|
| 135 | Else
|
---|
| 136 | Equals = _System_FALSE
|
---|
| 137 | End If
|
---|
| 138 | End Function
|
---|
| 139 |
|
---|
| 140 | Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As RectangleF
|
---|
[32] | 141 | Dim rect As RectangleF(l, t, r - l, b - t)
|
---|
| 142 | return rect
|
---|
[11] | 143 | End Function
|
---|
| 144 |
|
---|
[104] | 145 | Function Contains(x As Single, y As Single) As Boolean
|
---|
[11] | 146 | If x >= X And x < X + Width And y >= Y And y < Y + Height Then
|
---|
| 147 | Contains = _System_TRUE
|
---|
| 148 | Else
|
---|
| 149 | Contains = _System_FALSE
|
---|
| 150 | End If
|
---|
| 151 | End Function
|
---|
| 152 |
|
---|
[104] | 153 | Function Contains(ByRef pt As PointF) As Boolean
|
---|
[11] | 154 | ContainsPTF = Contains(pt.X, pt.Y)
|
---|
| 155 | End Function
|
---|
| 156 |
|
---|
[104] | 157 | Function Contains(ByRef rc As RectangleF) As Boolean
|
---|
[32] | 158 | If X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom Then
|
---|
[11] | 159 | ContainsRCF = _System_TRUE
|
---|
| 160 | Else
|
---|
| 161 | ContainsRCF = _System_FALSE
|
---|
| 162 | End If
|
---|
| 163 | End Function
|
---|
| 164 |
|
---|
| 165 | Sub Inflate(dx As Single, dy As Single)
|
---|
| 166 | X -= dx
|
---|
| 167 | Y -= dy
|
---|
[32] | 168 | Width += dx + dx
|
---|
| 169 | Height += dy + dy
|
---|
[11] | 170 | End Sub
|
---|
| 171 |
|
---|
| 172 | Sub Inflate(sz As SizeF)
|
---|
| 173 | Inflate(sz.Width, sz.Height)
|
---|
| 174 | End Sub
|
---|
| 175 |
|
---|
| 176 | Static Function Inflate(ByRef rc As RectangleF, x As Single, y As Single) As RectangleF
|
---|
| 177 | Inflate = rc
|
---|
| 178 | Inflate.Inflate(x, y)
|
---|
| 179 | End Function
|
---|
| 180 |
|
---|
[32] | 181 | Sub Intersect(ByRef rect As RectangleF)
|
---|
| 182 | This = RectangleF.Intersect(This, rect)
|
---|
| 183 | End Sub
|
---|
| 184 |
|
---|
[11] | 185 | Static Function Intersect(ByRef a As RectangleF, ByRef b As RectangleF) As RectangleF
|
---|
| 186 | Dim right As Single, bottom As Single, left As Single, top As Single
|
---|
| 187 | right = Math.Min(a.Right, b.Right)
|
---|
| 188 | bottom = Math.Min(a.Bottom, b.Bottom)
|
---|
| 189 | left = Math.Min(a.Left, b.Left)
|
---|
| 190 | top = Math.Min(a.Top, b.Top)
|
---|
| 191 | Return FromLTRB(left, top, right, bottom)
|
---|
| 192 | End Function
|
---|
| 193 |
|
---|
[104] | 194 | Function IntersectsWith(ByRef rc As RectangleF) As Boolean
|
---|
[11] | 195 | If Left < rc.Right And _
|
---|
| 196 | Top < rc.Bottom And _
|
---|
| 197 | Right > rc.Left And _
|
---|
| 198 | Bottom > rc.Top Then
|
---|
| 199 | IntersectsWith = _System_TRUE
|
---|
| 200 | Else
|
---|
| 201 | IntersectsWith = _System_FALSE
|
---|
| 202 | End If
|
---|
| 203 | End Function
|
---|
| 204 |
|
---|
| 205 | Static Function Union(ByRef a As RectangleF, ByRef b As RectangleF) As RectangleF
|
---|
| 206 | Dim right As Single, bottom As Single, left As Single, top As Single
|
---|
[32] | 207 | right = Math.Max(a.Right(), b.Right())
|
---|
| 208 | bottom = Math.Max(a.Bottom(), b.Bottom())
|
---|
| 209 | left = Math.Max(a.Left(), b.Left())
|
---|
| 210 | top = Math.Max(a.Top(), b.Top())
|
---|
[11] | 211 | Return FromLTRB(left, top, right, bottom)
|
---|
| 212 | End Function
|
---|
| 213 |
|
---|
| 214 | Sub Offset(pt As PointF)
|
---|
| 215 | Offset(pt.X, pt.Y)
|
---|
| 216 | End Sub
|
---|
| 217 |
|
---|
| 218 | Sub Offset(dx As Single, dy As Single)
|
---|
| 219 | X += dx
|
---|
| 220 | Y += dy
|
---|
| 221 | End Sub
|
---|
| 222 |
|
---|
| 223 | Public
|
---|
| 224 | x As Single
|
---|
| 225 | y As Single
|
---|
| 226 | width As Single
|
---|
| 227 | height As Single
|
---|
| 228 | End Class
|
---|
| 229 |
|
---|
| 230 | #endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
|
---|