/
welcome.go
99 lines (78 loc) · 2.08 KB
/
welcome.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 xirhogtk
import "github.com/gotk3/gotk3/gtk"
type welcome struct {
gtk.Frame
}
const fileDialogResponse = gtk.RESPONSE_ACCEPT // OK response
func newWelcome(parent gtk.IWindow, loader NewRendererSetter) *welcome {
// File Chooser
fileFilter, _ := gtk.FileFilterNew()
fileFilter.AddPattern("*.xml") // Flame XML
fileFilter.AddPattern("*.json") // JSON
fileDlg, _ := gtk.FileChooserDialogNewWith1Button(
"Import a Flame/JSON file",
parent, gtk.FILE_CHOOSER_ACTION_OPEN,
"Import", fileDialogResponse,
)
fileDlg.SetSelectMultiple(false)
fileDlg.AddFilter(fileFilter)
fileBtn, _ := gtk.FileChooserButtonNewWithDialog(fileDlg)
fileBtn.Show()
// Resolution Box
width, _ := gtk.SpinButtonNew(nil, 1, 0)
width.SetRange(1, 9999)
width.SetValue(1024)
width.Show()
xText, _ := gtk.LabelNew(`<span size="x-large">x</span>`)
xText.SetUseMarkup(true)
xText.Show()
height, _ := gtk.SpinButtonNew(nil, 1, 0)
height.SetRange(1, 9999)
height.SetValue(1024)
height.Show()
// Box
fileText, _ := gtk.LabelNew("Import a Flame/JSON file")
fileText.Show()
resText, _ := gtk.LabelNew("Canvas Resolution")
resText.Show()
resBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 5)
resBox.Add(width)
resBox.Add(xText)
resBox.Add(height)
resBox.Show()
ctnue, _ := gtk.ButtonNewWithLabel("Continue")
ctnue.SetMarginTop(10)
ctnue.SetHAlign(gtk.ALIGN_CENTER)
ctnue.Show()
ctnue.SetSensitive(false)
ctnue.Connect("clicked", func() {
loader.SetNewRenderer(
fileDlg.GetFilename(),
int(width.GetValue()),
int(height.GetValue()),
)
})
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
box.Add(fileText)
box.Add(fileBtn)
box.Add(resText)
box.Add(resBox)
box.Add(ctnue)
box.SetMarginBottom(10)
box.SetMarginStart(10)
box.SetMarginEnd(10)
box.Show()
// Frame
frame, _ := gtk.FrameNew("New Canvas")
frame.SetHAlign(gtk.ALIGN_CENTER)
frame.SetVAlign(gtk.ALIGN_CENTER)
frame.Add(box)
fileDlg.Connect("response", func(_ interface{}, respID gtk.ResponseType) {
if respID == fileDialogResponse {
ctnue.SetSensitive(true)
}
})
return &welcome{
Frame: *frame,
}
}