I have a panel for "playback button + status bar" within single panel.
The little buggy point is that the panel doesn't refresh when I resize foobar.
The buttons and status information stick to the initial postion even after I resized my foobar.
So, I want to know if there is any method to refresh this panel whenever I change the foobar size.
Thank you for your help.
// ==PREPROCESSOR==
// @name "Playback Buttons"
// @author "marc2003"
// @import "%fb2k_profile_path%js_marc2003\js\lodash.min.js"
// @import "%fb2k_profile_path%js_marc2003\js\helpers.js"
// @import "%fb2k_profile_path%js_marc2003\js\panel.js"
// ==/PREPROCESSOR==
var panel = new _.panel("Playback Buttons", ["custom_background"]);
var buttons = new _.buttons();
var bs = 32;
var guifx_font = _.gdiFont(guifx.font, 8, 1);
var ww = window.Width;
var wh = window.Height;
var left_text_tf = "%playback_time%[ / %length%] :: %__bitrate% kbps %codec% [%codec_profile% ]";
var text_colour = _.RGB(40, 40, 40);
var show_volume = window.GetProperty("2K3.STATUS.SHOW.VOLUME", true);
var font = _.gdiFont("Segoe UI", 11);
var count = 0;
var right_text = "";
var right_text_width = 0;
refresh();
buttons.buttons.menu = new _.button(5, 5, bs, bs, {normal : "buttons\\menu.png"}, function () { _.menu(0, 16); }, "Menu");
buttons.buttons.stop = new _.button(ww/2-2*bs-15, 5, bs, bs, {normal : "buttons\\stop.png"}, function () { fb.Stop(); }, "Stop");
buttons.buttons.play = new _.button(ww/2-bs-5, 5, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? "buttons\\play.png" : "buttons\\pause.png"}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "Play" : "Pause");
buttons.buttons.previous = new _.button(ww/2+5, 5, bs, bs, {normal : "buttons\\previous.png"}, function () { fb.Prev(); }, "Previous");
buttons.buttons.next = new _.button(ww/2+bs+15, 5, bs, bs, {normal : "buttons\\next.png"}, function () { fb.Next(); }, "Next");
buttons.update = function () {
this.buttons.play = new _.button(ww/2-bs-5, 5, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? "buttons\\play.png" : "buttons\\pause.png"}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? "Play" : "Pause");
window.RepaintRect(this.buttons.play.x, this.buttons.play.y, this.buttons.play.w, this.buttons.play.h);
}
function on_playlist_stop_after_current_changed() {
window.RepaintRect(buttons.buttons.stop.x, buttons.buttons.stop.y, buttons.buttons.stop.w, buttons.buttons.stop.h);
}
function on_size() {
panel.size();
window.MinHeight = 45;
window.MaxHeight = 45;
}
function on_paint(gr) {
panel.paint(gr);
buttons.paint(gr);
gr.SetTextRenderingHint(4);
if (fb.StopAfterCurrent)
gr.DrawString("", guifx_font, _.RGB(196, 30, 35), buttons.buttons.stop.x, buttons.buttons.stop.y + 1, buttons.buttons.stop.w, buttons.buttons.stop.h, SF_CENTRE);
if (fb.IsPlaying)
gr.GdiDrawText(_.tfe(left_text_tf), font, text_colour, 0, 2, ww - 55, font.Height, RIGHT);
if (count > 0)
gr.GdiDrawText(right_text, font, text_colour, 0, 22, ww - 5, font.Height, RIGHT);
if (show_volume)
gr.GdiDrawText(fb.Volume.toFixed(2) + " dB", font, text_colour, 0, 2, ww - 5, font.Height, RIGHT);
}
function on_playback_stop() {
buttons.update();
window.Repaint();
}
function on_playback_pause() {
buttons.update();
}
function on_playback_starting() {
buttons.update();
}
function on_mouse_move(x, y) {
buttons.move(x, y);
}
function on_mouse_leave() {
buttons.leave();
}
function on_mouse_lbtn_up(x, y) {
buttons.lbtn_up(x, y);
}
function on_mouse_rbtn_up(x, y) {
if (buttons.buttons.stop.trace(x, y)) {
var m = window.CreatePopupMenu();
m.AppendMenuItem(MF_STRING, 1, "Stop After Current");
m.CheckMenuItem(1, fb.StopAfterCurrent);
m.AppendMenuSeparator();
m.AppendMenuItem(MF_STRING, 2, "Configure...");
var idx = m.TrackPopupMenu(x, y);
if (idx == 1)
fb.StopAfterCurrent = !fb.StopAfterCurrent;
else if (idx == 2)
window.ShowConfigure();
m.Dispose();
return true;
} else {
return panel.rbtn_up(x, y);
}
}
function on_playback_time() {
window.Repaint();
}
function on_volume_change() {
window.Repaint();
}
function on_mouse_wheel(s) {
if (!show_volume)
return;
if (s == 1)
fb.VolumeUp();
else
fb.VolumeDown();
}
function on_mouse_lbtn_dblclk() {
fb.RunMainMenuCommand("View/Show now playing in playlist");
}
function on_mouse_rbtn_up(x, y) {
if (utils.IsKeyPressed(VK_SHIFT))
return false;
var m = window.CreatePopupMenu();
var c = fb.CreateContextMenuManager();
if (fb.IsPlaying) {
c.InitNowPlaying();
c.BuildMenu(m, 1, -1);
m.AppendMenuSeparator();
}
m.AppendMenuItem(MF_STRING, 10000, "Show volume");
m.CheckMenuItem(10000, show_volume);
m.AppendMenuSeparator();
m.AppendMenuItem(MF_STRING, 10001, "Configure...");
var idx = m.TrackPopupMenu(x, y);
switch (true) {
case idx == 0:
break;
case idx == 10000:
show_volume = !show_volume;
window.SetProperty("2K3.STATUS.SHOW.VOLUME", show_volume);
window.Repaint();
break;
case idx == 10001:
window.ShowConfigure();
break;
default:
c.ExecuteByID(idx - 1);
break;
}
m.Dispose();
c.Dispose();
return true;
}
function on_playlist_items_added(p) {
if (p == plman.ActivePlaylist)
refresh();
}
function on_playlist_items_removed(p) {
if (p == plman.ActivePlaylist)
refresh();
}
function on_playlist_switch() {
refresh();
}
function refresh() {
var items = plman.GetPlaylistItems(plman.ActivePlaylist);
count = items.Count;
right_text = count + (count == 1 ? " track :: " : " tracks :: ") + utils.FormatDuration(items.CalcTotalDuration()) + " :: " + utils.FormatFileSize(items.CalcTotalSize());
right_text_width = _.textWidth(right_text, font);
window.Repaint();
items.Dispose();
}