source: trunk/ab5.0/ablib/src/Classes/System/Drawing/RectangleF.ab@ 664

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

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

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