I'm working on seekbar. then I found out skipping repaint();
In on_timer() function , called window.RepaintRect() or window.Repaint(), but It didn't repaint in no burden program is running.
for checking, use code " bar.test = <value>; " in on_timer function, and reset variable " bar.test = 0;" in on_paint function.
next recursive on_timer function, check bar.test is empty with " if (bar.test) echo("error"); "
within playing a song, lots of error was printed in console.
there is other window.RepaintRect(..); code in on_playback_time function. but same results popped though make it comment.
Is this a bug? or miss something?
This is whole source code
// ==PREPROCESSOR==
// @name "j-seekbar"
// @version "0.3.3b"
// @author "jk007"
// ==/PREPROCESSOR==
var pn = "js| ",
debug = window.GetProperty("debug", 0),
dragging = 0,
cc=0, c0=0,
dragging_seek = 0,
timer, timerbar, timeout, g_now,
fz_song=12,fz_album=12, fz_info=12, fz_time=12,
last_x,
ww, wh,
bar={time:0,pos:0,interval:10},
song={posTime:0}
;
window.GetProperty("AutoResize",0);
window.GetProperty("SkipInst", 1);
window.MinHeight = 37;
window.MaxHeight = 185;
DT_TOP = 0x00000000;
DT_LEFT = 0x00000000;
DT_CENTER = 0x00000001;
DT_RIGHT = 0x00000002;
DT_VCENTER = 0x00000004;
DT_BOTTOM = 0x00000008;
DT_WORDBREAK = 0x00000010;
DT_CALCRECT = 0x00000400;
DT_NOPREFIX = 0x00000800;
DT_END_ELLIPSIS = 0x00008000;
ColorTypeCUI = {
text: 0,
selection_text: 1,
inactive_selection_text: 2,
background: 3,
selection_background: 4,
inactive_selection_background: 5,
active_item_frame: 6
};
ColorTypeDUI = {
text: 0,
background: 1,
highlight: 2,
selection: 3
};
(function get_colors(){
if (window.InstanceType) {
clr_txt = window.GetColorDUI(ColorTypeDUI.text);
clr_txt_hl = window.GetColorDUI(ColorTypeDUI.highlight);
clr_bckgrnd = window.GetColorDUI(ColorTypeDUI.background);
}
else {
clr_txt = window.GetColorCUI(ColorTypeCUI.text);
clr_txt_hl = window.GetColorCUI(ColorTypeCUI.text);
clr_bckgrnd = window.GetColorCUI(ColorTypeCUI.background);
}
})();
function on_size(){
debug && echo();
ww = window.Width;
wh = window.Height;
if (window.GetProperty("AutoResize") == 1)
window.MinHeight = window.MaxHeight = Math.max(37,ww * 185/2500);
else {
window.MinHeight = 37;
window.MaxHeight = 185;
}
fz_song = Math.floor(Math.max(12,Math.min(0.52*wh-5,0.0345*ww+2)));
fz_time = Math.floor(Math.max(12,Math.min(0.5*wh-5,0.0338*ww+2)));
fz_album = Math.floor(Math.max(11,Math.min(0.26*wh,0.0175*ww+4)));
fz_info = Math.floor(Math.max(11,Math.min(0.24*wh,0.0159*ww+4)));
compute_timeInfoWidth();
if (fb.IsPlaying) {
compute_repaintBarInterval();
if (!fb.IsPaused) timerbar = window.CreateTimerInterval(bar.interval);
}
}
function parseHMS(seconds)
{
var h, m, s;
seconds = Math.round(seconds);
h = Math.floor(seconds/3600);
m = Math.floor((seconds-=h*3600)/60);
s = seconds % 60;
return (h ? h+":" + (m<10 ? "0"+m : m) : m) + ":" + (s<10 ? "0"+s : s);
}
function on_paint(gr)
{
var timeInfo=song.length, pos, now;
if (fb.IsPlaying && fb.PlaybackLength)
{
now = g_now || fb.PlaybackTime;
pos = Math.round(now * bar.w);
if (now == bar.time) {
bar.test = 0;
bar.pos = pos;
} else if (pos < bar.pos) pos = bar.pos;
gr.FillGradRect(0, 0, pos, wh, 90, 0xffff1303, 0xffbe1303);
timeInfo = (fb.IsPaused ? "Paused ":"") + parseHMS(now) + " / " + song.length;
if (dragging) {
timeInfo = "< "+parseHMS(fb.PlaybackLength * dragging_seek) +" > "+ timeInfo;
gr.FillGradRect(0, 0, ww*dragging_seek, wh, 90, 0xa0f000f0, 0xb04000f0);
}
debug && gr.FillSolidRect(song.posTime,0,song.timeInfoWidth,wh,0x304000f0)
}
gr.SetTextRenderingHint(5);
gr.DrawString(timeInfo, gdi.Font("Segoe UI", fz_time, 3), clr_txt, 0, 1, ww-10, wh, 0x20000000);
gr.DrawString(song.codec, gdi.Font("Segoe UI", fz_info, 1), song.colorCodec, 0, 0, ww-10, wh-3, 0x22000000);
gr.gdiDrawText(song.album , gdi.Font("Segoe UI", fz_album, 2),clr_txt,20,0,ww-80, wh-2, DT_CALCRECT | DT_NOPREFIX|DT_BOTTOM);
gr.gdiDrawText(song.title, gdi.Font("Segoe UI", fz_song, 1), clr_txt, 7, 1, ww-17-song.timeInfoWidth*2, wh, DT_CALCRECT | DT_NOPREFIX);
}
function on_timer(id)
{
var now = fb.PlaybackTime;
var gap = now - bar.time;
0&&debug && echo("\t"+now.toFixed(5));
if (gap > 0){
if (bar.test) echo("Error Didn't repaint @ "+ bar.time);
bar.test = g_now = bar.time = now;
gap = Math.round(now*bar.w) - bar.pos;
window.RepaintRect(bar.pos, 0, gap, wh);
}
}
function on_playback_time(time)
{
g_now = time;
window.RepaintRect(song.posTime,0,song.timeInfoWidth,wh);
}
function on_playback_new_track()
{
debug && echo();
if (window.GetProperty("SkipInst") == 1 && fb.TitleFormat("%title%").Eval().match(/\(inst.|\(instrument|\(MR|instrumental\)/i))
fb.Next();
get_info();
//if (fb.isPaused) return;
compute_repaintBarInterval();
start_timer();
}
function compute_repaintBarInterval()
{
debug && echo(" + "+/.+\)/.exec(arguments.callee)+" ~~ "+/.+\)/.exec(arguments.callee.caller));
if (!ww || !fb.PlaybackLength) return false;
g_now = bar.time = bar.pos = 0;
bar.interval = Math.max(10,Math.round(fb.PlaybackLength*1000/ww));
bar.w = ww / fb.PlaybackLength;
debug && echo("bar.interval="+bar.interval+", ww="+ww+", PlaybackLength="+fb.PlaybackLength);
debug && echo("bar.w="+bar.w+"\t"+(bar.w*bar.interval/1000));
}
function start_timer()
{
window.Repaint();
debug && echo(" + "+/.+\)/.exec(arguments.callee)+" ~~ "+/.+\)/.exec(arguments.callee.caller));
timerbar = window.CreateTimerInterval(bar.interval);
}
function get_info()
{
song.title = fb.TitleFormat("%artist% - %title%").Eval(true);
song.length = fb.TitleFormat("%length%").Eval(true);
song.album = fb.TitleFormat("%album%[ '(' %date% ')'] [Disk %discnumber%]").Eval(true);
song.codec = fb.TitleFormat("$replace(%codec%,Monkey$char(39)s Audio,APE,PCM,WAV)[ %__codec_profile%] %__bitrate%kbps$ifequal(16,%__bitspersample%,,[ %__bitspersample%bit])$ifequal(44100,%__samplerate%,, %__samplerate%Hz)$if($strcmp(stereo,%channels%),, %channels%)").Eval(true);
song.colorCodec = (fb.TitleFormat("%__encoding%").Eval() == "lossy") ? 0xffff0000 : 0xff0000ff;
compute_timeInfoWidth();
}
function compute_timeInfoWidth()
{
// Using a temp IGdiGraphics interface
var temp_bmp = gdi.CreateImage(1, 1);
// Don't forget to call temp_bmp.ReleaseGraphics(temp_gr)!
var temp_gr = temp_bmp.GetGraphics();
song.timeInfoWidth = temp_gr.CalcTextWidth('/ '+song.length, gdi.Font("Segoe UI", fz_time, 3));
song.posTime = ww-10-song.timeInfoWidth*2;//*2.46;
// Free the resources
temp_bmp.ReleaseGraphics(temp_gr);
temp_bmp.Dispose();
}
function on_item_focus_change()
{
debug && echo();
if (fb.IsPlaying) return true;
get_info();
window.Repaint();
}
function on_playback_pause(state)
{
debug && echo();
if (state) {
timer && window.KillTimer(timer);
timeout && window.KillTimer(timeout);
timerbar && window.killTimer(timerbar);
CollectGarbage();
window.Repaint();
}
else
start_timer();
}
function on_playback_stop()
{
debug && echo();
timer && window.KillTimer(timer);
timeout && window.KillTimer(timeout);
timerbar && window.killTimer(timerbar);
window.Repaint();
CollectGarbage();
}
function on_playback_seek(time)
{
window.Repaint();
}
function on_mouse_lbtn_down(x,y)
{
if (fb.IsPlaying && fb.PlaybackLength > 0) {
dragging = 1;
dragging_seek = x < 0 ? 0 : x > ww ? 1 : x / ww;
last_x = x;
window.Repaint();
}
}
function on_mouse_lbtn_up(x,y)
{
if (dragging) {
g_now = bar.time = bar.pos = dragging = 0;
dragging_seek = x < 0 ? 0 : x > ww ? 1 : x / ww;
fb.PlaybackTime = fb.PlaybackLength * dragging_seek;
}
}
function on_mouse_move(x,y)
{
if (dragging && last_x != x) {
last_x = x;
dragging_seek = x < 0 ? 0 : x > ww ? 1 : x / ww;
if (y < 0 || wh < y) dragging = 0;
window.Repaint();
}
}
function on_colors_changed()
{
get_colors();
window.Repaint();
}
function echo(txt)
{
txt = txt || " + "+/.+\)/.exec(arguments.callee.caller);
fb.trace(pn+txt);
}
function on_mouse_rbtn_up(x, y)
{
var MF_SEPARATOR = 0x00000800;
var MF_STRING = 0x00000000;
var _menu = window.CreatePopupMenu();
var idx;
_menu.AppendMenuItem(MF_STRING, 14, "Debug mode");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 1, "Auto Resize");
_menu.AppendMenuItem(MF_STRING, 4, "Skip Instrumantal");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING, 2, "Properties");
_menu.AppendMenuItem(MF_STRING, 3, "Configure...");
_menu.CheckMenuItem(1, window.GetProperty("AutoResize")== 0 ? 0x0 : 0x8);
_menu.CheckMenuItem(4, window.GetProperty("SkipInst")== 0 ? 0x0 : 0x8);
_menu.CheckMenuItem(14, window.GetProperty("debug")== 0 ? 0 : 1);
idx = _menu.TrackPopupMenu(x, y);
switch (idx) {
case 1:
window.SetProperty("AutoResize", !window.GetProperty("AutoResize"));
on_size();
break;
case 2:
window.ShowProperties();
break;
case 3:
window.ShowConfigure();
break;
case 4:
window.SetProperty("SkipInst", !window.GetProperty("SkipInst"));
break;
case 14:
window.SetProperty("debug", !window.GetProperty("debug"));
debug = window.Getproperty('debug');
window.RepaintRect(song.posTime,0,song.timeInfoWidth,wh);
break;
}
_menu.Dispose();
return true;
}
(function (){
if (fb.isplaying)
on_playback_new_track();
else
on_item_focus_change();
})();