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
RevLine 
[11]1' Classes/System/Drawing/Rectangle.ab
2
3#ifndef __SYSTEM_DRAWING_RECTANGLE_AB__
4#define __SYSTEM_DRAWING_RECTANGLE_AB__
5
[223]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>
[11]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 RECT)
[223]35 x = r.left
36 y = r.top
37 width = r.right - r.left
38 height = r.top - r.bottom
[77]39 End Sub
40
[11]41 Function Location() As Point
42 Dim pt As Point(x, y)
43 Return pt
44 End Function
45
[212]46 Sub Location(point As Point)
[11]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
[212]55 Sub Size(size As Size)
[11]56 width = size.Width
57 height = size.Height
58 End Sub
59
[77]60 Function X() As Long
[11]61 Return x
62 End Function
63
[77]64 Sub X(value As Long)
[11]65 x = value
66 End Sub
67
[77]68 Function Y() As Long
[11]69 Return y
70 End Function
71
[77]72 Sub Y(value As Long)
[11]73 y = value
74 End Sub
75
[77]76 Function Width() As Long
[11]77 Return width
78 End Function
79
[77]80 Sub Width(value As Long)
[11]81 width = value
82 End Sub
83
[77]84 Function Height() As Long
[11]85 Return height
86 End Function
87
[77]88 Sub Height(value As Long)
[11]89 height = value
90 End Sub
91
[77]92 Function Left() As Long
[11]93 Return X
94 End Function
95
[77]96 Function Top() As Long
[11]97 Return Y
98 End Function
99
[77]100 Function Right() As Long
[11]101 Return X + Width
102 End Function
103
[77]104 Function Bottom() As Long
[11]105 Return Y + Height
106 End Function
107
[104]108 Function IsEmpty() As Boolean
[223]109 Return Width <= 0 Or Height <= 0
[11]110 End Function
[223]111
[212]112 Function Operator == (rc As Rectangle)
[11]113 Return Equals(rc)
114 End Function
115
[212]116 Function Operator <> (rc As Rectangle)
[11]117 Return Not Equals(rc)
118 End Function
119
120 Function Operator () As RectangleF
[212]121 Return New RectangleF(x, y, width, height)
[11]122 End Function
123
[212]124 Function Equals(rc As Rectangle) As Boolean
[223]125 Return X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height
[11]126 End Function
127
[166]128 Override Function GetHashCode() As Long
[223]129 Return x As DWord Xor _System_BSwap(y As DWord) Xor width As DWord Xor _System_BSwap(height As DWord)
[166]130 End Function
131
[77]132 Static Function FromLTRB(l As Long, t As Long, r As Long, b As Long) As Rectangle
[223]133 return New Rectangle(l, t, r - l, b - t)
[11]134 End Function
135
[104]136 Function Contains(x As Long, y As Long) As Boolean
[223]137 Return x >= X And x < X + Width And y >= Y And y < Y + Height
[11]138 End Function
139
[212]140 Function Contains(pt As Point) As Boolean
141 Return Contains(pt.X, pt.Y)
[11]142 End Function
143
[212]144 Function Contains(rc As Rectangle) As Boolean
[223]145 Return X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom
[11]146 End Function
147
[77]148 Sub Inflate(dx As Long, dy As Long)
[11]149 X -= dx
150 Y -= dy
[28]151 Width += dx + dx
152 Height += dy + dy
[11]153 End Sub
154
155 Sub Inflate(sz As Size)
156 Inflate(sz.Width, sz.Height)
157 End Sub
158
[212]159 Static Function Inflate(rc As Rectangle, x As Long, y As Long) As Rectangle
160 Inflate = New Rectangle(rc)
[11]161 Inflate.Inflate(x, y)
162 End Function
163
[212]164 Sub Intersect(rect As Rectangle)
[28]165 This = Rectangle.Intersect(This, rect)
166 End Sub
[11]167
[212]168 Static Function Intersect(a As Rectangle, ByRef b As Rectangle) As Rectangle
[77]169 Dim right As Long, bottom As Long, left As Long, top As Long
[11]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)
[28]174 Return Rectangle.FromLTRB(left, top, right, bottom)
[11]175 End Function
176
[212]177 Function IntersectsWith(rc As Rectangle) As Boolean
[223]178 Return Left < rc.Right And _
[11]179 Top < rc.Bottom And _
180 Right > rc.Left And _
[223]181 Bottom > rc.Top
[11]182 End Function
183
[212]184 Static Function Union(a As Rectangle, b As Rectangle) As Rectangle
[77]185 Dim right As Long, bottom As Long, left As Long, top As Long
[28]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())
[11]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
[77]197 Sub Offset(dx As Long, dy As Long)
[11]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
[77]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
[11]238Public
[77]239 x As Long
240 y As Long
241 width As Long
242 height As Long
[11]243End Class
244
245#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.