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