-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes_stipple.go
99 lines (93 loc) · 2.39 KB
/
shapes_stipple.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
package engoutil
// NewStippleLine
func NewStippleLine(points Points, factor int32, pattern uint16, lineWidth float32, clr uint32) *Shape {
s := newShape(SHAPE_KIND_STIPPLE_LINE)
s.stipple = &Stipple{
Factor: factor,
Pattern: pattern,
}
s.Render.Drawable = StippleLine{BorderWidth: lineWidth, Points: points.Points(), Stipple: *s.stipple}
s.Render.Color = NewColor(clr)
s.Render.SetShader(ShapeHUDShader)
return s
}
// NewStippleRect
func NewStippleRect(x, y, width, height float32, factor int32, pattern uint16, lineWidth float32, clr uint32) *Shape {
s := newShape(SHAPE_KIND_STIPPLE_RECT)
s.stipple = &Stipple{
Factor: factor,
Pattern: pattern,
}
s.attr[0] = x
s.attr[1] = y
s.attr[2] = width
s.attr[3] = height
s.Render.Drawable = StippleRect{BorderWidth: lineWidth, Stipple: *s.stipple}
s.Render.Color = NewColor(clr)
s.Render.SetShader(ShapeHUDShader)
s.Space.Position.X = x
s.Space.Position.Y = y
s.Space.Width = width
s.Space.Height = height
return s
}
// (*Shape) Stipple
func (s *Shape) Stipple() (int32, uint16) {
if s.stipple == nil {
return 0, 0
}
return s.stipple.Factor, s.stipple.Pattern
}
// (*Shape) SetStipple
func (s *Shape) SetStipple(factor int32, pattern uint16) {
if !s.requireKind(SHAPE_KIND_STIPPLE_LINE|SHAPE_KIND_STIPPLE_RECT, "SetStipple") {
return
}
if s.stipple.Factor == factor && s.stipple.Pattern == pattern {
return
}
switch t := s.Render.Drawable.(type) {
case StippleLine:
t.Stipple.Factor = factor
t.Stipple.Pattern = pattern
s.Render.Drawable = t
case StippleRect:
t.Stipple.Factor = factor
t.Stipple.Pattern = pattern
s.Render.Drawable = t
}
s.stipple.Factor = factor
s.stipple.Pattern = pattern
}
// (*Shape) MoveStippleLeft
func (s *Shape) MoveStippleLeft() {
if !s.requireKind(SHAPE_KIND_STIPPLE_LINE|SHAPE_KIND_STIPPLE_RECT, "MoveStippleLeft") {
return
}
if s.stipple.Pattern == 0xFFFF {
return
}
pattern := s.stipple.Pattern
if pattern&0x8000 > 0 {
pattern = s.stipple.Pattern<<1 | 1
} else {
pattern <<= 1
}
s.SetStipple(s.stipple.Factor, pattern)
}
// (*Shape) MoveStippleRight
func (s *Shape) MoveStippleRight() {
if !s.requireKind(SHAPE_KIND_STIPPLE_LINE|SHAPE_KIND_STIPPLE_RECT, "MoveStippleRight") {
return
}
if s.stipple.Pattern == 0xFFFF {
return
}
pattern := s.stipple.Pattern
if pattern&0x1 > 0 {
pattern = pattern>>1 | 0x8000
} else {
pattern >>= 1
}
s.SetStipple(s.stipple.Factor, pattern)
}