1 | ' Classes/System/Drawing/Size.ab
|
---|
2 |
|
---|
3 | #ifndef __SYSTEM_DRAWING_SIZE_AB__
|
---|
4 | #define __SYSTEM_DRAWING_SIZE_AB__
|
---|
5 |
|
---|
6 | #include <Classes/System/Math.ab>
|
---|
7 | #include <Classes/System/Drawing/SizeF.ab>
|
---|
8 |
|
---|
9 | Class Size
|
---|
10 | Public
|
---|
11 | Sub Size()
|
---|
12 | width = 0
|
---|
13 | height = 0
|
---|
14 | End Sub
|
---|
15 |
|
---|
16 | Sub Size(initWidth As Long, initHeight As Long)
|
---|
17 | width = initWidth
|
---|
18 | height = initHeight
|
---|
19 | End Sub
|
---|
20 |
|
---|
21 | Sub Size(ByRef sz As Size)
|
---|
22 | width = sz.width
|
---|
23 | height = sz.height
|
---|
24 | End Sub
|
---|
25 |
|
---|
26 | Function Width() As Long
|
---|
27 | Return width
|
---|
28 | End Function
|
---|
29 |
|
---|
30 | Sub Width(w As Long)
|
---|
31 | width = w
|
---|
32 | End Sub
|
---|
33 |
|
---|
34 | Function Height() As Long
|
---|
35 | Return height
|
---|
36 | End Function
|
---|
37 |
|
---|
38 | Sub Height(h As Long)
|
---|
39 | height = h
|
---|
40 | End Sub
|
---|
41 |
|
---|
42 | Function Operator +(sz As Size) As Size
|
---|
43 | Dim ret As Size(width + sz.width, height + sz.height)
|
---|
44 | Return ret
|
---|
45 | End Function
|
---|
46 |
|
---|
47 | Function Operator -(sz As Size) As Size
|
---|
48 | Dim ret As Size(width - sz.width, height - sz.height)
|
---|
49 | Return ret
|
---|
50 | End Function
|
---|
51 |
|
---|
52 | Function Operator () As SizeF
|
---|
53 | Dim szf As SizeF(width, height)
|
---|
54 | Return szf
|
---|
55 | End Function
|
---|
56 |
|
---|
57 | Function Operator ==(sz As Size) As Boolean
|
---|
58 | Return Equals(sz)
|
---|
59 | End Function
|
---|
60 |
|
---|
61 | Function Operator <>(sz As Size) As Boolean
|
---|
62 | Return Not Equals(sz)
|
---|
63 | End Function
|
---|
64 |
|
---|
65 | Sub Operator =(ByRef sz As Size)
|
---|
66 | width = sz.width
|
---|
67 | height = sz.height
|
---|
68 | End Sub
|
---|
69 |
|
---|
70 | Function Equals(sz As Size) As Boolean
|
---|
71 | If width = sz.width And height = sz.height Then
|
---|
72 | Equals = _System_TRUE
|
---|
73 | Else
|
---|
74 | Equals = _System_FALSE
|
---|
75 | End If
|
---|
76 | End Function
|
---|
77 |
|
---|
78 | Override Function GetHashCode() As Long
|
---|
79 | Return width Xor _System_BSwap(height)
|
---|
80 | End Function
|
---|
81 |
|
---|
82 | Function IsEmpty() As Boolean
|
---|
83 | If width = 0 And height = 0 Then
|
---|
84 | Empty = _System_TRUE
|
---|
85 | Else
|
---|
86 | Empty = _System_FALSE
|
---|
87 | End If
|
---|
88 | End Function
|
---|
89 |
|
---|
90 | Function Add(sz As Size) As Size
|
---|
91 | Return This + sz
|
---|
92 | End Function
|
---|
93 |
|
---|
94 | Function Subtract(sz As Size) As Size
|
---|
95 | Return This - sz
|
---|
96 | End Function
|
---|
97 |
|
---|
98 | Static Function Ceiling(szf As SizeF) As Size
|
---|
99 | Dim sz As Size(Math.Ceiling(szf.width), Math.Ceiling(szf.height))
|
---|
100 | Return sz
|
---|
101 | End Function
|
---|
102 |
|
---|
103 | Static Function Round(szf As SizeF) As Size
|
---|
104 | Dim sz As Size(Math.Round(szf.width), Math.Round(szf.height))
|
---|
105 | Return sz
|
---|
106 | End Function
|
---|
107 |
|
---|
108 | Static Function Truncate(szf As SizeF) As Size
|
---|
109 | Dim sz As Size(Math.Truncate(szf.width), Math.Truncate(szf.height))
|
---|
110 | Return sz
|
---|
111 | End Function
|
---|
112 |
|
---|
113 | Private
|
---|
114 | width As Long
|
---|
115 | height As Long
|
---|
116 | End Class
|
---|
117 |
|
---|
118 | #endif '__SYSTEM_DRAWING_SIZE_AB__
|
---|