-
Notifications
You must be signed in to change notification settings - Fork 3
/
locators.go
64 lines (49 loc) · 1.33 KB
/
locators.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
package gohotdraw
type Locator interface {
Locate(owner Figure) *Point
}
type DefaultLocator struct{}
type RelativeLocator struct {
*DefaultLocator
relativeX float
relativeY float
}
func NewDefaultRelativeLocator() *RelativeLocator {
return NewRelativeLocator(0.0, 0.0)
}
func NewRelativeLocator(relativeX, relativeY float) *RelativeLocator {
return &RelativeLocator{relativeX: relativeX, relativeY: relativeY}
}
func (this *RelativeLocator) Locate(owner Figure) *Point {
r := owner.GetDisplayBox()
xValue := r.X + (int)((float)(r.Width)*this.relativeX)
yValue := r.Y + (int)((float)(r.Height)*this.relativeY)
return &Point{xValue, yValue}
}
func CreateNorthLocator() Locator {
return NewRelativeLocator(0.5, 0.0)
}
func CreateWestLocator() Locator {
return NewRelativeLocator(0.0, 0.5)
}
func CreateSouthLocator() Locator {
return NewRelativeLocator(0.5, 1.0)
}
func CreateEastLocator() Locator {
return NewRelativeLocator(1.0, 0.5)
}
func CreateNorthEastLocator() Locator {
return NewRelativeLocator(1.0, 0.0)
}
func CreateNorthWestLocator() Locator {
return NewRelativeLocator(0.0, 0.0)
}
func CreateSouthEastLocator() Locator {
return NewRelativeLocator(1.0, 1.0)
}
func CreateSouthWestLocator() Locator {
return NewRelativeLocator(0.0, 1.0)
}
func CreateCenterLocator() Locator {
return NewRelativeLocator(0.5, 0.5)
}