-
Notifications
You must be signed in to change notification settings - Fork 30
/
rect.go
85 lines (65 loc) · 1.57 KB
/
rect.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
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
* Copyright (C) 2010-2013 Allen Dang. All Rights Reserved.
*/
package winc
import (
"github.com/tadvi/winc/w32"
)
type Rect struct {
rect w32.RECT
}
func NewEmptyRect() *Rect {
var newRect Rect
w32.SetRectEmpty(&newRect.rect)
return &newRect
}
func NewRect(left, top, right, bottom int) *Rect {
var newRect Rect
w32.SetRectEmpty(&newRect.rect)
newRect.Set(left, top, right, bottom)
return &newRect
}
func (re *Rect) Data() (left, top, right, bottom int32) {
left = re.rect.Left
top = re.rect.Top
right = re.rect.Right
bottom = re.rect.Bottom
return
}
func (re *Rect) Width() int {
return int(re.rect.Right - re.rect.Left)
}
func (re *Rect) Height() int {
return int(re.rect.Bottom - re.rect.Top)
}
func (re *Rect) GetW32Rect() *w32.RECT {
return &re.rect
}
func (re *Rect) Set(left, top, right, bottom int) {
w32.SetRect(&re.rect, left, top, right, bottom)
}
func (re *Rect) IsEqual(rect *Rect) bool {
return w32.EqualRect(&re.rect, &rect.rect)
}
func (re *Rect) Inflate(x, y int) {
w32.InflateRect(&re.rect, x, y)
}
func (re *Rect) Intersect(src *Rect) {
w32.IntersectRect(&re.rect, &re.rect, &src.rect)
}
func (re *Rect) IsEmpty() bool {
return w32.IsRectEmpty(&re.rect)
}
func (re *Rect) Offset(x, y int) {
w32.OffsetRect(&re.rect, x, y)
}
func (re *Rect) IsPointIn(x, y int) bool {
return w32.PtInRect(&re.rect, x, y)
}
func (re *Rect) Substract(src *Rect) {
w32.SubtractRect(&re.rect, &re.rect, &src.rect)
}
func (re *Rect) Union(src *Rect) {
w32.UnionRect(&re.rect, &re.rect, &src.rect)
}