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

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

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

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