Skip to content

anonymous /gist:a8d1e1ffe3916411838c secret

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
buttons.js
var dir = fb.FoobarPath+"\\images\\current\\";
var tooltip = window.CreateTooltip();
var activebtn = null;
var lastbtn = null;
var menuOn = false;
var lpad = window.GetProperty("Padding: Left",2);
var rpad = window.GetProperty("Padding: Right",2);
var tpad = window.GetProperty("Padding: Top",2);
var btw = window.GetProperty("Button Width",30);
var bth = window.GetProperty("Button Height",26);
//var tooltips_on = window.GetProperty("Tooltips",true);
//window.NotifyOthers("Buttons", tooltips_on);
ButtonStates = { normal: 0, hover: 1, down: 2 }
function button(icon,func_onClick,tooltiptxt,x,y,w,h)
{
this.icon=gdi.Image(dir+icon+".png");
this.state=ButtonStates.normal;
this.x=Math.floor(x);
this.y=y?y:tpad;
this.w=w?w:btw;
this.h=h?h:bth;
this.onClick = function(x,y) { func_onClick && func_onClick(x,y); }
//this.tooltiptxt=tooltiptxt;
this.isMouseOver = function (x, y)
{
return (this.x <= x) && (x < this.x + this.w) && (this.y <= y) && (y < this.y+this.h);
}
this.draw = function (gr)
{
g_theme = window.CreateThemeManager("Button");
switch(this.state)
{
case(ButtonStates.hover):
try { g_theme.SetPartAndStateId(1, 2);
g_theme.DrawThemeBackground(gr, this.x, this.y, this.w, this.h); } catch(e){}
break;
case(ButtonStates.down):
try { g_theme.SetPartAndStateId(1, 3);
g_theme.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);} catch(e){}
break;
}
gr.DrawImage(this.icon, this.x+this.w/2-this.icon.Width/2+((this.state==2)?1:0), this.y+this.h/2-this.icon.Height/2, this.icon.Width, this.icon.Height, 0, 0, this.icon.Width, this.icon.Height);
}
}
function drawAllButtons(gr)
{
for (i in buttons) buttons[i].draw(gr);
}
function getMouseOverBtn(x, y)
{
for (i in buttons)
if(buttons[i].isMouseOver(x, y))
return buttons[i];
return null;
}
function on_mouse_move(x, y)
{
if(lastbtn) lastbtn.state = ButtonStates.normal;
btn = getMouseOverBtn(x, y);
if(btn)
{
if(btn == activebtn)
btn.state = ButtonStates.down;
else if(!activebtn)
btn.state = ButtonStates.hover;
//tooltip.Text = btn.tooltiptxt;
//if(tooltips_on && btn != lastbtn ) tooltip.Activate();
}
lastbtn = btn;
//if( lastbtn == null ) tooltip.Deactivate();
if(fb.IsPlaying&&fb.PlaybackLength>0 && x>(2*lpad+5*btw) && x<(ww-2*rpad-3*btw))
{
g_drag_seek = (x<(2*lpad+5*btw+gap))?0:(x>(ww-gap-3*btw-2*rpad))?1:(x-(2*lpad+5*btw+gap))/(ww-2*lpad-2*rpad-8*btw-2*gap);
g_drag_seek = (g_drag_seek<0) ? 0 : (g_drag_seek<1) ? g_drag_seek : 1;
tooltip.Text = "Skip to " + TimeFmt(Math.floor(1000*g_drag_seek*fb.PlaybackLength)/1000);
tooltip.Activate();
}
else
{
tooltip.Deactivate();
}
window.Repaint();
}
function on_mouse_lbtn_down(x,y)
{
if(btn) btn.state = ButtonStates.down;
activebtn = getMouseOverBtn(x, y);
if(x>(2*lpad+5*btw) && x<(ww-2*rpad-3*btw))
{
if(fb.PlaybackLength){g_drag = 1;}
g_drag_seek = (x<(2*lpad+5*btw+gap))?0:(x>(ww-gap-3*btw-2*rpad))?1:(x-(2*lpad+5*btw+gap))/(ww-2*lpad-2*rpad-8*btw-2*gap);
g_drag_seek = (g_drag_seek<0) ? 0 : (g_drag_seek<1) ? g_drag_seek : 1;
}
window.Repaint();
}
function on_mouse_lbtn_up(x, y)
{
if(btn && btn == activebtn) btn.onClick(x,y);
activebtn = null;
if(g_drag && x>(2*lpad+5*btw) && x<(ww-2*rpad-3*btw))
{
g_drag = 0;
g_drag_seek = (x<(2*lpad+5*btw+gap))?0:(x>(ww-gap-3*btw-2*rpad))?1:(x-(2*lpad+5*btw+gap))/(ww-2*lpad-2*rpad-8*btw-2*gap);
g_drag_seek = (g_drag_seek<0) ? 0 : (g_drag_seek<1) ? g_drag_seek : 1;
fb.PlaybackTime = fb.PlaybackLength * g_drag_seek;
}
window.Repaint();
}
function on_mouse_leave()
{
lastbtn = null;
btn = null;
for (i in buttons)
{
if(menuOn && buttons[i] == activebtn)
buttons[i].state = ButtonStates.down;
else
buttons[i].state = ButtonStates.normal;
}
window.Repaint();
tooltip.Deactivate();
}
//Time formatting
function TimeFmt(t){
var zpad = function(n){
var str = n.toString();
return (str.length<2) ? "0"+str : str;
}
var h = Math.floor(t/3600); t-=h*3600;
var m = Math.floor(t/60); t-=m*60;
var s = Math.floor(t);
if(h>0) return h.toString()+":"+zpad(m)+":"+zpad(s);
return m.toString()+":"+zpad(s);
}
/* function on_mouse_rbtn_up(x, y, mask)
{
var ttmenu = window.CreatePopupMenu();
ttmenu.AppendMenuItem(MF_STRING, 1, "Tooltips");
ttmenu.AppendMenuSeparator();
ttmenu.AppendMenuItem(MF_STRING, 2, "Properties");
ttmenu.AppendMenuItem(MF_STRING, 3, "Configure");
ttmenu.CheckMenuItem(1, tooltips_on);
ret = ttmenu.TrackPopupMenu(x, y);
switch(ret)
{
case 1:
tooltips_on = !tooltips_on;
window.SetProperty("Tooltips",tooltips_on);
window.NotifyOthers("Buttons", tooltips_on);
break;
case 2:
window.ShowProperties();
break;
case 3:
window.ShowConfigure();
break;
}
ttmenu.Dispose();
return true;
}
function on_notify_data(name, info)
{
tooltips_on = info;
window.SetProperty("Tooltips",tooltips_on);
} */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.