source: Include/Classes/System/Drawing/RectangleF.ab@ 212

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

Object.ReferenceEqualsを追加

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