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

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

フルコンパイルでのミスあぶり出し。註:修正は全て@300や@301以前に行われた。

File size: 5.5 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
[303]112 Function Operator == (rc As Rectangle) As Boolean
[11]113 Return Equals(rc)
114 End Function
115
[303]116 Function Operator <> (rc As Rectangle) As Boolean
117 Return (Not Equals(rc))
[11]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)
[303]149 x -= dx
150 y -= dy
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
[303]160 Inflate = New Rectangle(rc.X, rc.Y, rc.Width, rc.Height)
[11]161 Inflate.Inflate(x, y)
162 End Function
163
[212]164 Sub Intersect(rect As Rectangle)
[303]165 Dim r = Rectangle.Intersect(This, rect)
166 x = r.x
167 y = r.y
168 width = r.width
169 height = r.height
[28]170 End Sub
[11]171
[212]172 Static Function Intersect(a As Rectangle, ByRef b As Rectangle) As Rectangle
[77]173 Dim right As Long, bottom As Long, left As Long, top As Long
[303]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)
[28]178 Return Rectangle.FromLTRB(left, top, right, bottom)
[11]179 End Function
180
[212]181 Function IntersectsWith(rc As Rectangle) As Boolean
[223]182 Return Left < rc.Right And _
[11]183 Top < rc.Bottom And _
184 Right > rc.Left And _
[223]185 Bottom > rc.Top
[11]186 End Function
187
[212]188 Static Function Union(a As Rectangle, b As Rectangle) As Rectangle
[77]189 Dim right As Long, bottom As Long, left As Long, top As Long
[303]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())
[11]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
[77]201 Sub Offset(dx As Long, dy As Long)
[303]202 x += dx
203 y += dy
[11]204 End Sub
205
206 Static Function Ceiling(rcf As RectangleF) As Rectangle
207 Dim r As Rectangle(
[303]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)
[11]212 Return r
213 End Function
214
215 Static Function Round(rcf As RectangleF) As Rectangle
216 Dim r As Rectangle(
[303]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)
[11]221 Return r
222 End Function
223
224 Static Function Truncate(rcf As RectangleF) As Rectangle
225 Dim r As Rectangle(
[303]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)
[11]230 Return r
231 End Function
232
[77]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
[11]242Public
[77]243 x As Long
244 y As Long
245 width As Long
246 height As Long
[11]247End Class
248
249#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.