-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdialogs.go
141 lines (128 loc) · 5.29 KB
/
dialogs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
. "gopaint/reza"
"log"
"strconv"
)
type ResizeDialog struct {
Dialog
}
type PropertiesDialog struct {
Dialog
lastSaved Label
sizeOnDisk Label
width TextBox
height TextBox
}
func NewResizeDialog(parent Window) *ResizeDialog {
dlg := &ResizeDialog{Dialog: NewDialog()}
dlg.Init(parent)
return dlg
}
func (dlg *ResizeDialog) Init(parent Window) {
logInfo("Initialize Resize dialog...")
dlg.Dialog.Initialize(parent, "Resize", 300, 320)
dlg.AddWidgets([]Widget{
&WGroup{Text: "Resize", DockType: DockFill,
Margins: Margins{Left: 10, Top: 10, Right: 10, Bottom: 10}, Widgets: []Widget{
&WFlowContainer{FlowDirection: FlowLeftToRight, DockType: DockFill,
Margins: Margins{Left: 20, Top: 30, Right: 10, Bottom: 10}, Widgets: []Widget{
&WLabel{Text: "By:\t"},
&WRadioButton{Text: "Parcentage", Margins: Margins{Right: 20}},
&WRadioButton{Text: "Pixels", Margins: Margins{Right: 20, Bottom: 20}, Checked: true},
&WImageViewer{Path: ".\\icons\\horizintal.png", Margins: Margins{Right: 30, Bottom: 20}},
&WLabel{Text: "Horizintal:\t", Margins: Margins{Top: 5}},
&WTextBox{Text: "100", Width: 60, Height: 24, Margins: Margins{Right: 20}},
&WImageViewer{Path: ".\\icons\\vertical.png", Margins: Margins{Right: 30, Bottom: 20}},
&WLabel{Text: "Vertical:\t\t", Margins: Margins{Top: 5}},
&WTextBox{Text: "100", Width: 60, Height: 24, Margins: Margins{Right: 20}},
&WCheckButton{Text: "Maintain aspect ratio", Checked: true},
}},
}},
})
}
func NewPropertiesDialog(parent Window) *PropertiesDialog {
dlg := &PropertiesDialog{Dialog: NewDialog()}
dlg.Init(parent)
return dlg
}
func (dlg *PropertiesDialog) Init(parent Window) {
logInfo("Initialize Properties dialog...")
dlg.Dialog.Initialize(parent, "Image Properties", 340, 360)
dlg.AddWidgets([]Widget{
&WGroup{Text: "File Attributes", DockType: DockTop, Height: 100,
Margins: Margins{Left: 10, Top: 10, Right: 10, Bottom: 10}, Widgets: []Widget{
&WFlowContainer{FlowDirection: FlowLeftToRight, DockType: DockFill,
Margins: Margins{Left: 15, Top: 15, Right: 5, Bottom: 5}, Widgets: []Widget{
&WLabel{Text: "Last Saved:\tNot Available", Margins: Margins{Top: 10, Right: 20}, AssignTo: &dlg.lastSaved},
&WLabel{Text: "Size on disk:\tNot Available", Margins: Margins{Top: 10, Right: 40}, AssignTo: &dlg.sizeOnDisk},
&WLabel{Text: "Resolution:\t96 DPI", Margins: Margins{Top: 10}},
}},
}},
&WFlowContainer{FlowDirection: FlowLeftToRight, DockType: DockBottom, Height: 25,
Margins: Margins{Left: 10, Right: 10, Bottom: 10}, Widgets: []Widget{
&WLabel{Text: "Width:\t", Margins: Margins{Top: 4}},
&WTextBox{Text: "1152", Width: 60, Height: 24, Margins: Margins{Right: 10}, AssignTo: &dlg.width},
&WLabel{Text: "Height:\t", Margins: Margins{Top: 4}},
&WTextBox{Text: "648", Width: 60, Height: 24, Margins: Margins{Right: 10}, AssignTo: &dlg.height},
&WButton{Text: "Default", Width: 70, Height: 24, OnClick: func(sender Button) {
dlg.width.SetText(strconv.Itoa(app.DefaultCanvasSize.Width))
dlg.height.SetText(strconv.Itoa(app.DefaultCanvasSize.Height))
}},
}},
&WFlowContainer{FlowDirection: FlowNone, DockType: DockFill,
Margins: Margins{Left: 10, Right: 10, Bottom: 10}, Widgets: []Widget{
&WGroup{Text: "Units", DockType: DockLeft, Width: 140, Margins: Margins{Right: 5}, Widgets: []Widget{
&WFlowContainer{FlowDirection: FlowLeftToRight, DockType: DockFill,
Margins: Margins{Left: 5, Top: 20, Right: 10, Bottom: 10}, Widgets: []Widget{
&WRadioButton{Text: "Inches", Margins: Margins{Left: 10, Top: 10}},
&WRadioButton{Text: "Centimeters", Margins: Margins{Left: 10, Top: 10}},
&WRadioButton{Text: "Pixels", Margins: Margins{Left: 10, Top: 10}, Checked: true},
}},
}},
&WGroup{Text: "Colors", DockType: DockFill, Margins: Margins{Left: 5}, Widgets: []Widget{
&WFlowContainer{FlowDirection: FlowLeftToRight, DockType: DockFill,
Margins: Margins{Left: 5, Top: 20, Right: 10, Bottom: 10}, Widgets: []Widget{
&WRadioButton{Text: "Black and white", Margins: Margins{Left: 10, Top: 10}},
&WRadioButton{Text: "Color", Margins: Margins{Left: 10, Top: 10}, Checked: true},
}},
}},
}},
})
}
func (dlg *PropertiesDialog) Show() {
canvas := mainWindow.workspace.canvas
image := canvas.image
if imageSize, available := image.SizeOnDisk(); available {
dlg.sizeOnDisk.SetText("Size on disk:\t" + imageSize)
} else {
dlg.sizeOnDisk.SetText("Size on disk:\tNot Available")
}
if lastSaved, available := image.LastSaved(); available {
dlg.lastSaved.SetText("Last Saved:\t" + lastSaved)
} else {
dlg.lastSaved.SetText("Last Saved:\tNot Available")
}
dlg.width.SetText(strconv.Itoa(image.Width()))
dlg.height.SetText(strconv.Itoa(image.Height()))
dlg.Dialog.Show(true, func() {
width := dlg.width.GetText()
height := dlg.height.GetText()
newCanvasWidth, err := strconv.Atoi(width)
if err == nil {
newCanvasHeight, err := strconv.Atoi(height)
if err == nil {
if newCanvasHeight > 0 && newCanvasWidth > 0 {
canvas.Resize(newCanvasWidth, newCanvasHeight)
mainWindow.workspace.RequestLayout()
} else {
log.Panicln("Enter valid canvas size!!!")
}
} else {
log.Panicln(err)
}
} else {
log.Panicln(err)
}
})
}