Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2012 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8f160fdd33c166d306ae to your computer and use it in GitHub Desktop.
Save anonymous/8f160fdd33c166d306ae to your computer and use it in GitHub Desktop.
Toolbar
// ==PREPROCESSOR==
// @import "%fb2k_path%scripts\Helpers.txt"
// @import "%fb2k_path%scripts\Flags.txt"
// @import "%fb2k_path%scripts\getColoursFonts.js"
// @import "%fb2k_path%scripts\buttons.js"
// @import "%fb2k_path%scripts\menus.js"
// ==/PREPROCESSOR==
window.MaxHeight = tpad+bth;
window.MinHeight = tpad+bth;
function on_size()
{
ww = window.Width;
wh = window.Height;
buttons = {
back: new button('back', function(){fb.Prev();},"Previous",lpad),
stop: new button('stop', function(){fb.Stop();},"Stop",lpad+btw),
pop: new button((fb.IsPlaying&&!fb.IsPaused)?'pause':'play',function(){fb.PlayOrPause();},(fb.IsPlaying&&!fb.IsPaused)?"Pause":"Play",lpad+2*btw),
sac: new button(fb.StopAfterCurrent?'sac_on':'sac',function(){fb.StopAfterCurrent=!fb.StopAfterCurrent;},"Stop After Current "+(fb.StopAfterCurrent?"(On)":"(Off)"),lpad+3*btw),
next: new button('fwd', function(){fb.Next();},"Next",lpad+4*btw),
//
cfp: new button(fb.CursorFollowPlayback?'cfp_on':'cfp',function() { fb.CursorFollowPlayback=!fb.CursorFollowPlayback; },"Cursor Follows Playback "+(fb.CursorFollowPlayback?"(On)":"(Off)"), ww-rpad-3*btw),
pfc: new button(fb.PlaybackFollowCursor?'pfc_on':'pfc',function() { fb.PlaybackFollowCursor=!fb.PlaybackFollowCursor; },"Playback Follows Cursor "+(fb.PlaybackFollowCursor?"(On)":"(Off)"), ww-rpad-2*btw),
pbo: new button(PBOArray[fb.PlayBackOrder],function() { playbackorder(); },"Playback Order ("+PBOArray[fb.PlayBackOrder]+")", ww-rpad-1*btw),
//lfm: new button('lfm', function(){lastfm();},"Last.fm", ww-rpad-2*btw),
//menu: new button('menu', function(){runmenu();},"Run", ww-rpad-btw)
}
}
function on_paint(gr)
{
gr.FillSolidRect(0,0,ww,wh,utils.GetSysColor(15));
//bg_theme = window.CreateThemeManager("BUTTON");
//try { bg_theme.SetPartAndStateId(1, 1); }catch(e) {}
//try { bg_theme.DrawThemeBackground(gr, lpad, tpad, ww-lpad-rpad, bth); } catch(e) {}
gr.SetSmoothingMode(4);
gr.FillGradRect(lpad+1, tpad+1, ww-lpad-rpad-1, bth-3, 90, 0xfff4f4f4, 0xffe1e1e1, 1);
gr.DrawRoundRect(lpad, tpad, ww-lpad-rpad-2, bth-1, 3, 3, 1, 0xffb2b2b2);
gr.DrawRoundRect(lpad+1, tpad+1, ww-lpad-rpad-3, bth-3, 3, 3, 1, 0xfffafafa);
drawAllButtons(gr);
///Seekbar
gr.SetTextRenderingHint(5);
//For normal playback
if(fb.PlaybackLength>0)
{
gap = gr.CalcTextWidth(len.Eval(),font_labels)+8;
if(fb.PlaybackLength > fb.PlaybackTime)
{
if(g_drag)
pos = (ww-(2*lpad+2*rpad+8*btw)-2*gap) * g_drag_seek;
else
pos = (ww-(2*lpad+2*rpad+8*btw)-2*gap) * (fb.PlaybackTime / fb.PlaybackLength);
}
else
{
pos=0;
}
seekbg.DrawThemeBackground(gr,2*lpad+5*btw+gap-2,6,ww-(2*lpad+2*rpad+8*btw)-2*gap+4,18);
gr.GdiDrawText(elap.Eval(), font_labels, txtcol, 2*lpad+5*btw, 7, gap, wh-1, DT_CENTER);
gr.GdiDrawText(remain.Eval(), font_labels, txtcol, ww-gap-2*rpad-3*btw, 7, gap, wh-1, DT_CENTER);
seekfill.DrawThemeBackground(gr,2*lpad+5*btw+gap,8,pos,14);
}
//For streams
else if(fb.IsPlaying && (fb.PlaybackLength < 0 || filetype_eval == "mms"))
{
seekbg.DrawThemeBackground(gr,2*lpad+5*btw+2,6,ww-(2*lpad+2*rpad+10*btw)-4,18);
gr.GdiDrawText(elap.Eval()+" (continuous)", font_labels, txtcol, 0, 9, ww, wh, DT_CENTER);
}
}
function on_playback_stop()
{
if(g_timer){window.KillTimer(g_timer);}
buttons.pop.icon=gdi.Image(dir+"play"+".png");
buttons.pop.tooltiptxt="Play";
window.Repaint();
}
function on_playback_pause(is_paused)
{
buttons.pop.icon=is_paused?gdi.Image(dir+"play"+".png"):gdi.Image(dir+"pause"+".png");
buttons.pop.tooltiptxt=is_paused?"Play":"Pause";
window.Repaint();
}
function on_playback_starting(cmd, is_paused)
{
g_timer = window.CreateTimerInterval(40);
buttons.pop.icon=is_paused?gdi.Image(dir+"play"+".png"):gdi.Image(dir+"pause"+".png");
buttons.pop.tooltiptxt=is_paused?"Play":"Pause";
window.Repaint();
}
function on_playlist_stop_after_current_changed(state)
{
buttons.sac.icon=state?gdi.Image(dir+"sac_on"+".png"):gdi.Image(dir+"sac"+".png");
buttons.sac.tooltiptxt="Stop After Current "+(state?"(On)":"(Off)");
window.Repaint();
}
function on_cursor_follow_playback_changed(state)
{
buttons.cfp.icon=state?gdi.Image(dir+"cfp_on"+".png"):gdi.Image(dir+"cfp"+".png");
buttons.cfp.tooltiptxt="Cursor Follows Playback "+(state?"(On)":"(Off)");
window.Repaint();
}
function on_playback_follow_cursor_changed(state)
{
buttons.pfc.icon=state?gdi.Image(dir+"pfc_on"+".png"):gdi.Image(dir+"pfc"+".png");
buttons.pfc.tooltiptxt="Playback Follows Cursor "+(state?"(On)":"(Off)");
window.Repaint();
}
function on_playback_order_changed(new_order_index)
{
buttons.pbo.icon=gdi.Image(dir+PBOArray[fb.PlayBackOrder]+".png");
buttons.pbo.tooltiptxt = "Playback Order ("+PBOArray[fb.PlayBackOrder]+")";
window.Repaint();
}
function on_playback_seek(time)
{
window.Repaint();
}
function on_playback_time(time)
{
if(!g_timer){g_timer = window.CreateTimerInterval(40);}
window.Repaint();
}
function on_playback_new_track(metadb)
{
filetype_eval = filetype.Eval();
window.Repaint();
}
function on_timer(id)
{
window.RepaintRect(2*lpad+5*btw,0,ww-(2*lpad+2*rpad+10*btw),wh);
}
////Seekbar
var g_drag = 0;
var g_drag_seek = 0;
//Titleformatting
var len = fb.Titleformat("%length%");
var elap = fb.TitleFormat("%playback_time%");
var remain = fb.TitleFormat("$if2(%playback_time_remaining%,continuous)");
var pos = 0;
var gap = 0;
var g_timer;
var filetype = fb.TitleFormat("$left(%path%,3)");
var filetype_eval;
var seekbg = window.CreateThemeManager("Progress");
try { seekbg.SetPartAndStateID(1,1); }
catch(e){}
var seekfill = window.CreateThemeManager("Progress");
try { seekfill.SetPartAndStateID(3,1); }
catch(e){}
function on_item_focus_change() { window.Repaint(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment