source: trunk/Include/Classes/System/Drawing/Rectangle.ab@ 335

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

SPrintF関連の追加。関数FloatToChars, FormatFloatE, FormatIntegerUと列挙体FormatFlags。

File size: 5.5 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) As Boolean
113 Return Equals(rc)
114 End Function
115
116 Function Operator <> (rc As Rectangle) As Boolean
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.X, rc.Y, rc.Width, rc.Height)
161 Inflate.Inflate(x, y)
162 End Function
163
164 Sub Intersect(rect As Rectangle)
165 Dim r = Rectangle.Intersect(This, rect)
166 x = r.x
167 y = r.y
168 width = r.width
169 height = r.height
170 End Sub
171
172 Static Function Intersect(a As Rectangle, ByRef b As Rectangle) As Rectangle
173 Dim right As Long, bottom As Long, left As Long, top As Long
174 right = System.Math.Min(a.Right, b.Right)
175 bottom = System.Math.Min(a.Bottom, b.Bottom)
176 left = System.Math.Min(a.Left, b.Left)
177 top = System.Math.Min(a.Top, b.Top)
178 Return Rectangle.FromLTRB(left, top, right, bottom)
179 End Function
180
181 Function IntersectsWith(rc As Rectangle) As Boolean
182 Return Left < rc.Right And _
183 Top < rc.Bottom And _
184 Right > rc.Left And _
185 Bottom > rc.Top
186 End Function
187
188 Static Function Union(a As Rectangle, b As Rectangle) As Rectangle
189 Dim right As Long, bottom As Long, left As Long, top As Long
190 right = System.Math.Max(a.Right(), b.Right())
191 bottom = System.Math.Max(a.Bottom(), b.Bottom())
192 left = System.Math.Max(a.Left(), b.Left())
193 top = System.Math.Max(a.Top(), b.Top())
194 Return FromLTRB(left, top, right, bottom)
195 End Function
196
197 Sub Offset(pt As Point)
198 Offset(pt.X, pt.Y)
199 End Sub
200
201 Sub Offset(dx As Long, dy As Long)
202 x += dx
203 y += dy
204 End Sub
205
206 Static Function Ceiling(rcf As RectangleF) As Rectangle
207 Dim r As Rectangle(
208 System.Math.Ceiling(rcf.X) As Long,
209 System.Math.Ceiling(rcf.Y) As Long,
210 System.Math.Ceiling(rcf.Width) As Long,
211 System.Math.Ceiling(rcf.Height) As Long)
212 Return r
213 End Function
214
215 Static Function Round(rcf As RectangleF) As Rectangle
216 Dim r As Rectangle(
217 System.Math.Round(rcf.X) As Long,
218 System.Math.Round(rcf.Y) As Long,
219 System.Math.Round(rcf.Width) As Long,
220 System.Math.Round(rcf.Height) As Long)
221 Return r
222 End Function
223
224 Static Function Truncate(rcf As RectangleF) As Rectangle
225 Dim r As Rectangle(
226 System.Math.Truncate(rcf.X) As Long,
227 System.Math.Truncate(rcf.Y) As Long,
228 System.Math.Truncate(rcf.Width) As Long,
229 System.Math.Truncate(rcf.Height) As Long)
230 Return r
231 End Function
232
233 Function ToRECT() As RECT
234 With ToRECT
235 .left = x
236 .top = y
237 .right = x + width
238 .bottom = y + height
239 End With
240 End Function
241
242Public
243 x As Long
244 y As Long
245 width As Long
246 height As Long
247End Class
248
249#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.