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