source: trunk/Include/Classes/System/Drawing/RectangleF.ab@ 499

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

実験として書いていたControlクラスを追加(せめてコミット前に既存のContorolに混ぜようとしたがコンパイルできなかった)。
ほかForms, Drawing及びGDI+の修正。

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