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