Last active
February 23, 2021 01:09
-
-
Save Onurtag/2ca60c42094b0c775907ec29daa63e8f to your computer and use it in GitHub Desktop.
Foobar2k Triangular JScript Panel volume bar (example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==PREPROCESSOR== | |
// @name "Volbar with GdiDrawText (Triangle mod)" | |
// @author "T.P Wang & Onurtag mod" | |
// @import "%fb2k_component_path%docs\flags.txt" | |
// @import "%fb2k_component_path%docs\helpers.txt" | |
// ==/PREPROCESSOR== | |
var g_font = gdi.Font("Segoe UI", 10, 0); | |
var g_drag = 0; | |
var ww = 0, wh = 0; | |
function on_size() { | |
ww = window.Width; | |
wh = window.Height; | |
} | |
function on_paint(gr) { | |
var volume = fb.Volume; | |
var pos = ww * vol2pos(volume); | |
var txt = volume.toFixed(2) + "dB"; | |
//You can set a custom background color here (Edit the RGB(240, 240, 240) value) | |
gr.FillSolidRect(0, 0, ww, wh, RGB(240, 240, 240)); | |
gr.SetTextRenderingHint(5); | |
gr.SetSmoothingMode(4); | |
gr.SetInterpolationMode(7); | |
var points1 = Array(0,wh-2,0,wh,pos-1,wh,pos-1,((wh-2)*(1-vol2pos(volume)))+1); | |
//You can set a custom triangle color here (Edit the RGB(94, 173, 255) value) | |
gr.FillPolygon(RGB(94, 173, 255), 0, points1); | |
//gr.GdiDrawText(txt, g_font, RGB(12, 12, 12), 0, 2, ww, wh, DT_CENTER | DT_VCENTER | DT_SINGLELINE); | |
//gr.GdiDrawText(vol2pos(volume).toFixed(2)+"||"+volume.toFixed(2), g_font, RGB(12, 12, 12), 0, 2, ww, wh, DT_SINGLELINE); | |
gr.GdiDrawText(txt, g_font, RGB(12, 12, 12), 0, 2, ww, wh, DT_SINGLELINE); | |
//gr.DrawRect(0, 1, ww - 1, wh - 2, 1.0, RGB(180, 180, 180)); //Puts a box around everything. | |
} | |
function on_mouse_lbtn_down(x, y) { | |
g_drag = 1; | |
} | |
function on_mouse_lbtn_up(x, y) { | |
on_mouse_move(x, y); | |
g_drag = 0; | |
} | |
function on_mouse_move(x, y) { | |
if (g_drag) { | |
var pos = x < 0 ? 0 : x > ww ? 1 : x / ww; | |
// pos2vol function is defined in docs\helpers.txt | |
fb.Volume = pos2vol(pos); | |
} | |
} | |
function on_mouse_wheel(delta) { | |
if (delta > 0) { | |
var newpos = vol2pos(fb.Volume) + 0.05; //%4 of bar whenever mwheel | |
if (newpos > 100) { | |
newpos = 100; | |
} | |
fb.Volume = pos2vol(newpos); | |
//fb.VolumeUp(); | |
} else { | |
var newpos = vol2pos(fb.Volume) - 0.05; | |
if (newpos < 0) { | |
newpos = 0; | |
} | |
fb.Volume = pos2vol(newpos); | |
//fb.VolumeDown(); | |
} | |
} | |
function on_volume_change(val) { | |
window.Repaint(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment