1 | ' Classes/System/Drawing/Point.ab
|
---|
2 |
|
---|
3 | #ifndef __SYSTEM_DRAWING_POINT_AB__
|
---|
4 | #define __SYSTEM_DRAWING_POINT_AB__
|
---|
5 |
|
---|
6 | #require <Classes/System/Drawing/PointF.ab>
|
---|
7 | #require <Classes/System/Drawing/Size.ab>
|
---|
8 | #require <Classes/System/Drawing/SizeF.ab>
|
---|
9 |
|
---|
10 | Namespace System
|
---|
11 | Namespace Drawing
|
---|
12 |
|
---|
13 | Class Point
|
---|
14 | Public
|
---|
15 | Sub Point()
|
---|
16 | x = 0
|
---|
17 | y = 0
|
---|
18 | End Sub
|
---|
19 |
|
---|
20 | Sub Point(initX As Long, initY As Long)
|
---|
21 | x = initX
|
---|
22 | y = initY
|
---|
23 | End Sub
|
---|
24 |
|
---|
25 | Sub Point(sz As Size)
|
---|
26 | x = sz.Width
|
---|
27 | y = sz.Height
|
---|
28 | End Sub
|
---|
29 |
|
---|
30 | Sub Point(dw As DWord)
|
---|
31 | x = LOWORD(dw)
|
---|
32 | y = HIWORD(dw)
|
---|
33 | End Sub
|
---|
34 |
|
---|
35 | Function X() As Long
|
---|
36 | Return x
|
---|
37 | End Function
|
---|
38 |
|
---|
39 | Sub X(newX As Long)
|
---|
40 | x = newX
|
---|
41 | End Sub
|
---|
42 |
|
---|
43 | Function Y() As Long
|
---|
44 | Return y
|
---|
45 | End Function
|
---|
46 |
|
---|
47 | Sub Y(newY As Long)
|
---|
48 | y = newY
|
---|
49 | End Sub
|
---|
50 |
|
---|
51 | Function IsEmpty() As Boolean
|
---|
52 | Return x = 0 And y = 0
|
---|
53 | End Function
|
---|
54 |
|
---|
55 | Function Operator + (pt As Point) As Point
|
---|
56 | Return Add(This, pt)
|
---|
57 | End Function
|
---|
58 |
|
---|
59 | Function Operator + (sz As Size) As Point
|
---|
60 | Return Add(This, sz)
|
---|
61 | End Function
|
---|
62 |
|
---|
63 | Function Operator - (pt As Point) As Point
|
---|
64 | Return Substract(This, pt)
|
---|
65 | End Function
|
---|
66 |
|
---|
67 | Function Operator - (sz As Size) As Point
|
---|
68 | Return Substract(This, sz)
|
---|
69 | End Function
|
---|
70 |
|
---|
71 | Function Operator == (sz As Point) As Boolean
|
---|
72 | Return Equals(sz)
|
---|
73 | End Function
|
---|
74 |
|
---|
75 | Function Operator <> (sz As Point) As Boolean
|
---|
76 | Return Not Equals(sz)
|
---|
77 | End Function
|
---|
78 |
|
---|
79 | Static Function Add(pt1 As Point, pt2 As Point) As Point
|
---|
80 | Dim ret As Point(pt1.x + pt2.x, pt1.y + pt2.y)
|
---|
81 | Return ret
|
---|
82 | End Function
|
---|
83 |
|
---|
84 | Static Function Add(pt As Point, sz As Size) As Point
|
---|
85 | Dim ret As Point(pt.x + sz.Width, pt.y + sz.Height)
|
---|
86 | Return ret
|
---|
87 | End Function
|
---|
88 |
|
---|
89 | Function Offset(pt As Point) As Point
|
---|
90 | Dim ret As Point(x + pt.x, y + pt.y)
|
---|
91 | Return ret
|
---|
92 | End Function
|
---|
93 |
|
---|
94 | Sub Offset(dx As Long, dy As Long)
|
---|
95 | x += dx
|
---|
96 | y += dy
|
---|
97 | End Sub
|
---|
98 |
|
---|
99 | Static Function Substract(pt1 As Point, pt2 As Point) As Point
|
---|
100 | Dim ret As Point(pt1.x - pt2.x, pt1.y - pt2.y)
|
---|
101 | Return ret
|
---|
102 | End Function
|
---|
103 |
|
---|
104 | Static Function Substract(pt As Point, sz As Size) As Point
|
---|
105 | Dim ret As Point(pt.x - sz.Width, pt.y - sz.Height)
|
---|
106 | Return ret
|
---|
107 | End Function
|
---|
108 |
|
---|
109 | Function Equals(pt As Point) As Boolean
|
---|
110 | Return x = pt.x And y = pt.y
|
---|
111 | End Function
|
---|
112 |
|
---|
113 | Override Function GetHashCode() As Long
|
---|
114 | Return x Xor _System_BSwap(y As DWord)
|
---|
115 | End Function
|
---|
116 |
|
---|
117 | Static Function Ceiling(ptf As PointF) As Point
|
---|
118 | Dim pt As Size(Math.Ceiling(ptf.width), Math.Ceiling(ptf.height))
|
---|
119 | Return pt
|
---|
120 | End Function
|
---|
121 |
|
---|
122 | Static Function Round(ptf As PointF) As Point
|
---|
123 | Dim pt As Point(Math.Round(ptf.width), Math.Round(ptf.height))
|
---|
124 | Return pt
|
---|
125 | End Function
|
---|
126 |
|
---|
127 | Static Function Truncate(ptf As PointF) As Point
|
---|
128 | Dim pt As Point(Math.Truncate(ptf.width), Math.Truncate(ptf.height))
|
---|
129 | Return pt
|
---|
130 | End Function
|
---|
131 |
|
---|
132 | Function Operator () As PointF
|
---|
133 | Return Return PointF(X, Y)
|
---|
134 | End Function
|
---|
135 |
|
---|
136 | Private
|
---|
137 | x As Long
|
---|
138 | y As Long
|
---|
139 | End Class
|
---|
140 |
|
---|
141 | End Namespace 'Drawing
|
---|
142 | End Namespace 'System
|
---|
143 |
|
---|
144 | #endif '__SYSTEM_DRAWING_POINT_AB__
|
---|