Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "WSH Simple Playlist Viewer"
- // @version "0.6.1"
- // @author "Br3tt"
- // @feature "dragdrop"
- // ==/PREPROCESSOR==
- //=================================================// Constants
- var DT_LEFT = 0x00000000;
- var DT_RIGHT = 0x00000002;
- var DT_TOP = 0x00000000;
- var DT_CENTER = 0x00000001;
- var DT_VCENTER = 0x00000004;
- var DT_WORDBREAK = 0x00000010;
- var DT_SINGLELINE = 0x00000020;
- var DT_CALCRECT = 0x00000400;
- var DT_NOPREFIX = 0x00000800;
- var DT_EDITCONTROL = 0x00002000;
- var DT_END_ELLIPSIS = 0x00008000;
- var VK_BACK = 0x08;
- var VK_RETURN = 0x0D;
- var VK_SHIFT = 0x10;
- var VK_CONTROL = 0x11;
- var VK_ALT = 0x12;
- var VK_ESCAPE = 0x1B;
- var VK_PGUP = 0x21;
- var VK_PGDN = 0x22;
- var VK_END = 0x23;
- var VK_HOME = 0x24;
- var VK_LEFT = 0x25;
- var VK_UP = 0x26;
- var VK_RIGHT = 0x27;
- var VK_DOWN = 0x28;
- var VK_INSERT = 0x2D;
- var VK_DELETE = 0x2E;
- var KMask = {
- none: 0,
- ctrl: 1,
- shift: 2,
- ctrlshift: 3,
- ctrlalt: 4,
- ctrlaltshift: 5
- }
- //=================================================// Globals
- var myitem = Array();
- var myscreen = Array();
- var myscrollbarbt = Array();
- var mytoolbarbt = Array();
- var ttt;
- var g_metadb;
- var g_metadb_playlist;
- var g_is_focused;
- var g_start_new_track = false;
- var ww, wh;
- var mouse_x;
- var mouse_y;
- var refresh_timer;
- var scroller_drag_timer;
- var draw_cover_timer;
- var init_mouse_down_timer;
- var mouse_down_timer;
- var wheel_up_timer;
- var wheel_dn_timer;
- var wheel_up_timer;
- var wheel_dn_timer;
- var cover_w = 45;
- var cover_h = 45;
- var cover_margin = 5;
- var g_playtime_parity = 0;
- var foo_playcount = utils.CheckComponent("foo_playcount", true);
- // rating globals
- var rating_x = 0;
- var rating_y = 0;
- var rating_w, rating_h;
- var hand;
- //=================================================// Image declarations
- var playicon_off;
- var scroller;
- var scroller_popup;
- var nocover;
- var streamcover;
- var star_img_off;
- var star_img_on;
- var star_img_hov;
- var star_img_kill;
- var scrollbarbt_menu;
- var scrollbarbt_up;
- var scrollbarbt_down;
- var mytoolbarbt_shownowplaying;
- var mytoolbarbt_scrollbar;
- //=================================================// Tools
- function RGB(r, g, b) {
- return (0xff000000 | (r << 16) | (g << 8) | (b))
- }
- function RGBA(r, g, b, a) {
- return ((a << 24) | (r << 16) | (g << 8) | (b))
- }
- function GetKeyboardMask() {
- var c = utils.IsKeyPressed(VK_CONTROL) ? true : false;
- var a = utils.IsKeyPressed(VK_ALT) ? true : false;
- var s = utils.IsKeyPressed(VK_SHIFT) ? true : false;
- var ret = KMask.none;
- if (c && !a && !s) ret = KMask.ctrl;
- if (!c && !a && s) ret = KMask.shift;
- if (c && !a && s) ret = KMask.ctrlshift;
- if (c && a && !s) ret = KMask.ctrlalt;
- if (c && a && s) ret = KMask.ctrlaltshift;
- return ret;
- }
- function num(strg, nb) {
- var i;
- var str = strg.toString();
- var k = nb - str.length;
- if (k > 0) {
- for (i=0;i<k;i++) {
- str = "0" + str;
- }
- }
- return str.toString();
- }
- function StringFormat() {
- var h_align = 0,
- v_align = 0,
- trimming = 0,
- flags = 0;
- switch (arguments.length) {
- case 3:
- trimming = arguments[2];
- case 2:
- v_align = arguments[1];
- case 1:
- h_align = arguments[0];
- break;
- default:
- return 0;
- }
- return ((h_align << 28) | (v_align << 24) | (trimming << 20) | flags);
- }
- var StringAlignment = {
- Near: 0,
- Centre: 1,
- Far: 2
- };
- var lt_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Near);
- var ct_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Near);
- var rt_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Near);
- var lc_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Centre);
- var cc_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Centre);
- var rc_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Centre);
- var lb_stringformat = StringFormat(StringAlignment.Near, StringAlignment.Far);
- var cb_stringformat = StringFormat(StringAlignment.Centre, StringAlignment.Far);
- var rb_stringformat = StringFormat(StringAlignment.Far, StringAlignment.Far);
- //=================================================// Title Format
- var tf_path = fb.TitleFormat("$left(%_path_raw%,4)");
- var tf_cover_path = fb.TitleFormat("$replace(%path%,%filename_ext%,)");
- var tf_tracknumber = fb.TitleFormat("%tracknumber%");
- var tf_artist = fb.TitleFormat("$if(%length%,%artist%,'Stream')");
- var tf_title = fb.TitleFormat("%title%");
- var tf_albumartist = fb.TitleFormat("$if(%length%,%album artist%,'Stream')");
- var tf_album = fb.TitleFormat("$if2(%album%,$if(%length%,'Single','web radios'))");
- var tf_disc = fb.TitleFormat("$if2(%discnumber%,0)");
- var tf_rating = fb.TitleFormat("$if2(%rating%,0)");
- var tf_length = fb.TitleFormat("$if2(%length%,' 0:00')");
- var tf_date = fb.TitleFormat("$if2($year(%date%),)");
- var tf_playback_time = fb.TitleFormat("%playback_time%");
- var tf_playback_time_remaining = fb.TitleFormat("$if(%length%,-%playback_time_remaining%,'0:00')");
- //=================================================// Objects
- button = function () {
- this.font = gdi.Font("segoe ui", 12, 0);
- this.ButtonStates = {
- normal: 0,
- hover: 1,
- down: 2
- };
- var tmp;
- this.create = function (normal, hover, down, id) {
- if (normal.Width) {
- this.normal = normal.Width?normal:gdi.Image(normal);
- this.hover = hover.Width?hover:gdi.Image(hover);
- this.down = down.Width?down:gdi.Image(down);
- this.zorder = id;
- this.x = 0;
- this.y = 0;
- this.w = this.normal.Width;
- this.h = this.normal.Height;
- this.state = this.ButtonStates.normal;
- this.g_timer_counter = 0;
- }
- }
- this.resize = function (w, h) {
- if (typeof this.normal != "undefined") {
- this.normal.Resize(w, h);
- this.hover.Resize(w, h);
- this.down.Resize(w, h);
- this.w = w;
- this.h = h;
- }
- }
- this.ontimer = function (id) {
- if (this.g_timer) {
- switch (id) {
- case this.g_timer.ID:
- if (this.g_timer_sens == 1) {
- this.g_timer_counter = (this.g_timer_counter < 10) ? this.g_timer_counter + 2 : this.g_timer_counter;
- if (this.g_timer_counter == 10) this.g_timer && window.KillTimer(this.g_timer);
- } else {
- this.g_timer_counter = (this.g_timer_counter > 0) ? this.g_timer_counter - 2 : 0;
- if (this.g_timer_counter == 0) this.g_timer && window.KillTimer(this.g_timer);
- }
- if (this.y >= 0) {
- window.RepaintRect(this.x, this.y, this.w + 1, this.h + 1)
- }
- break;
- }
- }
- }
- this.draw = function (gr, bx, by, alpha, label) {
- this.x = bx;
- this.y = by;
- switch (this.state) {
- case this.ButtonStates.normal:
- this.img_displayed = this.normal;
- break;
- case this.ButtonStates.hover:
- this.img_displayed = this.hover;
- break;
- case this.ButtonStates.down:
- this.img_displayed = this.down;
- break;
- }
- switch (alpha) {
- case 000:
- gr.DrawImage(this.img_displayed, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h, 0, 255);
- break;
- case 100:
- gr.DrawImage(this.img_displayed, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h, 0, 060);
- break;
- case 888:
- gr.DrawImage(this.img_displayed, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h, 0, 215 + this.g_timer_counter * 04);
- break;
- case 999:
- gr.DrawImage(this.img_displayed, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h, 0, 175 + this.g_timer_counter * 08);
- break;
- default:
- gr.DrawImage(this.img_displayed, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h, 0, 115 + this.g_timer_counter * 14);
- break;
- }
- }
- this.checkstate = function (event, x, y, id) {
- if (x > this.x && x < this.x + this.w - 1 && y > this.y && y < this.y + this.h - 1) {
- this.is_hover = true;
- this.mousecursor = 32649;
- } else {
- this.is_hover = false;
- this.mousecursor = 32512;
- }
- switch (event) {
- case "down":
- if (this.is_hover) {
- this.state = this.ButtonStates.down;
- } else if (this.state == this.ButtonStates.down) {
- this.state = this.ButtonStates.normal;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer_sens = 0;
- this.g_timer = window.CreateTimerInterval(40);
- }
- break;
- case "right":
- if (this.is_hover) {
- display_context_menu(x, y, id);
- }
- break;
- case "move":
- if (this.is_hover) {
- if (this.state != this.ButtonStates.down) {
- if (this.state != this.ButtonStates.hover) {
- this.g_timer_sens = 1;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer = window.CreateTimerInterval(40);
- this.state = this.ButtonStates.hover;
- }
- }
- } else if (this.state == this.ButtonStates.hover) {
- this.state = this.ButtonStates.normal;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer_sens = 0;
- this.g_timer = window.CreateTimerInterval(40)
- }
- break;
- case "up":
- if (this.is_hover) {
- if (this.state == this.ButtonStates.down) {
- this.state = this.ButtonStates.hover;
- } else {
- this.state = this.ButtonStates.normal;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer_sens = 0;
- this.g_timer = window.CreateTimerInterval(40);
- }
- } else {
- this.state = this.ButtonStates.normal;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer_sens = 0;
- this.g_timer = window.CreateTimerInterval(40);
- }
- break;
- case "leave":
- this.state = this.ButtonStates.normal;
- this.g_timer && window.KillTimer(this.g_timer);
- this.g_timer_sens = 0;
- this.g_timer = window.CreateTimerInterval(40);
- break;
- }
- if (this.y >= 0) {
- this.is_hover && window.RepaintRect(this.x, this.y, this.w + 1, this.h + 1);
- }
- return this.state;
- }
- }
- IC = {
- list_total: 0,
- height: window.GetProperty("Row Height", 28),
- show_coverart: window.GetProperty("Show Cover Art", true),
- draw_cover: false,
- pad_top: 0,
- pad_bot: 0,
- pad_left: 0,
- pad_right: 0,
- toolbar: window.GetProperty("Show Toolbar", false),
- default_toolbar_height: window.GetProperty("Default Toolbar Height", 20),
- toolbar_height: this.default_toolbar_height,
- scrollbar: window.GetProperty("Show Scrollbar", true),
- scrollbar_y : 0,
- scrollbar_h : 0,
- scrollbar_bt_h : 20,
- scrollbar_width: window.GetProperty("Scrollbar Width", 17),
- scroller_y: 0,
- scroller_drag: false,
- font: gdi.Font("segoe ui", 12, 0),
- scroll: window.GetProperty("Scrolling", false),
- scrollstep: window.GetProperty("Scroll Step", 3),
- pos: window.GetProperty("Item Offset", 0),
- ghnbrows: window.GetProperty("Group Header rows number", 2),
- artist_group_font: gdi.Font("segoe ui", 17, 0),
- album_group_font: gdi.Font("segoe ui", 12, 0),
- rating_font: gdi.Font("guifx v2 transports", 17, 0),
- grp_total_items_font: gdi.Font("segoe ui", 12, 1),
- nbvis: 0,
- topcut: window.GetProperty("Group Offset", 0),
- scrollstep_min: 0,
- total_items_visible: 0,
- paint_count: 0,
- metadblist_selection: plman.GetPlaylistSelectedItems(fb.ActivePlaylist),
- context_menu_called: false,
- nb_hidden_lines: 0,
- nowplaying: plman.GetPlayingItemLocation(),
- singleton_select_id: 0,
- bot_reached: false,
- scroll_down: false
- };
- item = function () {
- var i;
- this.ItemStates = {
- normal: 0,
- hover: 1,
- selected: 2
- };
- this.create = function(id, metadb, idx) {
- if (typeof this.id == "undefined") {
- this.idx = idx;
- this.id = id;
- this.state = this.ItemStates.normal;
- this.metadb = metadb;
- if(metadb) {
- this.track_type = TrackType(this.metadb.rawpath.substring(0,4));
- this.tracknumber = tf_tracknumber.EvalWithMetadb(this.metadb);
- if(this.tracknumber=="?") this.tracknumber = num(this.id+1,2);
- this.artist = tf_artist.EvalWithMetadb(this.metadb);
- this.title = tf_title.EvalWithMetadb(this.metadb);
- this.albumartist = tf_albumartist.EvalWithMetadb(this.metadb);
- this.album = tf_album.EvalWithMetadb(this.metadb);
- this.disc = tf_disc.EvalWithMetadb(this.metadb);
- this.rating = tf_rating.EvalWithMetadb(this.metadb);
- this.length = tf_length.EvalWithMetadb(this.metadb);
- this.date = tf_date.EvalWithMetadb(this.metadb);
- this.group_key = this.albumartist+this.album+this.disc;
- }
- this.x = 0;
- this.y = 0;
- this.w = ww - IC.pad_left - IC.pad_right - (IC.scrollbar?IC.scrollbar_width:0);
- this.h = IC.height - IC.pad_top - IC.pad_bot;
- }
- }
- this.template_it = function(id, metadb) {
- if (typeof this.id == "undefined") {
- this.id = id;
- this.metadb = metadb;
- if(metadb) {
- this.albumartist = tf_albumartist.EvalWithMetadb(this.metadb);
- this.album = tf_album.EvalWithMetadb(this.metadb);
- this.disc = tf_disc.EvalWithMetadb(this.metadb);
- this.group_key = this.albumartist+this.album+this.disc;
- }
- }
- }
- this.draw = function (gr, id) {
- this.w = ww - IC.pad_left - IC.pad_right - (IC.scrollbar?IC.scrollbar_width:0);
- // Draw group header
- if(IC.ghnbrows>0 && this.gridx!=0) {
- var artist_group_text_colour = RGB(220, 220, 220);
- var album_group_text_colour = RGB(160, 160, 160);
- var group_y = this.y - (this.gridx-1)*IC.height;
- // get cover art (from cache or disk)
- if(IC.show_coverart && this.metadb) {
- this.cover_path = this.metadb.path;
- this.cover_img = g_image_cache.hit(this);
- }
- gr.FillGradRect(this.x, group_y, this.w, IC.ghnbrows*IC.height, 90, RGB(245,245,245), RGB(230,230,230), 1.0);
- gr.FillSolidRect(this.x, group_y, this.w, 1, RGB(210,210,210));
- gr.FillSolidRect(this.x, group_y+1, this.w, 1, RGB(255,255,255));
- gr.FillSolidRect(this.x, group_y+IC.ghnbrows*IC.height-1, this.w, 1, RGB(200,200,200));
- gr.GdiDrawText(this.albumartist, IC.artist_group_font, RGB(160,160,160), this.x + 10 + cover_w, group_y+2, this.w-20-cover_w, Math.ceil(IC.ghnbrows*IC.height/2), DT_LEFT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.GdiDrawText(this.albumartist, IC.artist_group_font, RGB(255,255,255), this.x + 10 + cover_w, group_y+4, this.w-20-cover_w, Math.ceil(IC.ghnbrows*IC.height/2), DT_LEFT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.GdiDrawText(this.albumartist, IC.artist_group_font, artist_group_text_colour, this.x + 10 + cover_w, group_y+3, this.w-20-cover_w, Math.ceil(IC.ghnbrows*IC.height/2), DT_LEFT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.GdiDrawText(this.album, IC.album_group_font, RGB(255,255,255), this.x + 10 + cover_w, group_y+Math.ceil(IC.ghnbrows*IC.height/2)-0, this.w-20-cover_w, Math.ceil(IC.ghnbrows*IC.height/2), DT_LEFT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.GdiDrawText(this.album, IC.album_group_font, album_group_text_colour, this.x + 10 + cover_w, group_y+Math.ceil(IC.ghnbrows*IC.height/2)-1, this.w-20-cover_w, Math.ceil(IC.ghnbrows*IC.height/2), DT_LEFT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- if(IC.show_coverart && this.cover_img) {
- gr.DrawRect(this.x+cover_margin-1+5, group_y+cover_margin-1, cover_w-cover_margin*2+1, cover_h-cover_margin*2+1, 1.0, RGBA(0,0,0,15));
- gr.DrawRect(this.x+cover_margin+1+5, group_y+cover_margin+1, cover_w-cover_margin*2-1, cover_h-cover_margin*2-1, 1.0, RGBA(0,0,0,120));
- gr.DrawRect(this.x+cover_margin+2+5, group_y+cover_margin+2, cover_w-cover_margin*2-1, cover_h-cover_margin*2-1, 1.0, RGBA(0,0,0,40));
- gr.DrawImage(this.cover_img, this.x+cover_margin+5, group_y+cover_margin, cover_w-cover_margin*2, cover_h-cover_margin*2, 0, 0, cover_w, cover_h, 0, 255);
- }
- if(this.date.length>0 && this.gridx==IC.ghnbrows) {
- gr.SetSmoothingMode(2);
- gr.FillRoundRect(this.x+this.w-50, this.y-9, 40, 18, 3, 3, RGBA(0,0,0,050));
- gr.GdiDrawText(this.date, IC.grp_total_items_font, RGB(255,255,255), this.x+this.w-50, this.y-9+1, 40, 18, DT_CENTER | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.SetSmoothingMode(0);
- }
- }
- // Draw item
- if(this.gridx==0) {
- var parity = (this.id/2-Math.floor(this.id/2)==0)?0:1;
- if(this.metadb.Compare(fb.GetFocusItem())) {
- if(this.state!=this.ItemStates.selected) {
- this.state = this.ItemStates.selected;
- if(IC.metadblist_selection.Count==0) {
- IC.metadblist_selection.RemoveAll();
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, g_metadb_playlist.Find(this.metadb), true);
- IC.metadblist_selection.Add(this.metadb);
- }
- IC.singleton_select_id = this.id;
- }
- }
- switch(this.state) {
- case this.ItemStates.normal:
- var text_colour = RGB(120, 120, 120);
- var artist_text_colour = RGB(180, 180, 180);
- var title_text_colour = RGB(120, 120, 120);
- break;
- case this.ItemStates.hover:
- var text_colour = RGB(120, 120, 120);
- var artist_text_colour = RGB(180, 180, 180);
- var title_text_colour = RGB(120, 120, 120);
- break;
- case this.ItemStates.selected:
- var text_colour = RGB(60, 80, 220);
- var artist_text_colour = RGB(140, 160, 250);
- var title_text_colour = RGB(60, 80, 220);
- break;
- }
- // Item background
- var bg_colour = (parity==0)?RGB(247, 247, 247):RGB(250,250,250);
- gr.FillSolidRect(this.x, this.y, this.w, this.h, bg_colour);
- gr.FillGradRect(this.x, this.y, this.w, 1, 0, 0, RGB(220,220,220), 0.5);
- gr.FillGradRect(this.x, this.y+1, this.w, 1, 0, 0, RGB(255,255,255), 0.5);
- if(this.state==this.ItemStates.selected) {
- gr.FillSolidRect(this.x, this.y, this.w, 1, RGB(225,225,225));
- gr.FillGradRect(this.x, this.y+1, this.w, this.h/2+1, 90, RGB(235,245,255), 0, 1.0);
- }
- // if last item, draw bottom shadow!
- if(this.id==IC.list_total-1) {
- gr.FillGradRect(this.x, this.y+this.h, this.w, 4, 90, RGB(90,90,90), 0, 1.0);
- }
- // tag fields display
- gr.GdiDrawText(this.tracknumber+".", IC.font, text_colour, this.x + 10, this.y, 50, this.h, DT_RIGHT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- if(this.artist!=this.albumartist) {
- gr.GdiDrawText(this.title+" "+this.artist, IC.font, artist_text_colour, this.x + 70, this.y, this.w-70-65-60, this.h, DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- gr.GdiDrawText(this.title+" ", IC.font, title_text_colour, this.x + 70, this.y, this.w-70-65-60, this.h, DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- } else {
- gr.GdiDrawText(this.title, IC.font, title_text_colour, this.x + 70, this.y, this.w-70-65-60, this.h, DT_NOPREFIX | DT_CALCRECT | DT_VCENTER | DT_END_ELLIPSIS);
- }
- // draw play icon + time
- if(fb.PlayingPlaylist==fb.ActivePlaylist) {
- if(fb.IsPlaying && this.metadb.Compare(fb.GetNowPlaying())) {
- gr.DrawImage(playicon_off, this.x + 5, this.y+this.h/2-playicon_off.Height/2-1, playicon_off.Width, playicon_off.Height, 0, 0, playicon_off.Width, playicon_off.Height, 0, (g_playtime_parity==1)?255:127);
- if(this.length==" 0:00") {
- this.playback_time_remaining = tf_playback_time.Eval(true);
- } else {
- this.playback_time_remaining = tf_playback_time_remaining.Eval(true);
- }
- gr.GdiDrawText(this.playback_time_remaining, IC.font, text_colour, this.w - 60, this.y, 50, this.h, DT_RIGHT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER);
- } else {
- gr.GdiDrawText(this.length, IC.font, text_colour, this.w - 60, this.y, 50, this.h, DT_RIGHT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER);
- }
- } else {
- gr.GdiDrawText(this.length, IC.font, text_colour, this.w - 60, this.y, 50, this.h, DT_RIGHT | DT_NOPREFIX | DT_CALCRECT | DT_VCENTER);
- }
- // Rating engine
- this.rating_x = this.x+this.w-120;
- this.rating_y = this.y + Math.round(IC.height/2 - star_img_off.Height/2)+1;
- if(this.rating_hov) {
- for (i = 1; i < 6; i++){
- if(this.track_type<2){
- var img = (i > (this.rating_hov ? this.l_rating : this.rating)) ? star_img_off : (this.rating_hov ? (i==this.rating ? (i==this.l_rating ? star_img_kill : star_img_hov) : star_img_hov) : star_img_on);
- if(this.rating_hov && this.l_rating==this.rating) {
- img = i<=this.l_rating ? star_img_kill : star_img_off;
- }
- } else {
- var img = star_img_off;
- }
- gr.DrawImage(img, this.rating_x+img.Width*(i-1), this.rating_y, img.Width, img.Height, 0, 0, img.Width, img.Height, 0, 255);
- }
- } else {
- gr.SetTextRenderingHint(4);
- for(i=0;i<5;i++) {
- gr.DrawString("b", IC.rating_font, (i+1<=this.rating)?title_text_colour:RGB(230,230,230), this.rating_x+i*13, this.rating_y, 13, 18, lt_stringformat);
- }
- }
- }
- }
- this.checkstate = function (event, x, y, id) {
- this.ishover = (this.gridx==0 && x > this.x && x < this.x + this.w && y >= this.y && y < this.y + this.h)?true:false;
- this.isgrphover = (this.gridx>0 && x > this.x && x < this.x + this.w && y >= this.y && y < this.y + this.h)?true:false;
- var tmp = this.rating_hov;
- var tmp_l_rating = this.l_rating;
- this.rating_hov = (this.gridx==0 && x > this.x+this.w-120 && x < this.x+this.w-55 && y > this.rating_y+4 && y < this.rating_y + 18)?true:false;
- switch (event) {
- case "down":
- switch(this.state) {
- case this.ItemStates.normal:
- case this.ItemStates.hover:
- if(this.ishover && !this.rating_hov) {
- if(utils.IsKeyPressed(VK_CONTROL)) { // if Ctrl key pressed, add item to selection
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, this.id);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, this.id, true);
- this.state = this.ItemStates.selected;
- IC.singleton_select_id = this.id;
- on_item_focus_change();
- } else if(utils.IsKeyPressed(VK_SHIFT)) {
- if(IC.singleton_select_id != this.id) {
- SelectAtoB(IC.singleton_select_id, this.id);
- }
- } else {
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, this.id);
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, this.id, true);
- this.state = this.ItemStates.selected;
- IC.singleton_select_id = this.id;
- on_item_focus_change();
- }
- } else if(this.isgrphover) {
- SelectGroupItems(this.id, this.group_key);
- }
- break;
- case this.ItemStates.selected:
- if(this.ishover && !this.rating_hov && IC.metadblist_selection.Count>1) {
- if(utils.IsKeyPressed(VK_CONTROL)) { // if Ctrl key pressed, remove item from selection
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, this.id, false);
- this.state = this.ItemStates.hover;
- on_item_focus_change();
- } else {
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, this.id);
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, this.id, true);
- this.state = this.ItemStates.selected;
- IC.singleton_select_id = this.id;
- on_item_focus_change();
- }
- }
- break;
- }
- break;
- case "dblclk":
- switch(this.state) {
- case this.ItemStates.selected:
- if(this.ishover && !this.rating_hov) {
- fb.RunContextCommandWithMetadb("Play", this.metadb);
- }
- break;
- }
- break;
- case "right":
- if(this.ishover && !this.rating_hov) {
- switch(this.state) {
- case this.ItemStates.normal:
- case this.ItemStates.hover:
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, this.id);
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, this.id, true);
- this.state = this.ItemStates.selected;
- on_item_focus_change();
- break;
- }
- new_context_menu(x, y, this.id, this.idx);
- } else if(this.isgrphover) {
- SelectGroupItems(this.id, this.group_key);
- new_context_menu(x, y, this.id, this.idx);
- }
- break;
- case "up":
- // Rating
- if(this.track_type<2 && this.rating_hov) {
- if(foo_playcount) {
- // Rate to database statistics brought by foo_playcount.dll
- if (this.l_rating != this.rating) {
- if(this.metadb) {
- var bool = fb.RunContextCommandWithMetadb("Rating/"+((this.l_rating==0) ? "<not set>" : this.l_rating), this.metadb);
- this.rating = this.l_rating;
- }
- } else {
- var bool = fb.RunContextCommandWithMetadb("Rating/<not set>", this.metadb);
- this.rating = 0;
- }
- } else {
- // Rate to file
- if (this.l_rating != this.rating) {
- if(this.metadb) {
- var bool = this.metadb.UpdateFileInfoSimple("RATING", this.l_rating);
- this.rating = this.l_rating;
- }
- } else {
- var bool = this.metadb.UpdateFileInfoSimple("RATING","");
- this.rating = 0;
- }
- }
- }
- break;
- case "move":
- // Rating
- if(this.rating_hov) {
- this.l_rating = Math.floor((x - this.rating_x) / star_img_off.Width) + 1;
- } else {
- this.l_rating = 0;
- }
- switch(this.state) {
- case this.ItemStates.normal:
- if(this.ishover) {
- this.state = this.ItemStates.hover;
- }
- break;
- case this.ItemStates.selected:
- if(this.rating_hov!=tmp || (this.rating_hov && this.l_rating!=tmp_l_rating) || (this.rating_hov && this.l_rating==0)) {
- window.RepaintRect(this.rating_x, this.rating_y, rating_w, rating_h);
- }
- break;
- case this.ItemStates.hover:
- if(!this.ishover) {
- this.state = this.ItemStates.normal;
- if(this.rating_hov!=tmp) {
- window.RepaintRect(this.rating_x, this.rating_y, rating_w, rating_h);
- }
- } else {
- if(this.rating_hov!=tmp || (this.rating_hov && this.l_rating!=tmp_l_rating) || (this.rating_hov && this.l_rating==0)) {
- window.RepaintRect(this.rating_x, this.rating_y, rating_w, rating_h);
- }
- }
- break;
- }
- break;
- case "leave":
- break;
- }
- return this.state;
- }
- }
- //=================================================// Main Callbacks
- function on_init() {
- var i;
- if(IC.show_coverart) {
- cover_w = IC.ghnbrows*IC.height - 1;
- cover_h = cover_w;
- } else {
- cover_w = 0;
- cover_h = 0;
- }
- if(IC.toolbar) {
- IC.toolbar_height = IC.default_toolbar_height;
- } else {
- IC.toolbar_height = 0;
- }
- IC.pos = 0;
- IC.topcut = 0;
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- refresh_timer && window.KillTimer(refresh_timer);
- on_focus(false);
- on_item_focus_change();
- draw_icons();
- refresh_buttons();
- if(IC.list_total>0) {
- IC.singleton_select_id = g_metadb_playlist.Find(fb.GetFocusItem());
- ShowSelectedItem(IC.singleton_select_id);
- }
- }
- on_init();
- function on_size() {
- ww = window.Width;
- wh = window.Height - IC.toolbar_height;
- IC.scrollbar_y = IC.scrollbar_bt_h*2;
- IC.scrollbar_h = window.Height - IC.scrollbar_bt_h*3;
- on_item_focus_change();
- ShowSelectedItem(-1);
- }
- function on_paint(gr) {
- var i, k;
- if(myscreen.length>0) {
- if(myscreen[0].id == 0 && myscreen[myscreen.length-1].id == IC.list_total-1 && myscreen.length<IC.nbvis) {
- IC.scroller_y = IC.scrollbar_y;
- IC.pos = 0;
- IC.topcut = 0;
- } else {
- if(!IC.scroller_drag) {
- IC.scroller_y = IC.scrollbar_y + Math.round((IC.pos/(IC.list_total-IC.total_items_visible)*-1)*(IC.scrollbar_h-scroller.Height));
- }
- }
- } else {
- IC.scroller_y = IC.scrollbar_y;
- IC.pos = 0;
- IC.topcut = 0;
- }
- // draw main bg
- gr.FillSolidRect(0,0,ww,wh+IC.toolbar_height,RGB(225,225,225));
- // draw playlist
- for(k=0;k<myscreen.length;k++) {
- if(myscreen[k].y<wh+IC.toolbar_height+IC.height) myscreen[k].draw(gr, k);
- }
- // draw scrollbar
- if(IC.scrollbar) {
- gr.FillSolidRect(ww-IC.scrollbar_width, 0, 1, wh+IC.toolbar_height, RGB(100,100,100));
- gr.FillGradRect(ww-IC.scrollbar_width, IC.scrollbar_y, 4, IC.scrollbar_h, 0, RGB(130,130,130), 0, 1.0);
- gr.FillGradRect(ww-2, IC.scrollbar_y, 0, IC.scrollbar_h, 0, 0, RGB(150,150,150), 1.0);
- gr.DrawImage(scroller, ww-IC.scrollbar_width+1, IC.scroller_y, scroller.Width, scroller.Height, 0, 0, scroller.Width, scroller.Height, 0, 255);
- for(i=0;i<myscrollbarbt.length;i++) {
- switch (i) {
- case 0:
- myscrollbarbt[i].draw(gr, ww-IC.scrollbar_width, 0, 255, "");
- break;
- case 1:
- myscrollbarbt[i].draw(gr, ww-IC.scrollbar_width, IC.scrollbar_bt_h, 255, "");
- break;
- case 2:
- myscrollbarbt[i].draw(gr, ww-IC.scrollbar_width, IC.scrollbar_y+IC.scrollbar_h, 255, "");
- break;
- }
- }
- if(IC.scroller_drag && myscreen.length>0) {
- refresh_scroller_popup(myscreen[0].albumartist.substring(0,1));
- gr.DrawImage(scroller_popup, ww-IC.scrollbar_width+1-scroller_popup.Width-5, IC.scroller_y-1, scroller_popup.Width, scroller_popup.Height, 0, 0, scroller_popup.Width, scroller_popup.Height, 0, 255);
- }
- }
- // draw toolbar
- if(IC.toolbar) {
- var tw = (IC.scrollbar?IC.scrollbar_width:0);
- gr.FillGradRect(0, 0, ww-tw, IC.toolbar_height, 90, RGB(245,245,245), RGB(230,230,230), 1.0);
- gr.FillSolidRect(0, 0, ww-tw, 1, RGB(210,210,210));
- gr.FillSolidRect(0, 1, ww-tw, 1, RGB(255,255,255));
- gr.FillSolidRect(0, IC.toolbar_height-1, ww-tw, 1, RGB(150,150,150));
- gr.FillGradRect(1, 2, ww-tw-2, IC.toolbar_height-4, 90, RGB(245,245,245), RGB(230,230,230), 0.5);
- for(i=0;i<mytoolbarbt.length;i++) {
- switch (i) {
- case 0:
- mytoolbarbt[i].draw(gr, 0, 0, 255, "");
- break;
- case 1:
- mytoolbarbt[i].draw(gr, ww-tw-mytoolbarbt_scrollbar.Width, 0, 255, "");
- break;
- case 2:
- mytoolbarbt[i].draw(gr, mytoolbarbt_shownowplaying.Width, 0, 255, "");
- break;
- case 3:
- mytoolbarbt[i].draw(gr, mytoolbarbt_shownowplaying.Width+mytoolbarbt_search.Width, 0, 255, "");
- break;
- }
- }
- }
- }
- //=================================================// Mouse Callbacks
- function on_mouse_lbtn_down(x, y) {
- var k;
- if(IC.scrollbar) {
- for(k=0;k<myscrollbarbt.length;k++) {
- switch(k) {
- case 0:
- myscrollbarbt[k].checkstate("down", x, y, k);
- break;
- case 1:
- if(myscrollbarbt[k].checkstate("down", x, y, k)==myscrollbarbt[k].ButtonStates.down) {
- mouse_down_timer && window.KillTimer(mouse_down_timer);
- mouse_down_timer = false;
- init_mouse_down_timer && window.KillTimer(init_mouse_down_timer);
- init_mouse_down_timer = window.CreateTimerInterval(500);
- IC.scrollstep = 1;
- if(IC.scrollstep_min>0) IC.scrollstep_min = 1;
- on_mouse_wheel(1);
- }
- break;
- case 2:
- if(myscrollbarbt[k].checkstate("down", x, y, k)==myscrollbarbt[k].ButtonStates.down) {
- mouse_down_timer && window.KillTimer(mouse_down_timer);
- mouse_down_timer = false;
- init_mouse_down_timer && window.KillTimer(init_mouse_down_timer);
- init_mouse_down_timer = window.CreateTimerInterval(500);
- IC.scrollstep = 1;
- if(IC.scrollstep_min>0) IC.scrollstep_min = 1;
- on_mouse_wheel(-1);
- }
- break;
- }
- }
- }
- if(IC.toolbar) {
- for(k=0;k<mytoolbarbt.length;k++) {
- switch(k) {
- case 0:
- mytoolbarbt[k].checkstate("down", x, y, k);
- break;
- case 1:
- mytoolbarbt[k].checkstate("down", x, y, k);
- break;
- case 2:
- mytoolbarbt[k].checkstate("down", x, y, k);
- break;
- case 3:
- mytoolbarbt[k].checkstate("down", x, y, k);
- break;
- }
- }
- }
- for(k=0;k<myscreen.length;k++) {
- myscreen[k].checkstate("down", x, y, k);
- }
- IC.scroller_drag = (x>ww-IC.scrollbar_width && y>=IC.scroller_y && y<=IC.scroller_y+scroller.Height)?true:false;
- if(!IC.scroller_drag && x>ww-IC.scrollbar_width && y>=IC.scrollbar_y && y<=IC.scrollbar_y+IC.scrollbar_h) {
- IC.scroller_drag = true;
- IC.scroll_down = false;
- IC.draw_cover = false;
- IC.scroller_y = y-Math.floor(scroller.Height/2);
- if(IC.scroller_y<=IC.scrollbar_y) {
- IC.scroller_y = IC.scrollbar_y;
- IC.pos = 0;
- IC.topcut = 0;
- } else if(IC.scroller_y>IC.scrollbar_y+IC.scrollbar_h-scroller.Height) {
- IC.scroller_y = (IC.scrollbar_y+IC.scrollbar_h-scroller.Height);
- IC.pos = scroller2pos(IC.scroller_y);
- if(y>=mouse_y) {
- IC.scroll_down = true;
- }
- } else {
- if(myscreen.length>0) {
- IC.pos = scroller2pos(IC.scroller_y);
- }
- }
- scroller_drag_timer = window.CreateTimerInterval(50);
- mouse_y = y;
- }
- }
- function on_mouse_lbtn_up(x, y) {
- var k;
- IC.scrollstep = window.GetProperty("Scroll Step", 3);
- init_mouse_down_timer && window.KillTimer(init_mouse_down_timer);
- init_mouse_down_timer = false;
- mouse_down_timer && window.KillTimer(mouse_down_timer);
- mouse_down_timer = false;
- if(IC.scrollbar) {
- for (k=0;k<myscrollbarbt.length;k++) {
- switch (k) {
- case 0:
- if(myscrollbarbt[k].checkstate("up", x, y, k) == myscrollbarbt[k].ButtonStates.hover) {
- IC.toolbar = !IC.toolbar;
- window.SetProperty("Show Toolbar", IC.toolbar);
- if(IC.toolbar) {
- IC.toolbar_height = IC.default_toolbar_height;
- } else {
- IC.toolbar_height = 0;
- }
- wh = window.Height - IC.toolbar_height;
- refresh_buttons();
- on_item_focus_change();
- }
- break;
- case 1:
- if(myscrollbarbt[k].checkstate("up", x, y, k) == myscrollbarbt[k].ButtonStates.hover) {
- }
- break;
- case 2:
- if(myscrollbarbt[k].checkstate("up", x, y, k) == myscrollbarbt[k].ButtonStates.hover) {
- }
- break;
- }
- }
- }
- if(IC.toolbar) {
- for (k=0;k<mytoolbarbt.length;k++) {
- switch (k) {
- case 0:
- if(mytoolbarbt[k].checkstate("up", x, y, k) == mytoolbarbt[k].ButtonStates.hover) {
- ShowNowPlaying();
- on_item_focus_change();
- }
- break;
- case 1:
- if(mytoolbarbt[k].checkstate("up", x, y, k) == mytoolbarbt[k].ButtonStates.hover) {
- IC.scrollbar = !IC.scrollbar;
- window.SetProperty("Show Scrollbar", IC.scrollbar);
- refresh_buttons();
- on_item_focus_change();
- }
- break;
- case 2:
- if(mytoolbarbt[k].checkstate("up", x, y, k) == mytoolbarbt[k].ButtonStates.hover) {
- fb.RunMainMenuCommand("Edit/Search");
- }
- break;
- case 3:
- if(mytoolbarbt[k].checkstate("up", x, y, k) == mytoolbarbt[k].ButtonStates.hover) {
- fb.RunMainMenuCommand("Edit/Sort/Sort by...");
- }
- break;
- }
- }
- }
- for(k=0;k<myscreen.length;k++) {
- myscreen[k].checkstate("up", x, y, k);
- }
- IC.scroller_drag = false;
- window.Repaint();
- }
- function on_mouse_lbtn_dblclk(x, y, mask) {
- var k;
- if(x>ww-IC.scrollbar_width) on_mouse_lbtn_down(x, y);
- for(k=0;k<myscreen.length;k++) {
- myscreen[k].checkstate("dblclk", x, y, k);
- }
- }
- function on_mouse_rbtn_down(x, y) {
- var k;
- for(k=0;k<myscreen.length;k++) {
- myscreen[k].checkstate("right", x, y, k);
- }
- }
- function on_mouse_move(x, y) {
- var k;
- refresh_timer && window.KillTimer(refresh_timer);
- refresh_timer = false;
- if(IC.scrollbar && x>=ww-IC.scrollbar_width) {
- for(k=0;k<myscrollbarbt.length;k++) {
- myscrollbarbt[k].checkstate("move", x, y, k);
- }
- }
- if(IC.toolbar && y<IC.toolbar_height) {
- for(k=0;k<mytoolbarbt.length;k++) {
- mytoolbarbt[k].checkstate("move", x, y, k);
- }
- }
- for(k=0;k<myscreen.length;k++) {
- if(myscreen[k].checkstate("move", x, y, k)==myscreen[k].ItemStates.hover) {
- }
- }
- if(IC.scroller_drag) {
- IC.scroll_down = false;
- IC.draw_cover = false;
- IC.scroller_y = y-Math.floor(scroller.Height/2);
- if(IC.scroller_y<=IC.scrollbar_y) {
- IC.scroller_y = IC.scrollbar_y;
- IC.pos = 0;
- IC.topcut = 0;
- } else if(IC.scroller_y>IC.scrollbar_y+IC.scrollbar_h-scroller.Height) {
- IC.scroller_y = (IC.scrollbar_y+IC.scrollbar_h-scroller.Height);
- if(!IC.bot_reached) {
- IC.pos = scroller2pos(IC.scroller_y);
- }
- if(y>=mouse_y) {
- IC.scroll_down = true;
- }
- } else {
- if(myscreen.length>0) {
- if(myscreen[myscreen.length-1].id == IC.list_total-1 && myscreen[myscreen.length-1].visible) {
- if(y<mouse_y) {
- IC.pos = scroller2pos(IC.scroller_y);
- }
- } else {
- IC.pos = scroller2pos(IC.scroller_y);
- }
- }
- }
- if(y!=mouse_y && !scroller_drag_timer) {
- scroller_drag_timer = window.CreateTimerInterval(60);
- }
- }
- mouse_x = x;
- mouse_y = y;
- }
- function on_mouse_wheel(delta) {
- var i;
- var scrollstep, scrollstep_min;
- IC.scroll_down = false;
- if(delta>0) {
- delta = 1;
- scrollstep = IC.scrollstep;
- scrollstep_min = IC.scrollstep_min;
- } else {
- delta = -1;
- scrollstep = IC.scrollstep;
- scrollstep_min = IC.scrollstep_min;
- }
- if(IC.scroll) {
- IC.draw_cover = false;
- refresh_timer && window.KillTimer(refresh_timer);
- refresh_timer = false;
- if(delta>0) {
- for(i=0;i<scrollstep;i++) {
- if(IC.topcut>0) {
- IC.topcut--;
- } else {
- IC.pos += delta;
- }
- }
- if(IC.pos>0) {
- IC.pos = 0;
- IC.topcut = 0;
- }
- } else {
- for(i=0;i<scrollstep_min;i++) {
- switch(myscreen[i].gridx){
- case 0:
- IC.pos += delta;
- IC.topcut = 0;
- break;
- default:
- IC.topcut++;
- }
- }
- }
- window.SetProperty("Item Offset", IC.pos);
- window.SetProperty("Group Offset", IC.topcut);
- on_item_focus_change();
- }
- }
- function on_mouse_leave() {
- var k;
- for(k=0;k<myscrollbarbt.length;k++) {
- myscrollbarbt[k].checkstate("leave", 0, 0, k);
- }
- for(k=0;k<mytoolbarbt.length;k++) {
- mytoolbarbt[k].checkstate("leave", 0, 0, k);
- }
- g_is_focused = false;
- on_item_focus_change();
- refresh_timer && window.KillTimer(refresh_timer);
- refresh_timer = false;
- refresh_timer = window.CreateTimerInterval(1000);
- }
- //=================================================// Event Callbacks
- function on_timer(id) {
- var i;
- if(IC.scrollbar) {
- for (i=0;i<myscrollbarbt.length;i++) {
- myscrollbarbt[i].ontimer(id);
- }
- }
- if(IC.toolbar) {
- for (i=0;i<mytoolbarbt.length;i++) {
- mytoolbarbt[i].ontimer(id);
- }
- }
- if(scroller_drag_timer) {
- if(scroller_drag_timer.ID == id) {
- on_item_focus_change();
- scroller_drag_timer && window.KillTimer(scroller_drag_timer);
- scroller_drag_timer = false;
- if(IC.scroll_down) {
- while(!IC.bot_reached) {
- IC.scrollstep = IC.nbvis-1;
- on_mouse_wheel(-1);
- }
- IC.scroll_down = false;
- }
- }
- }
- if(draw_cover_timer) {
- if(draw_cover_timer.ID == id) {
- IC.draw_cover = true;
- window.Repaint();
- draw_cover_timer && window.KillTimer(draw_cover_timer);
- draw_cover_timer = false;
- }
- }
- if(init_mouse_down_timer) {
- if(init_mouse_down_timer.ID == id) {
- mouse_down_timer && window.KillTimer(mouse_down_timer);
- mouse_down_timer = window.CreateTimerInterval(75);
- init_mouse_down_timer && window.KillTimer(init_mouse_down_timer);
- init_mouse_down_timer = false;
- }
- }
- if(mouse_down_timer) {
- if(mouse_down_timer.ID == id) {
- if(myscrollbarbt[1].state == myscrollbarbt[1].ButtonStates.down) {
- on_mouse_wheel(1);
- } else {
- on_mouse_wheel(-1);
- }
- }
- }
- if(wheel_up_timer) {
- if(wheel_up_timer.ID == id) {
- on_mouse_wheel(1);
- }
- }
- if(wheel_dn_timer) {
- if(wheel_dn_timer.ID == id) {
- on_mouse_wheel(-1);
- }
- }
- }
- function on_notify_data(name, info) {
- }
- function on_playlists_changed() {
- }
- function on_playlist_switch() {
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- ShowSelectedItem(-1);
- refresh_spv();
- if(IC.list_total>0) {
- IC.singleton_select_id = g_metadb_playlist.Find(fb.GetFocusItem());
- ShowSelectedItem(IC.singleton_select_id);
- }
- window.Repaint();
- }
- function on_playlist_items_added(playlist_idx) {
- if(playlist_idx==fb.ActivePlaylist) {
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- refresh_spv();
- ShowSelectedItem(-1);
- window.Repaint();
- }
- }
- function on_playlist_items_reordered(playlist_idx) {
- if(playlist_idx==fb.ActivePlaylist) {
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- refresh_spv();
- ShowSelectedItem(-1);
- window.Repaint();
- }
- }
- function on_selection_changed(metadb) {
- g_start_new_track = false;
- if(!IC.context_menu_called) {
- ShowSelectedItem(-1);
- on_item_focus_change();
- } else {
- IC.context_menu_called = false;
- ShowSelectedItem(-1);
- window.Repaint();
- }
- }
- function on_playlist_items_selection_change() {
- on_item_focus_change();
- }
- function on_item_focus_change() {
- if(g_metadb) {
- window.UnwatchMetadb();
- }
- g_metadb = fb.GetFocusItem();
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- IC.metadblist_selection = plman.GetPlaylistSelectedItems(fb.ActivePlaylist);
- if(IC.metadblist_selection) {
- on_metadb_changed();
- g_metadb && window.WatchMetadb(g_metadb);
- }
- }
- function on_metadb_changed() {
- if(g_metadb) {}
- refresh_spv();
- window.Repaint();
- }
- function on_focus(is_focused) {
- g_is_focused = is_focused;
- }
- function on_key_up(vkey) {
- wheel_up_timer && window.KillTimer(wheel_up_timer);
- wheel_up_timer = false;
- wheel_dn_timer && window.KillTimer(wheel_dn_timer);
- wheel_dn_timer = false;
- }
- function on_key_down(vkey) {
- var mask = GetKeyboardMask();
- var focus_id;
- if (mask == KMask.none) {
- switch (vkey) {
- case VK_UP:
- IC.scrollstep = 1;
- if(!wheel_up_timer) {
- wheel_up_timer = window.CreateTimerInterval(75);
- }
- break;
- case VK_DOWN:
- IC.scrollstep = 1;
- if(!wheel_dn_timer) {
- wheel_dn_timer = window.CreateTimerInterval(75);
- }
- break;
- case VK_PGUP:
- IC.scrollstep = IC.nbvis-1;
- if(!wheel_up_timer) {
- wheel_up_timer = window.CreateTimerInterval(75);
- }
- break;
- case VK_PGDN:
- IC.scrollstep = IC.nbvis-1;
- if(!wheel_dn_timer) {
- wheel_dn_timer = window.CreateTimerInterval(75);
- }
- break;
- case VK_RETURN:
- // play focus item
- fb.RunContextCommandWithMetadb("Play", fb.GetFocusItem());
- break;
- case VK_ESCAPE:
- // clear selection (select only the focused item)
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- on_item_focus_change();
- break;
- case VK_END:
- IC.pos = 0 - (IC.list_total-(IC.nbvis-1));
- IC.topcut = 0;
- IC.scroll_down = true;
- // check if bot reached, if not, reaching it
- scroller_drag_timer = window.CreateTimerInterval(60);
- break;
- case VK_HOME:
- IC.pos = 0;
- IC.topcut = 0;
- on_item_focus_change();
- break;
- case VK_DELETE:
- IC.metadblist_selection.Sort();
- var id_to_remove;
- var new_focus_id;
- for(i=0;i<IC.metadblist_selection.Count;i++) {
- id_to_remove = Math.round(g_metadb_playlist.Find(IC.metadblist_selection.Item(i)));
- if(id_to_remove==IC.list_total-1) {
- new_focus_id = Math.round(IC.list_total-1);
- } else {
- new_focus_id = Math.round(id_to_remove);
- }
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, id_to_remove, true);
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, id_to_remove);
- fb.RunMainMenuCommand("Edit/Selection/Remove");
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- }
- if(IC.list_total>0) {
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, new_focus_id);
- }
- break;
- }
- }
- }
- //=================================================// Playback Callbacks
- function on_playback_new_track(info) {
- g_start_new_track = true;
- CursorFollowsPlayback();
- on_item_focus_change();
- }
- function on_playback_stop(reason) {
- if(reason==0) { // on user Stop
- on_item_focus_change();
- }
- }
- function on_playback_pause(state){
- }
- function on_playback_time(time) {
- g_playtime_parity = (time/2-Math.floor(time/2)==0)?0:1;
- window.Repaint();
- }
- //=================================================// Populate playlist
- function refresh_spv() {
- var i, m;
- var j=0; // idx of bounded items
- var k=0; // idx of screen lines
- var gstart = null;
- IC.nb_hidden_lines = 0;
- IC.total_items_visible = 0;
- IC.nbvis = Math.ceil(wh/IC.height);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- var deb = IC.pos>0?0:IC.pos*-1;
- var end = deb + IC.nbvis - 1;
- if(end>IC.list_total-1) end = IC.list_total-1;
- myitem.splice(0, myitem.length);
- myscreen.splice(0, myscreen.length);
- for(i=deb;i<end+1;i++) {
- myitem.push(new item);
- myitem[j].create(i, g_metadb_playlist.Item(i), j);
- if(myitem[j].id>0) {
- var previous_item = new item;
- if(myitem[j].idx>0) {
- previous_item = myitem[myitem[j].idx-1];
- } else {
- previous_item.create(myitem[j].id-1, g_metadb_playlist.Item(myitem[j].id-1), -1);
- }
- myitem[j].isgroup = (myitem[j].group_key!=previous_item.group_key)?true:false;
- } else {
- myitem[j].isgroup = true;
- }
- if(myitem[j].isgroup) {
- gstart = k>0?0:IC.topcut;
- for(m=gstart;m<IC.ghnbrows;m++) {
- myscreen.push(new item);
- myscreen[k].create(i, g_metadb_playlist.Item(i), k);
- myscreen[k].gridx = m+1;
- myscreen[k].y = myscreen[k].idx*IC.height + IC.toolbar_height;
- myscreen[k].visible = (k<IC.nbvis-1)?true:false;
- if(!myscreen[k].visible) {
- IC.nb_hidden_lines++;
- }
- k++;
- }
- }
- // item
- myscreen.push(new item);
- myscreen[k].create(i, g_metadb_playlist.Item(i), k);
- myscreen[k].gridx = 0;
- myscreen[k].y = myscreen[k].idx*IC.height + IC.toolbar_height;
- myscreen[k].visible = (k<IC.nbvis-1)?true:false;
- if(plman.IsPlaylistItemSelected(fb.ActivePlaylist, i)) {
- myscreen[k].state = myscreen[k].ItemStates.selected;
- }
- if(!myscreen[k].visible) {
- IC.nb_hidden_lines++;
- } else {
- IC.total_items_visible++;
- }
- myitem[j].visible = myscreen[k].visible;
- k++;
- // test if scrolling required
- if(IC.pos<0) {
- IC.scroll = true;
- } else {
- if(myitem[j].id==IC.list_total-1 && myitem[j].visible) {
- IC.scroll = false;
- } else {
- IC.scroll = true;
- }
- }
- j++;
- }
- // test if last item of the playlist is visible (bottom of the list reached, no more scrolling down!)
- if(myscreen.length>0) {
- if(myscreen[myscreen.length-1].id==IC.list_total-1) {
- var hh = Math.round(IC.toolbar_height) + (IC.nbvis-2)*IC.height;
- if(myscreen[myscreen.length-1].y <= hh) {
- IC.bot_reached = true;
- } else {
- IC.bot_reached = false;
- }
- }
- }
- // if last item of myscreen not the last playlist item => scrollstep is default
- if(myscreen.length>0) {
- if(myscreen[myscreen.length-1].id==IC.list_total-1) {
- if(IC.nb_hidden_lines<IC.scrollstep) {
- IC.scrollstep_min = IC.nb_hidden_lines;
- } else {
- IC.scrollstep_min = IC.scrollstep;
- }
- } else {
- IC.scrollstep_min = IC.scrollstep;
- }
- }
- // launch a timer to request an asynchronous cover art refresh
- if(IC.show_coverart && !IC.draw_cover) {
- draw_cover_timer && window.KillTimer(draw_cover_timer);
- draw_cover_timer = false;
- draw_cover_timer = window.CreateTimerInterval(250);
- }
- }
- //=================================================// Item Context Menu
- function new_context_menu(x, y, id, array_id) {
- var MF_STRING = 0x00000000;
- var MF_SEPARATOR = 0x00000800;
- var MF_GRAYED = 0x00000001;
- var MF_DISABLED = 0x00000002;
- IC.context_menu_called = true;
- var _menu = window.CreatePopupMenu();
- var Context = fb.CreateContextMenuManager();
- Context.InitContext(IC.metadblist_selection);
- Context.BuildMenu(_menu, 1, -1);
- _menu.AppendMenuItem(MF_SEPARATOR, 0, "");
- _menu.AppendMenuItem((fb.IsAutoPlaylist(fb.ActivePlaylist))?MF_DISABLED|MF_GRAYED:MF_STRING, 810, "Remove");
- _menu.AppendMenuItem(MF_SEPARATOR, 0, "");
- _menu.AppendMenuItem(fb.IsPlaying?MF_STRING:MF_DISABLED|MF_GRAYED, 800, "Show Now Playing");
- var ret = _menu.TrackPopupMenu(x, y);
- if(ret<800) {
- Context.ExecuteByID(ret - 1);
- } else {
- switch (ret) {
- case 800:
- ShowNowPlaying();
- on_item_focus_change();
- break;
- case 810:
- IC.metadblist_selection.Sort();
- var id_to_remove = -1;
- var new_focus_id = 0;
- for(i=0;i<IC.metadblist_selection.Count;i++) {
- id_to_remove = g_metadb_playlist.Find(IC.metadblist_selection.Item(i));
- if(id_to_remove==IC.list_total-1) {
- new_focus_id = IC.list_total==1?-1:IC.list_total-1;
- } else {
- new_focus_id = id_to_remove;
- }
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, id_to_remove, true);
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, id_to_remove);
- fb.RunMainMenuCommand("Edit/Selection/Remove");
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- }
- break;
- }
- }
- }
- function draw_icons() {
- var i;
- var gb;
- var gui_font = gdi.Font("guifx v2 transports", 15, 0);
- playicon_off = gdi.CreateImage(16, 16);
- gb = playicon_off.GetGraphics();
- gb.SetTextRenderingHint(4);
- gb.DrawString("1", gui_font, RGB(255,255,255), 0, 0, playicon_off.Width, playicon_off.Height, cc_stringformat);
- gb.DrawString("1", gui_font, RGB(100,100,100), 0, 2, playicon_off.Width, playicon_off.Height, cc_stringformat);
- gb.DrawString("1", gui_font, RGB(150,150,150), 0, 1, playicon_off.Width, playicon_off.Height, cc_stringformat);
- playicon_off.ReleaseGraphics(gb);
- star_img_off = gdi.CreateImage(13, 18);
- gb = star_img_off.GetGraphics();
- gui_font = gdi.Font("guifx v2 transports", 17, 0);
- gb.SetTextRenderingHint(4);
- gb.DrawString("b", gui_font, RGB(230,230,230), 0, 0, 13, 18, lt_stringformat);
- star_img_off.ReleaseGraphics(gb);
- star_img_on = gdi.CreateImage(13, 18);
- gb = star_img_on.GetGraphics();
- gui_font = gdi.Font("guifx v2 transports", 17, 0);
- gb.SetTextRenderingHint(4);
- gb.DrawString("b", gui_font, RGB(150,150,150), 0, 0, 13, 18, lt_stringformat);
- star_img_on.ReleaseGraphics(gb);
- star_img_hov = gdi.CreateImage(13, 18);
- gb = star_img_hov.GetGraphics();
- gui_font = gdi.Font("guifx v2 transports", 17, 0);
- gb.SetTextRenderingHint(3);
- gb.DrawString("b", gui_font, RGB(50, 50, 200), 0, 0, 13, 18, lt_stringformat);
- star_img_hov.ReleaseGraphics(gb);
- star_img_kill = gdi.CreateImage(13, 18);
- gb = star_img_kill.GetGraphics();
- gui_font = gdi.Font("guifx v2 transports", 15, 0);
- gb.SetTextRenderingHint(3);
- gui_font = gdi.Font("guifx v2 transports", 17, 0);
- gb.DrawString("b", gui_font, RGB(200,50,50), 0, 0, 13, 18, lt_stringformat);
- star_img_kill.ReleaseGraphics(gb);
- // Set rating area width
- rating_w = Math.floor(star_img_off.Width*5);
- rating_h = Math.floor(star_img_off.Height);
- scroller = gdi.CreateImage(IC.scrollbar_width-2, 18);
- gb = scroller.GetGraphics();
- gb.SetSmoothingMode(2);
- gb.FillRoundRect(2,2,IC.scrollbar_width-5,15,2,2,RGB(120,120,120));
- gb.FillGradRect(1,1,IC.scrollbar_width-5,15,0,RGB(200,200,200),RGB(240,240,240),0.5);
- gb.DrawRoundRect(1,1,IC.scrollbar_width-5,15,2,2,1.0,RGB(255,255,255));
- gb.SetSmoothingMode(0);
- gb.FillSolidRect(4,6,IC.scrollbar_width-10,1,RGB(175,175,175));
- gb.FillSolidRect(4,9,IC.scrollbar_width-10,1,RGB(175,175,175));
- gb.FillSolidRect(4,12,IC.scrollbar_width-10,1,RGB(175,175,175));
- gb.FillSolidRect(4,5,IC.scrollbar_width-10,1,RGB(255,255,255));
- gb.FillSolidRect(4,8,IC.scrollbar_width-10,1,RGB(255,255,255));
- gb.FillSolidRect(4,11,IC.scrollbar_width-10,1,RGB(255,255,255));
- scroller.ReleaseGraphics(gb);
- nocover = gdi.CreateImage(200, 200);
- gb = nocover.GetGraphics();
- gb.SetSmoothingMode(2);
- gb.FillGradRect(0,0,200,200,90,RGB(200,200,200),RGB(240,240,240),1.0);
- gb.SetTextRenderingHint(3);
- gui_font = gdi.Font("guifx v2 transports", 132, 0);
- gb.DrawString("x", gui_font, RGB(255,255,255), 1, 3, 200, 200, cc_stringformat);
- gb.DrawString("x", gui_font, RGB(120,120,120), 1, 0, 200, 200, cc_stringformat);
- nocover.ReleaseGraphics(gb);
- streamcover = gdi.CreateImage(200, 200);
- gb = streamcover.GetGraphics();
- gb.SetSmoothingMode(2);
- gb.FillGradRect(0,0,nocover.Width,nocover.Height,90,RGB(200,200,200),RGB(240,240,240),1.0);
- gb.SetTextRenderingHint(3);
- gui_font = gdi.Font("guifx v2 transports", 126, 0);
- gb.DrawString("$", gui_font, RGB(255,255,255), 1, 3, 200, 200, cc_stringformat);
- gb.DrawString("$", gui_font, RGB(120,120,120), 1, 0, 200, 200, cc_stringformat);
- streamcover.ReleaseGraphics(gb);
- CollectGarbage();
- }
- function refresh_scroller_popup(letter) {
- var gb;
- var font = gdi.Font("segoe ui", 14, 1);
- scroller_popup = gdi.CreateImage(22, 22);
- gb = scroller_popup.GetGraphics();
- gb.SetSmoothingMode(2);
- gb.FillRoundRect(0,0,scroller_popup.Width-1,scroller_popup.Height-1,3,3,RGBA(40,40,40,200));
- gb.DrawRoundRect(0,0,scroller_popup.Width-1,scroller_popup.Height-1,3,3,1.0,RGB(0,0,0));
- gb.SetTextRenderingHint(3);
- gb.DrawString(letter.toUpperCase(), font, RGB(0,0,0), 0, 0, scroller_popup.Width, scroller_popup.Height, cc_stringformat);
- gb.DrawString(letter.toUpperCase(), font, RGB(255,255,255), 0, -1, scroller_popup.Width, scroller_popup.Height, cc_stringformat);
- scroller_popup.ReleaseGraphics(gb);
- CollectGarbage();
- }
- function refresh_buttons() {
- var i;
- var gb;
- var gui_font = gdi.Font("guifx v2 transports", 12, 0);
- var DT_LT = DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX;
- scrollbarbt_menu = gdi.CreateImage(IC.scrollbar_width, IC.scrollbar_bt_h);
- gb = scrollbarbt_menu.GetGraphics();
- gb.FillSolidRect(1, 0, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(250,250,250));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(100,100,100));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-3, scrollbarbt_menu.Height-2, RGB(200,200,200));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 14, 0);
- gb.DrawString(IC.toolbar?"s":"a", gui_font, RGB(250,250,250), 1, 1, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- gb.DrawString(IC.toolbar?"s":"a", gui_font, RGB(100,100,100), 1, 0, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- scrollbarbt_menu.ReleaseGraphics(gb);
- scrollbarbt_up = gdi.CreateImage(IC.scrollbar_width, IC.scrollbar_bt_h);
- gb = scrollbarbt_up.GetGraphics();
- gb.FillSolidRect(1, 0, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(250,250,250));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(100,100,100));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-3, scrollbarbt_menu.Height-2, RGB(200,200,200));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 12, 0);
- gb.DrawString(".", gui_font, RGB(250,250,250), 1, 1, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- gb.DrawString(".", gui_font, RGB(100,100,100), 1, 0, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- scrollbarbt_up.ReleaseGraphics(gb);
- scrollbarbt_down = gdi.CreateImage(IC.scrollbar_width, IC.scrollbar_bt_h);
- gb = scrollbarbt_down.GetGraphics();
- gb.FillSolidRect(1, 0, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(250,250,250));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-2, scrollbarbt_menu.Height-1, RGB(100,100,100));
- gb.FillSolidRect(2, 1, scrollbarbt_menu.Width-3, scrollbarbt_menu.Height-2, RGB(200,200,200));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 12, 0);
- gb.DrawString(",", gui_font, RGB(250,250,250), 1, 1, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- gb.DrawString(",", gui_font, RGB(100,100,100), 1, 0, scrollbarbt_menu.Width-1, scrollbarbt_menu.Height, cc_stringformat);
- scrollbarbt_down.ReleaseGraphics(gb);
- myscrollbarbt.splice(0, myscrollbarbt.length);
- for(i=0;i<3;i++) {
- myscrollbarbt.push(new button);
- switch(i) {
- case 0:
- myscrollbarbt[i].create(scrollbarbt_menu, scrollbarbt_menu, scrollbarbt_menu, "", -01);
- break;
- case 1:
- myscrollbarbt[i].create(scrollbarbt_up, scrollbarbt_up, scrollbarbt_up, "", -02);
- break;
- case 2:
- myscrollbarbt[i].create(scrollbarbt_down, scrollbarbt_down, scrollbarbt_down, "", -03);
- break;
- }
- }
- mytoolbarbt_shownowplaying = gdi.CreateImage(20, IC.default_toolbar_height);
- gb = mytoolbarbt_shownowplaying.GetGraphics();
- gb.FillSolidRect(mytoolbarbt_shownowplaying.Width-1, 1, 1, mytoolbarbt_shownowplaying.Height-2, RGB(100,100,100));
- gb.FillSolidRect(mytoolbarbt_shownowplaying.Width-0, 1, 1, mytoolbarbt_shownowplaying.Height-2, RGB(255,255,255));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 16, 0);
- gb.DrawString("i", gui_font, RGB(255,255,255), 0, 1, mytoolbarbt_shownowplaying.Width-1, mytoolbarbt_shownowplaying.Height, cc_stringformat);
- gb.DrawString("i", gui_font, RGB(130,130,130), 0, 0, mytoolbarbt_shownowplaying.Width-1, mytoolbarbt_shownowplaying.Height, cc_stringformat);
- mytoolbarbt_shownowplaying.ReleaseGraphics(gb);
- mytoolbarbt_scrollbar = gdi.CreateImage(20, IC.default_toolbar_height);
- gb = mytoolbarbt_scrollbar.GetGraphics();
- gb.FillSolidRect(0, 1, 1, mytoolbarbt_scrollbar.Height-2, RGB(100,100,100));
- gb.FillSolidRect(1, 1, 1, mytoolbarbt_scrollbar.Height-2, RGB(255,255,255));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 15, 0);
- gb.DrawString(IC.scrollbar?"D":"A", gui_font, RGB(255,255,255), 1, 1, mytoolbarbt_scrollbar.Width-1, mytoolbarbt_scrollbar.Height, cc_stringformat);
- gb.DrawString(IC.scrollbar?"D":"A", gui_font, RGB(130,130,130), 1, 0, mytoolbarbt_scrollbar.Width-1, mytoolbarbt_scrollbar.Height, cc_stringformat);
- mytoolbarbt_scrollbar.ReleaseGraphics(gb);
- mytoolbarbt_search = gdi.CreateImage(20, IC.default_toolbar_height);
- gb = mytoolbarbt_search.GetGraphics();
- gb.FillSolidRect(mytoolbarbt_search.Width-1, 1, 1, mytoolbarbt_search.Height-2, RGB(100,100,100));
- gb.FillSolidRect(mytoolbarbt_search.Width-0, 1, 1, mytoolbarbt_search.Height-2, RGB(255,255,255));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("guifx v2 transports", 15, 0);
- gb.DrawString(")", gui_font, RGB(255,255,255), 0, 1, mytoolbarbt_search.Width-1, mytoolbarbt_search.Height, cc_stringformat);
- gb.DrawString(")", gui_font, RGB(130,130,130), 0, 0, mytoolbarbt_search.Width-1, mytoolbarbt_search.Height, cc_stringformat);
- mytoolbarbt_search.ReleaseGraphics(gb);
- mytoolbarbt_sort = gdi.CreateImage(20, IC.default_toolbar_height);
- gb = mytoolbarbt_sort.GetGraphics();
- gb.FillSolidRect(mytoolbarbt_sort.Width-1, 1, 1, mytoolbarbt_sort.Height-2, RGB(100,100,100));
- gb.FillSolidRect(mytoolbarbt_sort.Width-0, 1, 1, mytoolbarbt_sort.Height-2, RGB(255,255,255));
- gb.SetTextRenderingHint(4);
- gui_font = gdi.Font("segoe ui", 12, 0);
- gb.DrawString("Az", gui_font, RGB(255,255,255), 0, 0, mytoolbarbt_sort.Width-1, mytoolbarbt_sort.Height, cc_stringformat);
- gb.DrawString("Az", gui_font, RGB(130,130,130), 0, -1, mytoolbarbt_sort.Width-1, mytoolbarbt_sort.Height, cc_stringformat);
- mytoolbarbt_sort.ReleaseGraphics(gb);
- mytoolbarbt.splice(0, mytoolbarbt.length);
- for(i=0;i<4;i++) {
- mytoolbarbt.push(new button);
- switch(i) {
- case 0:
- mytoolbarbt[i].create(mytoolbarbt_shownowplaying, mytoolbarbt_shownowplaying, mytoolbarbt_shownowplaying, "", -01);
- break;
- case 1:
- mytoolbarbt[i].create(mytoolbarbt_scrollbar, mytoolbarbt_scrollbar, mytoolbarbt_scrollbar, "", -02);
- break;
- case 2:
- mytoolbarbt[i].create(mytoolbarbt_search, mytoolbarbt_search, mytoolbarbt_search, "", -03);
- break;
- case 3:
- mytoolbarbt[i].create(mytoolbarbt_sort, mytoolbarbt_sort, mytoolbarbt_sort, "", -04);
- break;
- }
- }
- CollectGarbage();
- }
- function CursorFollowsPlayback() {
- var i;
- if(fb.ActivePlaylist!=fb.PlayingPlaylist) {
- fb.ActivePlaylist = fb.PlayingPlaylist;
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- }
- IC.nowplaying = plman.GetPlayingItemLocation();
- var pid = IC.nowplaying.PlaylistItemIndex;
- var already_shown = false;
- for(i=0;i<myitem.length;i++) {
- if(myitem[i].id == pid) {
- if(myitem[i].visible) {
- already_shown = true;
- }
- break;
- }
- }
- if(!already_shown) {
- IC.pos = 0 - pid +1;
- if(IC.pos>0) {
- IC.pos = 0;
- IC.topcut = 0;
- }
- if(pid < Math.ceil(IC.viscount/2)) {
- IC.pos = 0;
- }
- }
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, pid, true);
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, pid);
- IC.metadblist_selection = plman.GetPlaylistSelectedItems(fb.ActivePlaylist);
- IC.singleton_select_id = pid;
- }
- function ShowNowPlaying() {
- if(!fb.IsPlaying) return true;
- if(fb.ActivePlaylist!=fb.PlayingPlaylist) {
- fb.ActivePlaylist = fb.PlayingPlaylist;
- g_metadb_playlist = plman.GetPlaylistItems(fb.ActivePlaylist);
- IC.list_total = fb.PlaylistItemCount(fb.ActivePlaylist);
- }
- IC.nowplaying = plman.GetPlayingItemLocation();
- var pid = IC.nowplaying.PlaylistItemIndex;
- IC.pos = 0 - pid +1;
- if(IC.pos>0) {
- IC.pos = 0;
- IC.topcut = 0;
- }
- if(pid < Math.ceil(IC.viscount/2)) {
- IC.pos = 0;
- }
- refresh_spv();
- }
- function ShowSelectedItem(pid) {
- var i;
- if(IC.list_total==0) return true;
- if(pid<0) {
- var focus_item = fb.GetFocusItem();
- pid = g_metadb_playlist.Find(focus_item);
- }
- var already_shown = false;
- for(i=0;i<myitem.length;i++) {
- if(myitem[i].id == pid) {
- if(myitem[i].visible) {
- already_shown = true;
- }
- break;
- }
- }
- if(!already_shown) {
- IC.pos = 0 - pid +1;
- if(IC.pos>0) {
- IC.pos = 0;
- IC.topcut = 0;
- }
- if(pid < Math.ceil(IC.viscount/2)) {
- IC.pos = 0;
- }
- refresh_spv();
- }
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, pid);
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, pid, true);
- }
- function SelectGroupItems(start_id, group_key) {
- var i;
- var count=0;
- var gitem;
- var gitem_prev;
- if(!utils.IsKeyPressed(VK_CONTROL)) {
- plman.ClearPlaylistSelection(fb.ActivePlaylist);
- }
- for(i=start_id;i<IC.list_total;i++) {
- gitem_prev = gitem;
- gitem = new item;
- gitem.template_it(i, g_metadb_playlist.Item(i));
- if(gitem.group_key==group_key) {
- plman.SetPlaylistSelectionSingle(fb.ActivePlaylist, gitem.id, true);
- } else {
- break;
- }
- count++;
- if(count>999) break;
- }
- plman.SetPlaylistFocusItem(fb.ActivePlaylist, gitem_prev.id);
- IC.singleton_select_id = gitem_prev.id;
- CollectGarbage();
- on_item_focus_change();
- }
- function SelectAtoB(start_id, end_id) {
- var i;
- var affectedItems = Array();
- if(start_id<end_id) {
- var deb = start_id;
- var fin = end_id;
- } else {
- var deb = end_id;
- var fin = start_id;
- }
- for(i=deb;i<=fin;i++) {
- affectedItems.push(i);
- }
- plman.SetPlaylistSelection(fb.ActivePlaylist, affectedItems, true);
- on_item_focus_change();
- }
- //=================================================// Cover Art Tools
- image_cache = function () {
- this._cachelist = {};
- this.hit = function (item) {
- var img = this._cachelist[item.cover_path];
- if (typeof img == "undefined") {
- if(IC.draw_cover) {
- img = refresh_cover(item);
- this._cachelist[item.cover_path] = img;
- }
- }
- return img;
- }
- }
- var g_image_cache = new image_cache;
- function TrackType(trkpath) {
- var taggable;
- var type;
- switch (trkpath) {
- case "file":
- taggable = 1;
- type = 0;
- break;
- case "cdda":
- taggable = 1;
- type = 1;
- break;
- case "FOO_":
- taggable = 0;
- type = 2;
- break;
- case "http":
- taggable = 0;
- type = 3;
- break;
- case "mms:":
- taggable = 0;
- type = 3;
- break;
- case "unpa":
- taggable = 0;
- type = 4;
- break;
- default:
- taggable = 0;
- type = 5;
- }
- return type;
- }
- function FormatCover(image) {
- if(!image) return image;
- if(cover_w<=0 || cover_h<=0) return image;
- var tmp_img = gdi.CreateImage(cover_w, cover_h);
- var gp = tmp_img.GetGraphics();
- gp.SetInterpolationMode(7);
- gp.DrawImage(image, -1, -1, cover_w+2, cover_h+2, 0, 0, image.width, image.height, 0, 255);
- gp.SetSmoothingMode(2);
- // frame
- gp.DrawRect(0, 0, cover_w-1, cover_h-1, 1.0, RGBA(250,250,250,255));
- gp.DrawRect(1, 1, cover_w-3, cover_h-3, 1.0, RGBA(0,0,0,055));
- tmp_img.ReleaseGraphics(gp);
- CollectGarbage();
- return tmp_img;
- }
- function refresh_cover(item) {
- var type = 0;
- var cover_img;
- if(item.track_type!=3) {
- if(item.metadb) {
- cover_img = FormatCover(utils.GetAlbumArtEmbedded(item.metadb.rawpath, type));
- if(!cover_img) {
- cover_img = FormatCover(utils.GetAlbumArtV2(item.metadb, type));
- if(!cover_img) cover_img = FormatCover(nocover);
- }
- }
- } else if (fb.IsPlaying && fb.PlaybackLength) {
- cover_img = FormatCover(streamcover);
- } else {
- cover_img = FormatCover(nocover);
- }
- return cover_img;
- }
- function scroller2pos(scroller_y) {
- var r = (scroller_y-IC.scrollbar_y) / (IC.scrollbar_h-scroller.Height);
- var pos = 0 - Math.round(r*(IC.list_total-(IC.nbvis-1)));
- return pos;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement