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

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

Controlがコンパイルできるように修正

File size: 5.2 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
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 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 RECT)
35 x = r.left
36 y = r.top
37 width = r.right - r.left
38 height = r.top - r.bottom
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(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(size As Size)
56 width = size.Width
57 height = size.Height
58 End Sub
59
60 Function X() As Long
61 Return x
62 End Function
63
64 Sub X(value As Long)
65 x = value
66 End Sub
67
68 Function Y() As Long
69 Return y
70 End Function
71
72 Sub Y(value As Long)
73 y = value
74 End Sub
75
76 Function Width() As Long
77 Return width
78 End Function
79
80 Sub Width(value As Long)
81 width = value
82 End Sub
83
84 Function Height() As Long
85 Return height
86 End Function
87
88 Sub Height(value As Long)
89 height = value
90 End Sub
91
92 Function Left() As Long
93 Return X
94 End Function
95
96 Function Top() As Long
97 Return Y
98 End Function
99
100 Function Right() As Long
101 Return X + Width
102 End Function
103
104 Function Bottom() As Long
105 Return Y + Height
106 End Function
107
108 Function IsEmpty() As Boolean
109 Return Width <= 0 Or Height <= 0
110 End Function
111
112 Function Operator == (rc As Rectangle)
113 Return Equals(rc)
114 End Function
115
116 Function Operator <> (rc As Rectangle)
117 Return Not Equals(rc)
118 End Function
119
120 Function Operator () As RectangleF
121 Return New RectangleF(x, y, width, height)
122 End Function
123
124 Function Equals(rc As Rectangle) As Boolean
125 Return X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height
126 End Function
127
128 Override Function GetHashCode() As Long
129 Return x As DWord Xor _System_BSwap(y As DWord) Xor width As DWord Xor _System_BSwap(height As DWord)
130 End Function
131
132 Static Function FromLTRB(l As Long, t As Long, r As Long, b As Long) As Rectangle
133 return New Rectangle(l, t, r - l, b - t)
134 End Function
135
136 Function Contains(x As Long, y As Long) As Boolean
137 Return x >= X And x < X + Width And y >= Y And y < Y + Height
138 End Function
139
140 Function Contains(pt As Point) As Boolean
141 Return Contains(pt.X, pt.Y)
142 End Function
143
144 Function Contains(rc As Rectangle) As Boolean
145 Return X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom
146 End Function
147
148 Sub Inflate(dx As Long, dy As Long)
149 X -= dx
150 Y -= dy
151 Width += dx + dx
152 Height += dy + dy
153 End Sub
154
155 Sub Inflate(sz As Size)
156 Inflate(sz.Width, sz.Height)
157 End Sub
158
159 Static Function Inflate(rc As Rectangle, x As Long, y As Long) As Rectangle
160 Inflate = New Rectangle(rc)
161 Inflate.Inflate(x, y)
162 End Function
163
164 Sub Intersect(rect As Rectangle)
165 This = Rectangle.Intersect(This, rect)
166 End Sub
167
168 Static Function Intersect(a As Rectangle, ByRef b As Rectangle) As Rectangle
169 Dim right As Long, bottom As Long, left As Long, top As Long
170 right = Math.Min(a.Right, b.Right)
171 bottom = Math.Min(a.Bottom, b.Bottom)
172 left = Math.Min(a.Left, b.Left)
173 top = Math.Min(a.Top, b.Top)
174 Return Rectangle.FromLTRB(left, top, right, bottom)
175 End Function
176
177 Function IntersectsWith(rc As Rectangle) As Boolean
178 Return Left < rc.Right And _
179 Top < rc.Bottom And _
180 Right > rc.Left And _
181 Bottom > rc.Top
182 End Function
183
184 Static Function Union(a As Rectangle, b As Rectangle) As Rectangle
185 Dim right As Long, bottom As Long, left As Long, top As Long
186 right = Math.Max(a.Right(), b.Right())
187 bottom = Math.Max(a.Bottom(), b.Bottom())
188 left = Math.Max(a.Left(), b.Left())
189 top = Math.Max(a.Top(), b.Top())
190 Return FromLTRB(left, top, right, bottom)
191 End Function
192
193 Sub Offset(pt As Point)
194 Offset(pt.X, pt.Y)
195 End Sub
196
197 Sub Offset(dx As Long, dy As Long)
198 X += dx
199 Y += dy
200 End Sub
201
202 Static Function Ceiling(rcf As RectangleF) As Rectangle
203 Dim r As Rectangle(
204 Math.Ceiling(rcf.X),
205 Math.Ceiling(rcf.Y),
206 Math.Ceiling(rcf.Width),
207 Math.Ceiling(rcf.Height))
208 Return r
209 End Function
210
211 Static Function Round(rcf As RectangleF) As Rectangle
212 Dim r As Rectangle(
213 Math.Round(rcf.X),
214 Math.Round(rcf.Y),
215 Math.Round(rcf.Width),
216 Math.Round(rcf.Height))
217 Return r
218 End Function
219
220 Static Function Truncate(rcf As RectangleF) As Rectangle
221 Dim r As Rectangle(
222 Math.Truncate(rcf.X),
223 Math.Truncate(rcf.Y),
224 Math.Truncate(rcf.Width),
225 Math.Truncate(rcf.Height))
226 Return r
227 End Function
228
229 Function ToRECT() As RECT
230 With ToRECT
231 .left = x
232 .top = y
233 .right = x + width
234 .bottom = y + height
235 End With
236 End Function
237
238Public
239 x As Long
240 y As Long
241 width As Long
242 height As Long
243End Class
244
245#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.