source: branch/egtra-gdiplus/Classes/System/Drawing/Rectangle.ab@ 711

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

GDI+に対して名前空間で囲ったものの、現在コンパイルできないため分岐させておく

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