-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_window.go
135 lines (121 loc) · 2.96 KB
/
main_window.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
package main
import (
"fmt"
"path/filepath"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
)
func mainWindow(a fyne.App, skin *Skin) (fyne.Window, error) {
w := a.NewWindow("It really whips the guanaco's ass!!!")
//drv, ok := a.Driver().(desktop.Driver)
//if !ok {
//panic("driver is not a driver")
//}
//w := drv.CreateSplashWindow()
//w.SetFixedSize(true)
w.SetMaster()
w.SetPadded(false)
w.Resize(fyne.Size{
Width: 275 * scaleFactor,
Height: 116 * scaleFactor,
})
// Load sprites
stack, err := stackFromFromDefinitions(skin)
if err != nil {
return nil, fmt.Errorf("loading stack: %w", err)
}
textLayer := &TextLayer{}
ts := &TextSprite{
Text: "CLICK EJECT BUTTON",
File: "text.bmp",
StrLen: 27,
Marquee: false,
RenderedText: nil,
Image: nil,
AbsolutePositionX: 110,
AbsolutePositionY: 28,
}
if err := ts.Load(skin); err != nil {
panic(err)
}
textLayer.sprites = append(textLayer.sprites, ts)
timeM := &TextSprite{
Text: "00",
File: "numbers.bmp",
Numeric: true,
CharSpacing: 1,
StrLen: 2,
Marquee: false,
RenderedText: nil,
Image: nil,
AbsolutePositionX: 50,
AbsolutePositionY: 26,
}
if err := timeM.Load(skin); err != nil {
panic(err)
}
timeS := &TextSprite{
Text: "00",
File: "numbers.bmp",
Numeric: true,
CharSpacing: 1,
StrLen: 2,
Marquee: false,
RenderedText: nil,
Image: timeM.Image, // it's the same image
AbsolutePositionX: 80,
AbsolutePositionY: 26,
}
textLayer.sprites = append(textLayer.sprites, timeS)
textLayer.sprites = append(textLayer.sprites, timeM)
mainWindowBG := &Background{
stack: stack,
textLayer: textLayer,
}
stack.register("close", func() error {
w.Close()
return nil
})
widget := newBgWidget(mainWindowBG)
w.SetContent(widget)
player, err := NewPlayer(func(elapsed, total uint64) error {
mins := elapsed / 60
seconds := elapsed - (mins * 60)
timeM.Set(fmt.Sprintf("%02d", mins))
timeS.Set(fmt.Sprintf("%02d", seconds))
perc := (float64(elapsed) * 100.0) / float64(total)
stack.FindByID("player.slider.seek").DraggableSeek(perc / 100)
widget.Refresh()
return nil
})
if err != nil {
panic(err)
}
go player.PlayerLoop()
stack.register("STOP", func() error {
return player.Stop()
})
stack.register("PLAY", func() error {
err = player.Play()
if err != nil {
return fmt.Errorf("playing: %w", err)
}
return nil
})
stack.register("PAUSE", func() error {
player.TogglePause()
return nil
})
stack.register("EJECT", func() error {
dialog.NewFileOpen(func(uri fyne.URIReadCloser, err error) {
defer uri.Close()
player.LoadFile(uri.URI().Path())
fileName := filepath.Base(uri.URI().Path())
ts.Set(strings.ToUpper(fileName))
widget.Refresh()
}, w).Show()
return nil
})
return w, nil
}