source: branch/egtra-gdiplus/Classes/System/Drawing/RectangleF.ab

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

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

File size: 4.8 KB
Line 
1' Classes/System/Drawing/RectangleF.ab
2
3#ifndef __SYSTEM_DRAWING_RECTANGLEF_AB__
4#define __SYSTEM_DRAWING_RECTANGLEF_AB__
5
6#require <Classes/System/Math.ab>
7#require <Classes/System/Drawing/PointF.ab>
8#require <Classes/System/Drawing/SizeF.ab>
9
10Namespace System
11Namespace Drawing
12
13Class RectangleF
14Public
15 Sub RectangleF()
16 x = 0
17 y = 0
18 width = 0
19 height = 0
20 End Sub
21
22 Sub RectangleF(x As Single, y As Single, width As Single, height As Single)
23 x = x
24 y = y
25 width = width
26 height = height
27 End Sub
28
29 Sub RectangleF(location As PointF, size As SizeF)
30 x = location.X
31 y = location.Y
32 width = size.Height
33 height = size.Height
34 End Sub
35
36 Sub RectangleF(rc As RectangleF)
37 x = rc.x
38 y = rc.y
39 width = rc.width
40 height = rc.height
41 End Sub
42
43 Function Location() As PointF
44 Dim pt As PointF(x, y)
45 Return pt
46 End Function
47
48 Sub Location(point As PointF)
49 x = point.X
50 y = point.Y
51 End Sub
52
53 Function Size() As SizeF
54 Dim size As SizeF(width, height)
55 End Function
56
57 Sub Size(size As SizeF)
58 width = size.Width
59 height = size.Height
60 End Sub
61
62 Function X() As Single
63 Return x
64 End Function
65
66 Sub X(value As Single)
67 x = value
68 End Sub
69
70 Function Y() As Single
71 Return y
72 End Function
73
74 Sub Y(value As Single)
75 y = value
76 End Sub
77
78 Function Width() As Single
79 Return width
80 End Function
81
82 Sub Width(value As Single)
83 width = value
84 End Sub
85
86 Function Height() As Single
87 Return height
88 End Function
89
90 Sub Height(value As Single)
91 height = value
92 End Sub
93
94 Function Left() As Single
95 Return X
96 End Function
97
98 Function Top() As Single
99 Return Y
100 End Function
101
102 Function Right() As Single
103 Return X + Width
104 End Function
105
106 Function Bottom() As Single
107 Return Y + Height
108 End Function
109
110 Function IsEmpty() As Boolean
111 If Width <= 0 Or Height <= 0 Then
112 IsEmpty = _System_TRUE
113 Else
114 IsEmpty = _System_FALSE
115 End If
116 End Function
117
118 Function Operator ==(rc As RectangleF)
119 Return Equals(rc)
120 End Function
121
122 Function Operator <>(rc As RectangleF)
123 Return Not Equals(rc)
124 End Function
125
126 Function Equals(rc As RectangleF) As Boolean
127 If X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height Then
128 Return True
129 Else
130 Return False
131 End If
132 End Function
133
134 Override Function GetHashCode() As Long
135 Return GetDWord(VarPtr(x)) Xor _System_BSwap(GetDWord(VarPtr(y))) Xor GetDWord(VarPtr(width)) Xor _System_BSwap(GetDWord(VarPtr(height)))
136 End Function
137
138 Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As RectangleF
139 return New RectangleF(l, t, r - l, b - t)
140 End Function
141
142 Function Contains(x As Single, y As Single) As Boolean
143 If x >= X And x < X + Width And y >= Y And y < Y + Height Then
144 Contains = _System_TRUE
145 Else
146 Contains = _System_FALSE
147 End If
148 End Function
149
150 Function Contains(pt As PointF) As Boolean
151 Return Contains(pt.X, pt.Y)
152 End Function
153
154 Function Contains(rc As RectangleF) As Boolean
155 If X <= rc.X And rc.Right <= Right And Y <= rc.Y And rc.Bottom <= Bottom Then
156 Return True
157 Else
158 Return False
159 End If
160 End Function
161
162 Sub Inflate(dx As Single, dy As Single)
163 X -= dx
164 Y -= dy
165 Width += dx + dx
166 Height += dy + dy
167 End Sub
168
169 Sub Inflate(sz As SizeF)
170 Inflate(sz.Width, sz.Height)
171 End Sub
172
173 Static Function Inflate(rc As RectangleF, x As Single, y As Single) As RectangleF
174 Inflate = New Rectangle(rc)
175 Inflate.Inflate(x, y)
176 End Function
177
178 Sub Intersect(rect As RectangleF)
179 This = RectangleF.Intersect(This, rect)
180 End Sub
181
182 Static Function Intersect(a As RectangleF, b As RectangleF) As RectangleF
183 Dim right As Single, bottom As Single, left As Single, top As Single
184 right = Math.Min(a.Right, b.Right)
185 bottom = Math.Min(a.Bottom, b.Bottom)
186 left = Math.Min(a.Left, b.Left)
187 top = Math.Min(a.Top, b.Top)
188 Return FromLTRB(left, top, right, bottom)
189 End Function
190
191 Function IntersectsWith(rc As RectangleF) As Boolean
192 If Left < rc.Right And _
193 Top < rc.Bottom And _
194 Right > rc.Left And _
195 Bottom > rc.Top Then
196 IntersectsWith = _System_TRUE
197 Else
198 IntersectsWith = _System_FALSE
199 End If
200 End Function
201
202 Static Function Union(a As RectangleF, b As RectangleF) As RectangleF
203 Dim right As Single, bottom As Single, left As Single, top As Single
204 right = Math.Max(a.Right(), b.Right())
205 bottom = Math.Max(a.Bottom(), b.Bottom())
206 left = Math.Max(a.Left(), b.Left())
207 top = Math.Max(a.Top(), b.Top())
208 Return FromLTRB(left, top, right, bottom)
209 End Function
210
211 Sub Offset(pt As PointF)
212 Offset(pt.X, pt.Y)
213 End Sub
214
215 Sub Offset(dx As Single, dy As Single)
216 X += dx
217 Y += dy
218 End Sub
219
220Public
221 x As Single
222 y As Single
223 width As Single
224 height As Single
225End Class
226
227End Namespace 'Drawing
228End Namespace 'System
229
230#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.