-
Notifications
You must be signed in to change notification settings - Fork 8
/
gui.go
175 lines (147 loc) · 5.62 KB
/
gui.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"context"
"fmt"
"time"
g "github.com/AllenDang/giu"
"gopkg.in/vansante/go-ffprobe.v2"
)
const dragDropLabel = "\n\n\n\n\n\n\n Drag n' Drop your anime here"
const shadersTooltip = "Check the project's GitHub page if you're not sure what to choose"
const encoderTooltip = "Codec for encoding output file. In most cases GPU based are faster, use CPU mainly if you have slow GPU\n" +
"GPU based AV1 is compatible only with RTX 4000+ and RX 6500XT+\n" +
"HDR videos are supported only by AV1 codec"
const crfTooltip = "Constant Rate Factor parameter encoder. \nDon't set it too high - file will be very big. " +
"\n\nCorrect values: 0 - 51 \nIf you don't know what to enter, leave it as 20"
const outputFormatTooltip = "If your input file contains subtitles streams you must use MKV as output format due to other formats limitations"
const compatibilityModeTooltip = "Should be used only for compatibility troubleshooting, disables most of features"
const debugModeTooltip = "Show more detailed logs, useful for troubleshooting and debugging"
var mainPos float32 = 580
var tablePos float32 = 1200
var bottomBarPos float32 = 1310
var bottomProgressPos float32 = 120
var bottomSpeedPos float32 = 110
func loop(window *g.MasterWindow) {
resolutionsNames := make([]string, len(resolutions))
for index, res := range resolutions {
resolutionsNames[index] = res.Format()
}
shadersNames := make([]string, len(shaders))
for index, shader := range shaders {
shadersNames[index] = shader.Name
}
availableEncodersNames := make([]string, len(availableEncoders))
for index, encoder := range availableEncoders {
availableEncodersNames[index] = encoder.Name
}
g.SingleWindow().Layout(
g.SplitLayout(g.DirectionHorizontal, &mainPos,
g.SplitLayout(g.DirectionVertical, &tablePos,
g.Layout{
g.Table().Flags(g.TableFlagsResizable).Rows(buildTableRows()...).Columns(buildTableColumns()...),
},
g.Layout{
g.Label("Settings"),
g.Label(""),
g.Label("Target resolution"),
g.Combo("##", resolutionsNames[settings.Resolution], resolutionsNames, &settings.Resolution).Size(400),
g.Label(""),
g.Label("Shaders"),
g.Tooltip(shadersTooltip),
g.Combo("##", shaders[settings.Shaders].Name, shadersNames, &settings.Shaders).Size(400),
g.Tooltip(shadersTooltip),
g.Label(""),
g.Label("Encoder"),
g.Tooltip(encoderTooltip),
g.Combo("##", availableEncoders[settings.Encoder].Name, availableEncodersNames, &settings.Encoder).Size(400),
g.Tooltip(encoderTooltip),
g.Label(""),
g.Label("Constant Rate Factor (CRF)"),
g.Tooltip(crfTooltip),
g.InputInt(&settings.Crf).Size(400).OnChange(func() { handleMinMax(&settings.Crf, 0, 0, 51, 51) }),
g.Tooltip(crfTooltip),
g.Label(""),
g.Label("Output format"),
g.Tooltip(outputFormatTooltip),
g.Combo("##", outputFormats[settings.OutputFormat], outputFormats, &settings.OutputFormat).Size(400),
g.Tooltip(outputFormatTooltip),
g.Label(""),
g.Checkbox("Compatibility mode", &settings.CompatibilityMode),
g.Tooltip(compatibilityModeTooltip),
g.Checkbox("Debug mode", &settings.DebugMode),
g.Tooltip(debugModeTooltip),
g.Label(""),
g.Button(gui.ButtonLabel).OnClick(handleButton).Size(360, 30),
},
),
g.Layout{
g.Label("Logs"),
g.InputTextMultiline(&gui.Logs).Flags(g.InputTextFlagsReadOnly).Size(1600, 270),
g.SplitLayout(g.DirectionVertical, &bottomBarPos,
g.SplitLayout(g.DirectionVertical, &bottomProgressPos,
g.Label("Progress: "+gui.TotalProgress),
g.ProgressBar(gui.Progress).Overlay(gui.ProgressLabel).Size(1170, 20),
),
g.SplitLayout(g.DirectionVertical, &bottomSpeedPos,
g.Label(gui.CurrentSpeed),
g.Label(gui.Eta),
),
),
},
),
)
settings.PositionX, settings.PositionY = window.GetPos()
}
func handleDrop(files []string) {
if processing {
return
}
ffprobe.SetFFProbeBinPath(".\\ffmpeg\\ffprobe.exe")
ctx, closeCtx := context.WithTimeout(context.Background(), 5*time.Second)
defer closeCtx()
for _, path := range files {
handleFfprobe(path, ctx)
}
}
func handleButton() {
if processing {
cancelProcessing()
} else {
go startProcessing()
}
}
func resetUI() {
gui.CurrentSpeed = "Speed:"
gui.Eta = "ETA:"
gui.TotalProgress = fmt.Sprintf("%d / %d", calcFinished(), len(animeList))
g.Update()
}
func buildTableRows() []*g.TableRowWidget {
rows := make([]*g.TableRowWidget, len(animeList))
for i, anime := range animeList {
rows[i] = g.TableRow(
g.Label(fmt.Sprintf("%d", i+1)),
g.Label(anime.Name),
g.Label(formatMillis(anime.Length)),
g.Label(formatMegabytes(anime.Size)),
g.Label(fmt.Sprintf("%dx%d", anime.Width, anime.Height)),
g.Label(string(anime.Status)),
g.Custom(func() { // Workaround for weird UI bug
g.Button("Remove").Disabled(processing).OnClick(func() { removeAnime(i) }).Build()
}),
)
}
return rows
}
func buildTableColumns() []*g.TableColumnWidget {
columns := []*g.TableColumnWidget{
g.TableColumn("ID").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
g.TableColumn("Title").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(550),
g.TableColumn("Length").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
g.TableColumn("Size").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
g.TableColumn("Resolution").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
g.TableColumn("Status").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
g.TableColumn("Action").Flags(g.TableColumnFlagsWidthFixed).InnerWidthOrWeight(100),
}
return columns
}