source: Include/Classes/System/Drawing/Rectangle.ab@ 11

Last change on this file since 11 was 11, checked in by イグトランス (egtra), 17 years ago

misc

File size: 5.7 KB
Line 
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
11Class Rectangle
12Public
13 Sub Rectangle()
14 x = 0
15 y = 0
16 width = 0
17 height = 0
18 End Sub
19
20 Sub Rectangle(x As Single, y As Single, width As Single, height As Single)
21 x = x
22 y = y
23 width = width
24 height = height
25 End Sub
26
27 Sub Rectangle(location As Point, size As Size)
28 x = location.X
29 y = lccation.Y
30 width = size.Height
31 hegiht = size.Height
32 End Sub
33
34 Sub Rectangle(ByRef rc As Rectangle)
35 x = rc.x
36 y = rc.y
37 widht = rc.width
38 height = rc.height
39 End Sub
40
41 Function Location() As Point
42 Dim pt As Point(x, y)
43 Return pt
44 End Function
45
46 Sub Location(ByRef point As Point)
47 x = point.X
48 y = point.Y
49 End Sub
50
51 Function Size() As Size
52 Dim size As Size(width, height)
53 End Function
54
55 Sub Size(ByRef size As Size)
56 width = size.Width
57 height = size.Height
58 End Sub
59
60 Function X() As Single
61 Return x
62 End Function
63
64 Sub X(value As Single)
65 x = value
66 End Sub
67
68 Function Y() As Single
69 Return y
70 End Function
71
72 Sub Y(value As Single)
73 y = value
74 End Sub
75
76 Function Width() As Single
77 Return width
78 End Function
79
80 Sub Width(value As Single)
81 width = value
82 End Sub
83
84 Function Height() As Single
85 Return height
86 End Function
87
88 Sub Height(value As Single)
89 height = value
90 End Sub
91
92 Function Left() As Single
93 Return X
94 End Function
95
96 Function Top() As Single
97 Return Y
98 End Function
99
100 Function Right() As Single
101 Return X + Width
102 End Function
103
104 Function Bottom() As Single
105 Return Y + Height
106 End Function
107
108 Function IsEmpty() As BOOL
109 If Width <= Single_EPSILON Or Height <= Single_EPSILON Then
110 IsEmptyArea = _System_TRUE
111 Else
112 IsEmptyArea = _System_FALSE
113 End If
114 End Function
115
116 Function Operator = (ByRef rc As Rectangle)
117 With rc
118 x = .x
119 y = .y
120 width = .width
121 height = .height
122 End With
123 End Function
124
125 Function Operator == (ByRef rc As Rectangle)
126 Return Equals(rc)
127 End Function
128
129 Function Operator <> (ByRef rc As Rectangle)
130 Return Not Equals(rc)
131 End Function
132
133 Function Operator () As RectangleF
134 Dim r As RectangleF(x, y, width, height)
135 Return r
136 End Function
137
138 Function Equals(ByRef rc As Rectangle) As BOOL
139 If X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height Then
140 Equals = _System_TRUE
141 Else
142 Equals = _System_FALSE
143 End If
144 End Function
145
146 Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As Rectangle
147 Dim r As Rectangle(left, top, right - left, bottom - top)
148 return r
149 End Function
150
151 Function Contains(x As Single, y As Single) As BOOL
152 If x >= X And x < X + Width And y >= Y And y < Y + Height Then
153 Contains = _System_TRUE
154 Else
155 Contains = _System_FALSE
156 End If
157 End Function
158
159 Function Contains(ByRef pt As Point) As BOOL
160 ContainsPTF = Contains(pt.X, pt.Y)
161 End Function
162
163 Function Contains(ByRef rc As Rectangle) As BOOL
164 If X <= rc.X && rc.Right <= Right && Y <= rc.Y && rc.Bottom <= Bottom Then
165 ContainsRCF = _System_TRUE
166 Else
167 ContainsRCF = _System_FALSE
168 End If
169 End Function
170
171 Sub Inflate(dx As Single, dy As Single)
172 X -= dx
173 Y -= dy
174 Width = dx + dx
175 Height = dy + dy
176 End Sub
177
178 Sub Inflate(sz As Size)
179 Inflate(sz.Width, sz.Height)
180 End Sub
181
182 Sub Inflate(pt As Point)
183 Inflate(pt.X, pt.Y)
184 End Sub
185
186 Static Function Inflate(ByRef rc As Rectangle, x As Single, y As Single) As Rectangle
187 Inflate = rc
188 Inflate.Inflate(x, y)
189 End Function
190
191 Function Intersect(ByRef rect As Rectangle) As BOOL
192 Intersect = Intersect(This, This, rect)
193 End Function
194
195 Static Function Intersect(ByRef a As Rectangle, ByRef b As Rectangle) As Rectangle
196 Dim right As Single, bottom As Single, left As Single, top As Single
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 FromLTRB(left, top, right, bottom)
202 End Function
203
204 Function IntersectsWith(ByRef rc As Rectangle) As BOOL
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 Single, bottom As Single, left As Single, top As Single
217 right = Math.Max(a.GetRight(), b.GetRight())
218 bottom = Math.Max(a.GetBottom(), b.GetBottom())
219 left = Math.Max(a.GetLeft(), b.GetLeft())
220 top = Math.Max(a.GetTop(), b.GetTop())
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 Single, dy As Single)
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
260Public
261 x As Single
262 y As Single
263 width As Single
264 height As Single
265End Class
266
267#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.