Skip to content

Commit 55f06a5

Browse files
add theme
1 parent 7db88d4 commit 55f06a5

14 files changed

+551
-236
lines changed

HybridSpiderMonkey.js

Lines changed: 75 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,289 +1,133 @@
11
'use strict';
22
include(fb.ComponentPath + 'samples\\complete\\js\\lodash.min.js');
33
include(fb.ComponentPath + 'samples\\complete\\js\\helpers.js');
4-
include(fb.ComponentPath + 'samples\\complete\\js\\panel.js');
5-
include(fb.ComponentPath + 'samples\\complete\\js\\seekbar.js');
64

7-
const DT_EXPANDTABS = 0x00000040,
8-
DT_WORD_ELLIPSIS = 0x00040000;
9-
10-
const FontTypeDUI = {
11-
defaults: 0,
12-
tabs: 1,
13-
lists: 2,
14-
playlists: 3,
15-
statusbar: 4,
16-
console: 5
17-
};
18-
19-
var FontTypeCUI = {
20-
items: 0,
21-
labels: 1
5+
include(fb.ComponentPath + 'HybridSpiderMonkey\\lib\\Hsm.js');
6+
include(fb.ComponentPath + 'HybridSpiderMonkey\\lib\\HsmPanel.js');
7+
include(fb.ComponentPath + 'HybridSpiderMonkey\\lib\\HsmImage.js');
8+
include(fb.ComponentPath + 'HybridSpiderMonkey\\lib\\HsmText.js');
9+
include(fb.ComponentPath + 'HybridSpiderMonkey\\lib\\HsmMediaControl.js');
10+
11+
let metaSources = {
12+
default: fb.TitleFormat('[Title$tab() %Title%$crlf()]\
13+
[Artist$tab() %Artist%$crlf()]\
14+
[Album$tab() %Album%$crlf()]\
15+
[Genre$tab() %Genre%$crlf()]\
16+
[$if(%Length%,,Path$tab() %Path%$crlf())]\
17+
[Date$tab() %Date%$crlf()]\
18+
[$crlf()%ALBUMDESCRIPTION%$]'),
19+
20+
saycast: fb.TitleFormat('$if(%playback_time%,[Title$tab() %Artist%$crlf()][Artist$tab() %Title%$crlf()])\
21+
[Path$tab() %Path%]'),
22+
saycastUrl: 'saycast.com'
2223
};
2324

24-
const IMG = {
25-
foobar2000: _img(fb.ComponentPath + 'HybridSpiderMonkey\\images\\foobar2000.png'),
26-
album: _img(fb.ComponentPath + 'HybridSpiderMonkey\\images\\album.png')
27-
}
25+
let panel = new HsmPanel(),
26+
metaImage = new HsmImage(panel, DOCK_LEFT | DOCK_SQUARE),
27+
mediaControl = new HsmMediaControl(panel, DOCK_BOTTOM, 16, {
28+
all: panel.prop.margin.value
29+
}),
30+
infoText = new HsmText(panel, DOCK_FILL, {}, {
31+
left: panel.prop.margin.value,
32+
top: panel.prop.margin.value,
33+
right: panel.prop.margin.value
34+
});
35+
panel.controls = [metaImage, mediaControl, infoText];
2836

29-
let panel = new _panel(),
30-
buttons = new _buttons(),
31-
seekbar = new _seekbar(0, 0, 0, 0);
32-
33-
let fonts = {};
37+
on_selection_changed();
3438

35-
let metas = {
36-
db: null,
37-
img: null,
38-
albumDesc: '',
39-
albumDescName: 'ALBUMDESCRIPTION',
40-
path: 3,
41-
splitter: '\t ',
42-
list: ['Title', 'Artist', 'Album', 'Path', 'Date'],
43-
saycast: ['Artist', 'Title', 'Album', 'Path', 'Date'],
44-
x: 0,
45-
y: 0,
46-
w: 0,
47-
h: 0,
48-
wheel: 0,
49-
lineCount: 0,
50-
linePerPage: 0
51-
};
39+
function getMetaValues() {
40+
return !panel.metadb ? null : panel.isStreaming() & panel.metadb.Path.includes(metaSources.saycastUrl) ?
41+
panel.getMetaValue(metaSources.saycast) : panel.getMetaValue(metaSources.default);
42+
}
5243

53-
let button = {
54-
x: 0,
55-
y: 0,
56-
w: 0,
57-
h: 32,
58-
playId: 3,
59-
pauseId: 4,
60-
text: ['Menu', 'Stop', 'Previous', 'Play', 'Pause', 'Next', 'Random', 'Console', 'Layout editing mode'],
61-
img: [IMG.foobar2000 || 'M', '\u23F9', '\u23EE', '\u23F5', '\u23f8', '\u23ED', 'R', 'C', 'L'
62-
],
63-
func: [(x, y, mask) => {
64-
_menu(x, y);
65-
}, () => {
66-
fb.Stop();
67-
}, () => {
68-
fb.Prev();
69-
}, () => {
70-
fb.PlayOrPause();
71-
}, () => {
72-
fb.PlayOrPause();
73-
}, () => {
74-
fb.Next();
75-
}, () => {
76-
fb.Random();
77-
}, () => {
78-
fb.RunMainMenuCommand('Console');
79-
}, () => {
80-
fb.RunMainMenuCommand('Enable layout editing mode');
81-
}]
82-
};
44+
// window callback
8345

84-
let playtime = {
85-
playing: fb.TitleFormat('%playback_time%$if(%length%, / %length%)'),
86-
stop: fb.TitleFormat('$if(%length%,%length%)'),
87-
x: 0,
88-
y: 0,
89-
w: 0,
90-
h: 0
46+
function on_mouse_lbtn_dblclk(x, y) {
47+
fb.RunMainMenuCommand('View/Show now playing in playlist');
9148
}
9249

93-
on_font_changed();
94-
on_selection_changed();
95-
96-
function isStreaming() {
97-
return metas.db.RawPath.includes('http:') || metas.db.RawPath.includes('https:');
50+
function on_mouse_lbtn_up(x, y) {
51+
mediaControl.lbtn_up(x, y);
9852
}
9953

100-
function getMetaValue(meta, i) {
101-
if (isStreaming()) {
102-
// at saycast url, change the title with the singer
103-
if (metas.db.Path.includes('saycast.com')) meta = metas.saycast[i];
104-
}
105-
return fb.TitleFormat('%' + meta + '%').Eval(true);
54+
function on_mouse_lbtn_down(x, y) {
55+
mediaControl.lbtn_down(x, y);
10656
}
10757

108-
function getMetaData() {
109-
metas.wheel = 0;
110-
metas.lineCount = 0;
111-
metas.albumDesc = metas.db ? fb.TitleFormat('%' + metas.albumDescName + '%').Eval(true) : '';
112-
metas.img = metas.db ? (utils.GetAlbumArtV2(metas.db, 0) || IMG.album) : IMG.album;
58+
function on_mouse_move(x, y) {
59+
mediaControl.move(x, y) || infoText.move(x, y);
11360
}
11461

115-
function updateButtons() {
116-
let x = button.x;
117-
const isPlaying = fb.IsPlaying && !fb.IsPaused;
118-
for (let i = 0, length = button.text.length; i < length; i++) {
119-
let h = ((i == button.playId && isPlaying) || (i == button.pauseId && !isPlaying)) ? 0 : button.h;
62+
function on_mouse_wheel(s) {
63+
if (mediaControl.wheel(s)) return;
64+
if (infoText.wheel(s)) window.Repaint();
65+
}
12066

121-
buttons.buttons[i] = new _button(x, button.y, h, h, {
122-
normal: (typeof button.img[i] == 'string' ?
123-
_chrToImg(button.img[i], panel.colours.text) : button.img[i])
124-
}, button.func[i], button.text[i]);
125-
x += h;
126-
}
67+
function on_key_down(vkey) {
68+
if (infoText.key_down(vkey)) window.Repaint();
12769
}
12870

12971
function on_paint(gr) {
13072
panel.paint(gr);
131-
buttons.paint(gr);
132-
133-
// album art
134-
if (metas.img) _drawImage(gr, metas.img, 0, 0, panel.h, panel.h, image.centre);
135-
136-
if (metas.db) {
137-
let info = '';
138-
for (let i = 0, length = metas.list.length; i < length; i++) {
139-
// path show only streaming url
140-
if (i == metas.path && !isStreaming()) continue;
141-
142-
const meta = metas.list[i];
143-
let text = fb.IsPlaying ? getMetaValue(meta, i) :
144-
fb.TitleFormat('%' + meta + '%').EvalWithMetadb(metas.db);
145-
// skip space or html tag
146-
if (!text || text == '?' || text.startsWith('<')) continue;
147-
info += meta + metas.splitter + text + '\n';
148-
}
149-
let fontInfo = fonts.title;
150-
if (metas.albumDesc && metas.albumDesc.length > 1) {
151-
info += '\n' + metas.albumDesc;
152-
fontInfo = fonts.desc;
153-
metas.lineCount = metas.lineCount || gr.MeasureString(info, fontInfo, metas.x, metas.y,
154-
metas.w, fonts.desc.Height * 1000, 0).Lines;
155-
156-
if (metas.lineCount > metas.linePerPage) {
157-
gr.GdiDrawText(metas.wheel + ' / ' + metas.lineCount, fonts.desc, panel.colours.text,
158-
playtime.x, playtime.y, playtime.w, playtime.h, 0);
159-
}
160-
}
161-
if (info) {
162-
let scrollText = fontInfo.Height * metas.wheel;
163-
gr.GdiDrawText('\n' + info, fontInfo, panel.colours.text,
164-
metas.x, metas.y - scrollText, metas.w, metas.h + scrollText, DT_EXPANDTABS | DT_WORDBREAK);
165-
}
166-
167-
// play time & length
168-
let playTimeText = fb.IsPlaying ? playtime.playing.Eval() : playtime.stop.EvalWithMetadb(metas.db);
169-
gr.GdiDrawText(playTimeText, fonts.desc, panel.colours.text,
170-
playtime.x, playtime.y, playtime.w, playtime.h, 2);
171-
172-
// seek bar progress
173-
if (fb.IsPlaying && fb.PlaybackLength > 0) {
174-
gr.FillSolidRect(seekbar.x, seekbar.y, seekbar.pos(), seekbar.h, panel.colours.highlight);
175-
}
176-
}
177-
// seek bar border line
178-
gr.DrawRect(seekbar.x, seekbar.y, seekbar.w, seekbar.h, 1, panel.colours.text);
17973
}
18074

18175
function on_size() {
18276
panel.size();
183-
let margin = button.h / 2;
184-
185-
// buttons position
186-
button.x = panel.h + margin;
187-
button.w = button.h * (button.text.length - 1);
188-
button.y = panel.h - button.h - margin / 2;
189-
190-
// seek bar position
191-
seekbar.h = 12;
192-
seekbar.x = button.x + button.w;
193-
seekbar.w = panel.w - seekbar.x - margin;
194-
seekbar.y = panel.h - seekbar.h - margin;
195-
196-
// play time position
197-
playtime.x = seekbar.x;
198-
playtime.w = seekbar.w;
199-
playtime.h = fonts.title.Height;
200-
playtime.y = seekbar.y - playtime.h;
201-
202-
// track info position
203-
metas.x = button.x;
204-
metas.w = seekbar.w + button.w;
205-
metas.y = 0;
206-
metas.h = button.y - metas.y - margin;
207-
metas.linePerPage = Math.floor(metas.h / fonts.desc.Height);
208-
metas.h = fonts.desc.Height * metas.linePerPage;
209-
metas.wheel = 0;
210-
metas.lineCount = 0;
211-
212-
updateButtons();
213-
}
214-
215-
function on_mouse_lbtn_down(x, y) {
216-
seekbar.lbtn_down(x, y);
217-
}
218-
219-
function on_mouse_lbtn_up(x, y) {
220-
buttons.lbtn_up(x, y) || seekbar.lbtn_up(x, y) ||
221-
fb.RunMainMenuCommand('View/Show now playing in playlist');
77+
window.Repaint();
22278
}
22379

224-
function on_mouse_move(x, y) {
225-
buttons.move(x, y) || seekbar.move(x, y);
226-
}
80+
// metadb changed callback
22781

228-
function on_mouse_wheel(s) {
229-
if (seekbar.wheel(s)) return;
230-
if (s == 1 && metas.wheel > 0) {
231-
metas.wheel -= metas.linePerPage;
232-
if (metas.wheel < 0) metas.wheel = 0;
233-
} else if ((metas.wheel + metas.linePerPage) <= metas.lineCount) {
234-
metas.wheel += metas.linePerPage;
235-
} else return;
82+
function on_metadb_changed() {
83+
if (!panel.metadb) return;
84+
metaImage.img = utils.GetAlbumArtV2(panel.metadb, 0);
85+
infoText.update(getMetaValues());
86+
mediaControl.metadb_changed();
23687
window.Repaint();
23788
}
23889

23990
function on_selection_changed() {
240-
metas.db = fb.IsPlaying ? fb.GetNowPlaying() : fb.GetFocusItem();
241-
getMetaData();
242-
window.Repaint();
91+
if (panel.selection_changed()) on_metadb_changed();
24392
}
24493

24594
function on_playback_new_track(metadb) {
246-
metas.db = metadb;
247-
getMetaData();
248-
window.Repaint();
95+
panel.playback_new_track(metadb);
96+
on_metadb_changed();
24997
}
25098

251-
function on_playback_edited(time) {
252-
window.Repaint();
99+
function on_playback_dynamic_info_track() {
100+
on_metadb_changed();
253101
}
254102

255-
function on_playback_time(time) {
256-
window.Repaint();
257-
}
258-
259-
function on_playback_seek(time) {
260-
seekbar.playback_seek();
261-
window.Repaint();
262-
}
103+
// playback callback
263104

264105
function on_playback_stop() {
265-
updateButtons();
266-
window.Repaint();
106+
mediaControl.playback_stop();
267107
}
268108

269109
function on_playback_starting() {
270-
updateButtons();
271-
metas.db = fb.GetNowPlaying() || fb.GetFocusItem();
272-
getMetaData();
273-
window.Repaint();
110+
mediaControl.playback_starting();
274111
}
275112

276113
function on_playback_pause() {
277-
updateButtons();
278-
window.Repaint();
114+
mediaControl.playback_pause();
115+
}
116+
117+
function on_playback_time(time) {
118+
mediaControl.playback_time(time);
279119
}
280120

121+
// colours & font callback
122+
281123
function on_colours_changed() {
282124
panel.colours_changed();
125+
mediaControl.colours_changed();
126+
window.Repaint();
283127
}
284128

285129
function on_font_changed() {
286-
fonts.desc = window.InstanceType ? window.GetFontDUI(0) : window.GetFontCUI(0);
287-
fonts.title = gdi.Font(fonts.desc.Name, fonts.desc.Size + 3);
130+
panel.font_changed();
131+
infoText.font_changed();
288132
window.Repaint();
289133
}

0 commit comments

Comments
 (0)