-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathview.go
88 lines (79 loc) · 1.73 KB
/
view.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
package painter
import (
"gopkg.in/fogleman/gg.v1"
)
type PosterContext struct {
Width int
Height int
Ctx *gg.Context
}
type View interface {
Paint(ctx *PosterContext)
}
type LineView struct {
X float64
Y float64
X2 float64
Y2 float64
LineWidth float64
LineColor string
}
func (v *LineView) Paint(pc *PosterContext) {
dc := pc.Ctx
dc.DrawLine(v.X, v.Y, v.X2, v.Y2)
dc.SetLineWidth(v.LineWidth)
dc.SetHexColor(v.LineColor)
dc.Stroke()
}
type RectangleView struct {
X float64
Y float64
Width float64
Height float64
BackgroudColor string
BorderStyle string
BorderRadius float64
BorderWidth float64
BorderColor string
}
func (v *RectangleView) Paint(ctx *PosterContext) {
dc := ctx.Ctx
dc.NewSubPath()
if v.BorderStyle != "" && v.BorderStyle != "none" {
dc.SetLineWidth(v.BorderWidth)
dc.DrawRoundedRectangle(v.X, v.Y, v.Width, v.Height, v.BorderRadius)
dc.SetHexColor(v.BorderColor)
dc.Stroke()
}
if v.BackgroudColor != "" {
dc.DrawRoundedRectangle(v.X, v.Y, v.Width, v.Height, v.BorderRadius)
dc.SetHexColor(v.BackgroudColor)
dc.Fill()
}
dc.ClosePath()
}
type CircleView struct {
X float64
Y float64
Radius float64
BackgroudColor string
BorderStyle string
BorderWidth float64
BorderColor string
}
func (v *CircleView) Paint(pc *PosterContext) {
dc := pc.Ctx
dc.NewSubPath()
if v.BorderStyle != "" && v.BorderStyle != "none" {
dc.SetLineWidth(v.BorderWidth)
dc.DrawCircle(v.X, v.Y, v.Radius)
dc.SetHexColor(v.BorderColor)
dc.Stroke()
}
if v.BackgroudColor != "" {
dc.DrawCircle(v.X, v.Y, v.Radius)
dc.SetHexColor(v.BackgroudColor)
dc.Fill()
}
dc.ClosePath()
}