-
Notifications
You must be signed in to change notification settings - Fork 227
/
types.go
323 lines (249 loc) · 5.45 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//----------------------------------------
//
// Copyright © ying32. All Rights Reserved.
//
// Licensed under Apache License 2.0
//
//----------------------------------------
package types
type TPoint struct {
X int32
Y int32
}
type TRect struct {
Left int32
Top int32
Right int32
Bottom int32
}
type TSize struct {
Cx int32
Cy int32
}
type HWND = uintptr
type HBITMAP = uintptr
type HMENU = uintptr
type HICON = uintptr
type HDC = uintptr
type HFONT = uintptr
type HBRUSH = uintptr
type HPEN = uintptr
type HKEY = uintptr
type HMONITOR = uintptr
type HGDIOBJ = uintptr
type HMODULE = uintptr
type COLORREF = uint32
type DWORD = uint32
type HCURSOR = HICON
type HINST = uintptr
type LPCWSTR = uintptr
type HRGN = uintptr
type UINT = uint32
type LPARAM = uintptr
type WPARAM = uintptr
type LRESULT = uintptr
type HResult = uintptr
type HPALETTE = uintptr
type HRSRC = uintptr
type HGLOBAL = uintptr
type TFNWndEnumProc = uintptr
type TXId = uint64
type ATOM = uint16
type TAtom = uint16
type SIZE_T = uintptr
type DWORD_PTR = uintptr
type ACCESS_MASK = DWORD
type REGSAM = ACCESS_MASK
// TSet Pascal集合类型 set of xxx
type TSet uint32
// TUTF8Char
// UTF-8 character is at most 6 bytes plus a #0
type TUTF8Char struct {
Len byte
Content [7]byte
}
func (u *TUTF8Char) ToString() string {
if u.Len > 0 && u.Len < 7 {
return string(u.Content[0:u.Len])
}
return ""
}
func (u *TUTF8Char) SetString(str string) {
if str != "" {
bs := []byte(str)
u.Len = byte(len(bs))
if u.Len > 6 {
u.Len = 6
}
copy(u.Content[:], bs[:u.Len])
}
}
//----------------------------------------------------------------------------------------------------------------------
// -- TRect
func Rect(left, top, right, bottom int32) TRect {
return TRect{Left: left, Top: top, Right: right, Bottom: bottom}
}
func (r TRect) PtInRect(P TPoint) bool {
return P.X >= r.Left && P.X < r.Right && P.Y >= r.Top && P.Y < r.Bottom
}
func (r TRect) Width() int32 {
return r.Right - r.Left
}
func (r *TRect) SetWidth(val int32) {
r.Right = r.Left + val
}
func (r TRect) Height() int32 {
return r.Bottom - r.Top
}
func (r *TRect) SetHeight(val int32) {
r.Bottom = r.Top + val
}
func (r TRect) IsEmpty() bool {
return r.Right <= r.Left || r.Bottom <= r.Top
}
func (r *TRect) Empty() {
r.Left = 0
r.Top = 0
r.Right = 0
r.Bottom = 0
}
func (r TRect) Size() TSize {
return TSize{r.Width(), r.Height()}
}
func (r *TRect) SetSize(w, h int32) {
r.SetWidth(w)
r.SetHeight(h)
}
func (r *TRect) Inflate(dx, dy int32) {
r.Left += -dx
r.Top += -dy
r.Right += dx
r.Bottom += dy
}
func (r TRect) Contains(aR TRect) bool {
return r.Left <= aR.Left && r.Right >= aR.Right && r.Top <= aR.Top && r.Bottom >= aR.Bottom
}
func (r TRect) IntersectsWith(aR TRect) bool {
return r.Left < aR.Right && r.Right > aR.Left && r.Top < aR.Bottom && r.Bottom > aR.Top
}
func (r TRect) CenterPoint() (ret TPoint) {
ret.X = (r.Right-r.Left)/2 + r.Left
ret.Y = (r.Bottom-r.Top)/2 + r.Top
return
}
func (r *TRect) Scale(val float64) {
r.Left = int32(float64(r.Left) * val)
r.Top = int32(float64(r.Top) * val)
r.Right = int32(float64(r.Right) * val)
r.Bottom = int32(float64(r.Bottom) * val)
}
func (r *TRect) Scale2(val int) {
r.Scale(float64(val))
}
// -- TPoint
func Point(x, y int32) TPoint {
return TPoint{X: x, Y: y}
}
func (p TPoint) IsZero() bool {
return p.X == 0 && p.Y == 0
}
func (p *TPoint) Offset(dx, dy int32) {
p.X += dx
p.Y += dy
}
func (p *TPoint) Scale(val float64) {
p.X = int32(float64(p.X) * val)
p.Y = int32(float64(p.Y) * val)
}
func (p *TPoint) Scale2(val int) {
p.Scale(float64(val))
}
// TMsg
//
// Only Windows, tagMSG
type TMsg struct {
Hwnd HWND
Message uint32
WParam uintptr
LParam uintptr
Time uint32
Pt TPoint
}
// TCursorInfo
type TCursorInfo struct {
CbSize uint32
Flags uint32
HCursor HCURSOR
PtScreenPos TPoint
}
// TWndClass
type TWndClass struct {
Style uint32
LpfnWndProc uintptr
CbClsExtra int32
CbWndExtra int32
HInstance uintptr
HIcon HICON
HCursor HCURSOR
HbrBackground HBRUSH
LpszMenuName LPCWSTR
LpszClassName LPCWSTR
}
// TGestureEventInfo
//type TGestureEventInfo struct {
// GestureID TGestureID
// Location TPoint
// Flags TInteractiveGestureFlags
// Angle float64
// InertiaVector TSmallPoint
// //case Integer of
// // 0: (Distance: Integer);
// // 1: (TapLocation: TSmallPoint);
// // end;
// TapLocation TSmallPoint
//}
// -------------- TSet
// NewSet
//
// 新建TSet,初始值为0,然后添加元素
//
// Create a new TSet, the initial value is 0, and then add elements.
func NewSet(opts ...uint8) TSet {
var s TSet
return s.Include(opts...)
}
// Include
//
// 集合加法,val...中存储为位的索引,下标为0
//
// Set addition, stored as bit index in val..., subscript 0.
func (s TSet) Include(val ...uint8) TSet {
r := uint32(s)
for _, v := range val {
r |= (1 << uint8(v))
}
return TSet(r)
}
// Exclude
//
// 集合减法,val...中存储为位的索引,下标为0
//
// Set subtraction, stored as bit index in val..., subscript 0.
func (s TSet) Exclude(val ...uint8) TSet {
r := uint32(s)
for _, v := range val {
r &= ^(1 << uint8(v))
}
return TSet(r)
}
// In
//
// 集合类型的判断,val表示位数,下标为0
//
// Judgment of the Set type, val represents the number of digits, and the subscript is 0.
func (s TSet) In(val uint32) bool {
if s&(1<<uint8(val)) != 0 {
return true
}
return false
}