// ==PREPROCESSOR== // @name "Track Info + Seekbar + Buttons" // @author "marc2003" // @import "%fb2k_component_path%helpers.txt" // @import "%fb2k_component_path%samples\js\lodash.min.js" // @import "%fb2k_component_path%samples\js\common.js" // @import "%fb2k_component_path%samples\js\panel.js" // @import "%fb2k_component_path%samples\js\seekbar.js" // ==/PREPROCESSOR== // $rgb is supported here var tfo = { artist : fb.TitleFormat("%artist%"), title : fb.TitleFormat("%title%"), playback_time : fb.TitleFormat("[%playback_time%]"), length : fb.TitleFormat("$if2(%length%,LIVE)"), }; var colours = { text : RGB(240, 240, 240), background : RGB(30, 30, 30), buttons : RGB(255, 255, 255), slider_background : RGB(160, 160, 160), contrast : RGB(196, 30, 35), }; ////////////////////////////////////////////////////////////// var panel = new _panel(); var seekbar = new _seekbar(0, 0, 0, 0); var buttons = new _buttons(); var img = null; var bs = _scale(24); var pbo_chars = [chars.repeat_off, chars.repeat_all, chars.repeat_one, chars.random, chars.shuffle, chars.album, chars.folder]; var pbo_names = plman.GetPlaybackOrders().toArray(); var normal_font = CreateFontString('Segoe UI', 12); var bold_font = CreateFontString('Segoe UI', 12, true); window.MaxHeight = _scale(150); on_playback_new_track(fb.GetNowPlaying()); buttons.update = function () { var y = Math.round((panel.h - bs) / 2); var pbo = plman.PlaybackOrder; this.buttons.pbo = new _button(panel.w - LM - (bs * 10), y - 2, bs + 4, bs + 4, { char : pbo_chars[pbo], colour: pbo == 0 ? setAlpha(colours.buttons, 60) : colours.contrast }, null, function () { pbo >= pbo_chars.length - 1 ? plman.PlaybackOrder = 0 : plman.PlaybackOrder++ }, 'Playback Order: ' + pbo_names[pbo]); this.buttons.stop = new _button(panel.w - LM - (bs * 8), y, bs, bs, { char : chars.stop, colour:fb.StopAfterCurrent ? colours.contrast : colours.buttons}, null, function () { fb.Stop(); }, 'Stop'); this.buttons.previous = new _button(panel.w - LM - (bs * 7), y, bs, bs, { char : chars.prev, colour:colours.buttons }, null, function () { fb.Prev(); }, 'Previous'); this.buttons.play = new _button(panel.w - LM - (bs * 6), y, bs, bs, { char : !fb.IsPlaying || fb.IsPaused ? chars.play : chars.pause, colour:colours.buttons}, null, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? 'Play' : 'Pause'); this.buttons.next = new _button(panel.w - LM - (bs * 5), y, bs, bs, { char : chars.next, colour:colours.buttons }, null, function () { fb.Next(); }, 'Next'); this.buttons.console = new _button(panel.w - LM - (bs * 3), y, bs, bs, {char : chars.list, colour:colours.buttons }, null, function () { fb.ShowConsole(); }, 'Console'); this.buttons.search = new _button(panel.w - LM - (bs * 2), y, bs, bs, { char : chars.search, colour:colours.buttons }, null, function () { fb.RunMainMenuCommand('Library/Search'); }, 'Library Search'); this.buttons.preferences = new _button(panel.w - LM - bs, y, bs, bs, { char : chars.preferences, colour:colours.buttons}, null, function () { fb.ShowPreferences(); }, 'Preferences'); } function update_album_art(metadb) { if (img) img.Dispose(); img = null; if (metadb) { img = metadb.GetAlbumArt(); } window.Repaint(); } function on_mouse_lbtn_down(x, y) { seekbar.lbtn_down(x, y); } function on_mouse_lbtn_up(x, y) { if (x < panel.h && fb.IsPlaying && img) { fb.GetNowPlaying().ShowAlbumArtViewer(); return; } if (buttons.lbtn_up(x, y)) { return; } if (seekbar.lbtn_up(x, y)) { return; } fb.RunMainMenuCommand('View/Show now playing in playlist'); } function on_mouse_leave() { buttons.leave(); } function on_mouse_move(x, y) { window.SetCursor(x < panel.h && fb.IsPlaying && img ? IDC_HAND : IDC_ARROW); if (buttons.move(x, y)) { return; } seekbar.move(x, y); } function on_mouse_rbtn_up(x, y) { if (buttons.buttons.stop.containsXY(x, y)) { fb.StopAfterCurrent = !fb.StopAfterCurrent; return true; } return panel.rbtn_up(x, y); } function on_mouse_wheel(s) { if (seekbar.wheel(s)) { return; } if (s == 1) { fb.VolumeUp(); } else { fb.VolumeDown(); } } function on_paint(gr) { gr.Clear(colours.background); gr.FillRoundedRectangle(seekbar.x, seekbar.y, seekbar.w, seekbar.h, _scale(2), _scale(2), colours.slider_background); buttons.paint(gr); if (fb.IsPlaying) { if (img) { _drawImage(gr, img, 0, 0, panel.h, panel.h, image.crop_top); } DrawColouredText(gr, tfo.title.Eval(), bold_font, colours.text, panel.h + 10, 0, seekbar.x - panel.h - _scale(60), panel.h * 0.6, DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_PARAGRAPH_ALIGNMENT_CENTER, DWRITE_WORD_WRAPPING_NO_WRAP, DWRITE_TRIMMING_GRANULARITY_CHARACTER); DrawColouredText(gr, tfo.artist.Eval(), normal_font, colours.text, panel.h + 10, panel.h * 0.3, seekbar.x - panel.h - _scale(60), panel.h * 0.7, DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_PARAGRAPH_ALIGNMENT_CENTER, DWRITE_WORD_WRAPPING_NO_WRAP, DWRITE_TRIMMING_GRANULARITY_CHARACTER); DrawColouredText(gr, tfo.playback_time.Eval(), normal_font, colours.text, seekbar.x - _scale(72), 0, _scale(60), panel.h, DWRITE_TEXT_ALIGNMENT_TRAILING, DWRITE_PARAGRAPH_ALIGNMENT_CENTER); DrawColouredText(gr, tfo.length.Eval(), normal_font, colours.text, seekbar.x + seekbar.w + _scale(12), 0, _scale(60), panel.h, DWRITE_TEXT_ALIGNMENT_LEADING, DWRITE_PARAGRAPH_ALIGNMENT_CENTER); if (fb.PlaybackLength > 0) { gr.FillEllipse(seekbar.x + seekbar.pos(), seekbar.y + _scale(3), _scale(6), _scale(6), colours.contrast); } } } function on_playback_dynamic_info_track(type) { if (type == 0) window.Repaint(); else update_album_art(fb.GetNowPlaying()); } function on_playback_edited() { window.Repaint(); } function on_playback_new_track(metadb) { update_album_art(metadb); } function on_playback_order_changed() { buttons.update(); window.Repaint(); } function on_playback_pause() { buttons.update(); window.Repaint(); } function on_playback_seek() { seekbar.playback_seek(); } function on_playback_starting() { buttons.update(); window.Repaint(); } function on_playback_stop() { buttons.update(); window.Repaint(); } function on_playback_time() { window.RepaintRect(panel.h, 0, seekbar.x - panel.h, panel.h); } function on_playlist_stop_after_current_changed() { buttons.update(); window.Repaint(); } function on_size() { panel.size(); seekbar.x = _scale(300); seekbar.w = panel.w - seekbar.x - _scale(310); seekbar.h = _scale(6); seekbar.y = (panel.h - seekbar.h + _scale(2)) / 2; buttons.update(); }