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

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

GetHashCodeを実装

File size: 5.8 KB
RevLine 
[11]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
[77]20 Sub Rectangle(x As Long, y As Long, width As Long, height As Long)
[11]21 x = x
22 y = y
23 width = width
24 height = height
25 End Sub
26
[77]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
[11]32 End Sub
33
[77]34 Sub Rectangle(ByRef r As Rectangle)
35 x = r.x
36 y = r.y
37 width = r.width
38 height = r.height
[11]39 End Sub
40
[77]41 Sub Rectangle(ByRef r As RECT)
42 This = FromLTRB(r.left, r.top, r.right, r.bottom)
43 End Sub
44
[11]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
[77]64 Function X() As Long
[11]65 Return x
66 End Function
67
[77]68 Sub X(value As Long)
[11]69 x = value
70 End Sub
71
[77]72 Function Y() As Long
[11]73 Return y
74 End Function
75
[77]76 Sub Y(value As Long)
[11]77 y = value
78 End Sub
79
[77]80 Function Width() As Long
[11]81 Return width
82 End Function
83
[77]84 Sub Width(value As Long)
[11]85 width = value
86 End Sub
87
[77]88 Function Height() As Long
[11]89 Return height
90 End Function
91
[77]92 Sub Height(value As Long)
[11]93 height = value
94 End Sub
95
[77]96 Function Left() As Long
[11]97 Return X
98 End Function
99
[77]100 Function Top() As Long
[11]101 Return Y
102 End Function
103
[77]104 Function Right() As Long
[11]105 Return X + Width
106 End Function
107
[77]108 Function Bottom() As Long
[11]109 Return Y + Height
110 End Function
111
[104]112 Function IsEmpty() As Boolean
[28]113 If Width <= 0 Or Height <= 0 Then
114 IsEmpty = _System_TRUE
[11]115 Else
[28]116 IsEmpty = _System_FALSE
[11]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
[104]142 Function Equals(ByRef rc As Rectangle) As Boolean
[11]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
[166]150 Override Function GetHashCode() As Long
151 Return x Xor _System_BSwap(y) Xor width Xor _System_BSwap(height)
152 End Function
153
[77]154 Static Function FromLTRB(l As Long, t As Long, r As Long, b As Long) As Rectangle
[28]155 Dim rect As Rectangle(l, t, r - l, r - b)
156 return rect
[11]157 End Function
158
[104]159 Function Contains(x As Long, y As Long) As Boolean
[11]160 If x >= X And x < X + Width And y >= Y And y < Y + Height Then
161 Contains = _System_TRUE
162 Else
163 Contains = _System_FALSE
164 End If
165 End Function
166
[104]167 Function Contains(ByRef pt As Point) As Boolean
[11]168 ContainsPTF = Contains(pt.X, pt.Y)
169 End Function
170
[104]171 Function Contains(ByRef rc As Rectangle) As Boolean
[28]172 If X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom Then
[11]173 ContainsRCF = _System_TRUE
174 Else
175 ContainsRCF = _System_FALSE
176 End If
177 End Function
178
[77]179 Sub Inflate(dx As Long, dy As Long)
[11]180 X -= dx
181 Y -= dy
[28]182 Width += dx + dx
183 Height += dy + dy
[11]184 End Sub
185
186 Sub Inflate(sz As Size)
187 Inflate(sz.Width, sz.Height)
188 End Sub
189
[77]190 Static Function Inflate(ByRef rc As Rectangle, x As Long, y As Long) As Rectangle
[11]191 Inflate = rc
192 Inflate.Inflate(x, y)
193 End Function
194
[28]195 Sub Intersect(ByRef rect As Rectangle)
196 This = Rectangle.Intersect(This, rect)
197 End Sub
[11]198
199 Static Function Intersect(ByRef a As Rectangle, ByRef b As Rectangle) As Rectangle
[77]200 Dim right As Long, bottom As Long, left As Long, top As Long
[11]201 right = Math.Min(a.Right, b.Right)
202 bottom = Math.Min(a.Bottom, b.Bottom)
203 left = Math.Min(a.Left, b.Left)
204 top = Math.Min(a.Top, b.Top)
[28]205 Return Rectangle.FromLTRB(left, top, right, bottom)
[11]206 End Function
207
[104]208 Function IntersectsWith(ByRef rc As Rectangle) As Boolean
[11]209 If Left < rc.Right And _
210 Top < rc.Bottom And _
211 Right > rc.Left And _
212 Bottom > rc.Top Then
213 IntersectsWith = _System_TRUE
214 Else
215 IntersectsWith = _System_FALSE
216 End If
217 End Function
218
219 Static Function Union(ByRef a As Rectangle, ByRef b As Rectangle) As Rectangle
[77]220 Dim right As Long, bottom As Long, left As Long, top As Long
[28]221 right = Math.Max(a.Right(), b.Right())
222 bottom = Math.Max(a.Bottom(), b.Bottom())
223 left = Math.Max(a.Left(), b.Left())
224 top = Math.Max(a.Top(), b.Top())
[11]225 Return FromLTRB(left, top, right, bottom)
226 End Function
227
228 Sub Offset(pt As Point)
229 Offset(pt.X, pt.Y)
230 End Sub
231
[77]232 Sub Offset(dx As Long, dy As Long)
[11]233 X += dx
234 Y += dy
235 End Sub
236
237 Static Function Ceiling(rcf As RectangleF) As Rectangle
238 Dim r As Rectangle(
239 Math.Ceiling(rcf.X),
240 Math.Ceiling(rcf.Y),
241 Math.Ceiling(rcf.Width),
242 Math.Ceiling(rcf.Height))
243 Return r
244 End Function
245
246 Static Function Round(rcf As RectangleF) As Rectangle
247 Dim r As Rectangle(
248 Math.Round(rcf.X),
249 Math.Round(rcf.Y),
250 Math.Round(rcf.Width),
251 Math.Round(rcf.Height))
252 Return r
253 End Function
254
255 Static Function Truncate(rcf As RectangleF) As Rectangle
256 Dim r As Rectangle(
257 Math.Truncate(rcf.X),
258 Math.Truncate(rcf.Y),
259 Math.Truncate(rcf.Width),
260 Math.Truncate(rcf.Height))
261 Return r
262 End Function
263
[77]264 Function ToRECT() As RECT
265 With ToRECT
266 .left = x
267 .top = y
268 .right = x + width
269 .bottom = y + height
270 End With
271 End Function
272
[11]273Public
[77]274 x As Long
275 y As Long
276 width As Long
277 height As Long
[11]278End Class
279
280#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.