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