/
statusbar.go
128 lines (105 loc) · 2.9 KB
/
statusbar.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
package ui
import (
"github.com/usedbytes/fonts"
"image"
"image/draw"
"fmt"
)
const (
STATE_PLAYING = iota
STATE_PAUSED
STATE_NONE
)
const (
ICON_PLAY = string(1)
ICON_PAUSE = string(2)
ICON_REPEAT = string(3)
ICON_SHUFFLE = string(4)
ICON_BLANK = string(5)
ICON_SELECTED = string(6)
)
type StatusBar struct {
view *View
icons, tiny *fonts.Font
stateLabel, shuffleLabel, repeatLabel, tracksLabel *Label
State int
Repeat, Shuffle bool
TrackNum, Tracks int
}
func NewStatusBar(p *Widget) (*StatusBar) {
sb := new(StatusBar)
sb.view = NewView(p, "Status Bar")
sb.view.AutoWidth = false
sb.view.AutoHeight = false
sb.view.SetWidth(101)
sb.view.SetHeight(8)
sb.icons = fonts.NewFontFromFile("/home/kernelcode/icon_font.fnt")
sb.tiny = fonts.NewFontFromFile("/home/kernelcode/tiny_font.fnt")
sb.State = STATE_NONE
sb.Repeat, sb.Shuffle = false, false
sb.TrackNum, sb.Tracks = 0, 0
sb.stateLabel = NewLabel(sb.view.Widget, sb.icons)
sb.stateLabel.SetPos(image.Point{2, 0})
sb.repeatLabel = NewLabel(sb.view.Widget, sb.icons)
sb.repeatLabel.SetPos(image.Point{10, 0})
sb.shuffleLabel = NewLabel(sb.view.Widget, sb.icons)
sb.shuffleLabel.SetPos(image.Point{19, 0})
sb.tracksLabel = NewLabel(sb.view.Widget, sb.tiny)
sb.tracksLabel.AutoWidth = false
sb.tracksLabel.SetWidth(70)
width := sb.view.Bounds().Dx()
sb.tracksLabel.SetPos(image.Point{width - 70, 0})
sb.tracksLabel.HAlign = Right
sb.view.AddChild(sb.stateLabel)
sb.view.AddChild(sb.repeatLabel)
sb.view.AddChild(sb.shuffleLabel)
sb.view.AddChild(sb.tracksLabel)
//sb.view.Damage(sb.Bounds())
return sb
}
func (sb *StatusBar) IsDirty() bool {
//sb.Update()
return sb.view.IsDirty()
}
func (sb *StatusBar) Update() {
switch sb.State {
case STATE_PLAYING:
sb.stateLabel.Text = ICON_PLAY
case STATE_PAUSED:
sb.stateLabel.Text = ICON_PAUSE
case STATE_NONE:
fallthrough
default:
sb.stateLabel.Text = ICON_BLANK
}
if (sb.Repeat) {
sb.repeatLabel.Text = ICON_REPEAT
} else {
sb.repeatLabel.Text = ICON_BLANK
}
if (sb.Shuffle) {
sb.shuffleLabel.Text = ICON_SHUFFLE
} else {
sb.shuffleLabel.Text = ICON_BLANK
}
sb.tracksLabel.Text = fmt.Sprintf("%d/%d", sb.TrackNum, sb.Tracks)
sb.view.Update()
}
func (sb *StatusBar) IsVisible() bool {
return sb.view.IsVisible()
}
func (sb *StatusBar) Draw(to draw.Image) image.Rectangle {
if (sb.IsDirty()) {
sb.Update()
if sb.IsVisible() {
return sb.view.Draw(to)
}
}
return image.ZR
}
func (sb *StatusBar) Bounds() (image.Rectangle) {
return sb.view.Bounds()
}
func (sb *StatusBar) MakeDirty() {
sb.view.Dirty = true
}