1
- package main
1
+ package demo
2
2
3
3
import (
4
- "fmt"
5
4
"github.com/shibukawa/nanovgo"
6
5
"math"
7
-
8
- "log"
9
6
"strconv"
10
7
)
11
8
9
+ const (
10
+ IconSEARCH = 0x1F50D
11
+ IconCIRCLEDCROSS = 0x2716
12
+ IconCHEVRONRIGHT = 0xE75E
13
+ IconCHECK = 0x2713
14
+ IconLOGIN = 0xE740
15
+ IconTRASH = 0xE729
16
+ )
17
+
12
18
// DemoData keeps font and image handlers
13
19
type DemoData struct {
14
- fontNormal , fontBold , fontIcons int
15
- images []int
20
+ FontNormal , FontBold , FontIcons int
21
+ Images []int
16
22
}
17
23
18
- func (d * DemoData ) loadData (ctx * nanovgo.Context ) {
19
- for i := 0 ; i < 12 ; i ++ {
20
- path := fmt .Sprintf ("images/image%d.jpg" , i + 1 )
21
- d .images = append (d .images , ctx .CreateImage (path , 0 ))
22
- if d .images [i ] == 0 {
23
- log .Fatalf ("Could not load %s" , path )
24
- }
25
- }
26
-
27
- d .fontIcons = ctx .CreateFont ("icons" , "entypo.ttf" )
28
- if d .fontIcons == - 1 {
29
- log .Fatalln ("Could not add font icons." )
30
- }
31
- d .fontNormal = ctx .CreateFont ("sans" , "Roboto-Regular.ttf" )
32
- if d .fontNormal == - 1 {
33
- log .Fatalln ("Could not add font italic." )
34
- }
35
- d .fontBold = ctx .CreateFont ("sans-bold" , "Roboto-Bold.ttf" )
36
- if d .fontBold == - 1 {
37
- log .Fatalln ("Could not add font bold." )
24
+ func (d * DemoData ) FreeData (ctx * nanovgo.Context ) {
25
+ for _ , img := range d .Images {
26
+ ctx .DeleteImage (img )
38
27
}
39
28
}
40
29
41
- func (d * DemoData ) freeData (ctx * nanovgo.Context ) {
42
- for _ , img := range d .images {
43
- ctx .DeleteImage (img )
30
+ func RenderDemo (ctx * nanovgo.Context , mx , my , width , height , t float32 , blowup bool , data * DemoData ) {
31
+ drawEyes (ctx , width - 250 , 50 , 150 , 100 , mx , my , t )
32
+ drawParagraph (ctx , width - 450 , 50 , 150 , 100 , mx , my )
33
+ drawGraph (ctx , 0 , height / 2 , width , height / 2 , t )
34
+ drawColorWheel (ctx , width - 300 , height - 300 , 250.0 , 250.0 , t )
35
+
36
+ // Line joints
37
+ drawLines (ctx , 120 , height - 50 , 600 , 50 , t )
38
+
39
+ // Line widths
40
+ drawWidths (ctx , 10 , 50 , 30 )
41
+
42
+ // Line caps
43
+ drawCaps (ctx , 10 , 300 , 30 )
44
+
45
+ drawScissor (ctx , 50 , height - 80 , t )
46
+
47
+ ctx .Save ()
48
+ defer ctx .Restore ()
49
+
50
+ if blowup {
51
+ ctx .Rotate (sinF (t * 0.3 ) * 5.0 / 180.0 * nanovgo .PI )
52
+ ctx .Scale (2.0 , 2.0 )
44
53
}
54
+
55
+ // Widgets
56
+ drawWindow (ctx , "Widgets `n Stuff" , 50 , 50 , 300 , 400 )
57
+ var x float32 = 60.0
58
+ var y float32 = 95.0
59
+ drawSearchBox (ctx , "Search" , x , y , 280 , 25 )
60
+ y += 40
61
+ drawDropDown (ctx , "Effects" , x , y , 280 , 28 )
62
+ popy := y + 14
63
+ y += 45
64
+
65
+ // Form
66
+ drawLabel (ctx , "Login" , x , y , 280 , 20 )
67
+ y += 25
68
+ drawEditBox (ctx , "Email" , x , y , 280 , 28 )
69
+ y += 35
70
+ drawEditBox (ctx , "Password" , x , y , 280 , 28 )
71
+ y += 38
72
+ drawCheckBox (ctx , "Remember me" , x , y , 140 , 28 )
73
+ drawButton (ctx , IconLOGIN , "Sign in" , x + 138 , y , 140 , 28 , nanovgo .RGBA (0 , 96 , 128 , 255 ))
74
+ y += 45
75
+
76
+ // Slider
77
+ drawLabel (ctx , "Diameter" , x , y , 280 , 20 )
78
+ y += 25
79
+ drawEditBoxNum (ctx , "123.00" , "px" , x + 180 , y , 100 , 28 )
80
+ drawSlider (ctx , 0.4 , x , y , 170 , 28 )
81
+ y += 55
82
+
83
+ drawButton (ctx , IconTRASH , "Delete" , x , y , 160 , 28 , nanovgo .RGBA (128 , 16 , 8 , 255 ))
84
+ drawButton (ctx , 0 , "Cancel" , x + 170 , y , 110 , 28 , nanovgo .RGBA (0 , 0 , 0 , 0 ))
85
+
86
+ // Thumbnails box
87
+ drawThumbnails (ctx , 365 , popy - 30 , 160 , 300 , data .Images , t )
45
88
}
46
89
47
90
func cosF (a float32 ) float32 {
@@ -150,7 +193,7 @@ func drawSearchBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
150
193
ctx .SetFontFace ("icons" )
151
194
ctx .SetFillColor (nanovgo .RGBA (255 , 255 , 255 , 64 ))
152
195
ctx .SetTextAlign (nanovgo .AlignCenter | nanovgo .AlignMiddle )
153
- ctx .Text (x + h * 0.55 , y + h * 0.55 , cpToUTF8 (iconSEARCH ))
196
+ ctx .Text (x + h * 0.55 , y + h * 0.55 , cpToUTF8 (IconSEARCH ))
154
197
155
198
ctx .SetFontSize (20.0 )
156
199
ctx .SetFontFace ("sans" )
@@ -163,7 +206,7 @@ func drawSearchBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
163
206
ctx .SetFontFace ("icons" )
164
207
ctx .SetFillColor (nanovgo .RGBA (255 , 255 , 255 , 32 ))
165
208
ctx .SetTextAlign (nanovgo .AlignCenter | nanovgo .AlignMiddle )
166
- ctx .Text (x + w - h * 0.55 , y + h * 0.55 , cpToUTF8 (iconCIRCLEDCROSS ))
209
+ ctx .Text (x + w - h * 0.55 , y + h * 0.55 , cpToUTF8 (IconCIRCLEDCROSS ))
167
210
}
168
211
169
212
func drawDropDown (ctx * nanovgo.Context , text string , x , y , w , h float32 ) {
@@ -191,7 +234,7 @@ func drawDropDown(ctx *nanovgo.Context, text string, x, y, w, h float32) {
191
234
ctx .SetFontFace ("icons" )
192
235
ctx .SetFillColor (nanovgo .RGBA (255 , 255 , 255 , 64 ))
193
236
ctx .SetTextAlign (nanovgo .AlignCenter | nanovgo .AlignMiddle )
194
- ctx .Text (x + w - h * 0.5 , y + h * 0.5 , cpToUTF8 (iconCHEVRONRIGHT ))
237
+ ctx .Text (x + w - h * 0.5 , y + h * 0.5 , cpToUTF8 (IconCHEVRONRIGHT ))
195
238
}
196
239
197
240
func drawEditBoxBase (ctx * nanovgo.Context , x , y , w , h float32 ) {
@@ -266,7 +309,7 @@ func drawCheckBox(ctx *nanovgo.Context, text string, x, y, w, h float32) {
266
309
ctx .SetFontFace ("icons" )
267
310
ctx .SetFillColor (nanovgo .RGBA (255 , 255 , 255 , 128 ))
268
311
ctx .SetTextAlign (nanovgo .AlignCenter | nanovgo .AlignMiddle )
269
- ctx .Text (x + 9 + 2 , y + h * 0.5 , cpToUTF8 (iconCHECK ))
312
+ ctx .Text (x + 9 + 2 , y + h * 0.5 , cpToUTF8 (IconCHECK ))
270
313
}
271
314
272
315
func drawButton (ctx * nanovgo.Context , preicon int , text string , x , y , w , h float32 , col nanovgo.Color ) {
0 commit comments