secret
Created

buttons.js

  • Download Gist
gistfile1.txt
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
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);
} */

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.