Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.73 KB | None | 0 0
  1. // Control Panel for StrigUI
  2. // completely reworked and restyled version of control buttons panel (by eXtremeHunter1972 from FooAero)
  3. // Latest change: 28.09.2014 fixed performance issues with on_mouse_move func
  4.  
  5. var height = 64;
  6. window.MinHeight = height;
  7. window.MaxHeight = height;
  8. window.SetProperty("TipText", true);
  9.  
  10. var d = new Date();
  11. var g_textrender = gdi.CreateStyleTextRender();
  12. var str = "";
  13.  
  14. // ---> Initial timers
  15. window.SetInterval(function() {
  16. if (!fb.IsPlaying || fb.IsPaused || fb.PlaybackLength == 0) return;
  17. window.RepaintRect(seek_x - 10 + (seek_pos > 25 ? (seek_pos - 25) : 0), seek_y, 50, seek_h); // seek area
  18. }, 150);
  19.  
  20. window.SetInterval(function(){ // create timer for initial clock display
  21. if (fb.IsPlaying) return;
  22. d = new Date();
  23. window.RepaintRect(time_x, time_y, time_w, time_h); // time area
  24. }, 1000);
  25.  
  26. // ---> Additional images
  27. var imgPath = fb.FoobarPath + "themes\\strigUI\\Images\\";
  28. var SEEK_L1 = gdi.Image(imgPath + "Buttons\\SEEK_L1.png");
  29. var SEEK_L2 = gdi.Image(imgPath + "Buttons\\SEEK_L2.png");
  30. var dsp_button_img = gdi.Image(imgPath + "Buttons\\DSP_man.png");
  31. var eq_button_img = gdi.Image(imgPath + "Buttons\\EQ_ICO.png");
  32. var output_button_img = gdi.Image(imgPath + "Buttons\\OUT_ICO.png");
  33. var adj_button_img = gdi.Image(imgPath + "Buttons\\DJ_ICO.png");
  34. var adj_button_down_img = gdi.Image(imgPath + "Buttons\\DJ_H_ICO.png");
  35. var queue_button_img = gdi.Image(imgPath + "Buttons\\QUEUE_ICO.png");
  36. var queue_button_down_img = gdi.Image(imgPath + "Buttons\\QUEUE_ICO_.png");
  37.  
  38. // ---> More vars
  39. var XYinVol = XYinVol_h = vol_drag = volume_change = sac = saci = XYinSeek = XYinSeek_h = XYinMenu = lbtn_down = seek_drag = ShiftDown = volume_change = vol_timer = false;
  40. var vol_pos = volstate = vol_x = vol_y = vol_w = vol_h = time_x = time_y = time_w = time_h = time_pos = seek_pos = ww = wh = 0;
  41.  
  42. // ---> RATING vars
  43. var g_drag = 0;
  44. var g_rate = fb.TitleFormat("%RATING%");
  45. var bool = g_metadb = rating = nrating = lrating = img = XYinRate = false;
  46. var R_hoffset = 15;
  47. var R_voffset = 25;
  48. var R_imgw = 22;
  49. var R_w = R_imgw * 5;
  50.  
  51. // ================================================== //
  52. // ---> Draw a star function
  53. function DrawPolyStar(gr, x, y, out_radius, in_radius, points, line_thickness, line_color, fill_color, angle, opacity){
  54. if(!opacity && opacity != 0) opacity = 255;
  55.  
  56. //---> Create points
  57. var point_arr = [];
  58.  
  59. for (var i = 0; i != points; i++) {
  60. i % 2 ? r = Math.round((out_radius-line_thickness*4)/2) / in_radius : r = Math.round((out_radius-line_thickness*4)/2);
  61. var x_point = Math.floor(r * Math.cos(Math.PI * i / points * 2 - Math.PI / 2));
  62. var y_point = Math.ceil(r * Math.sin(Math.PI * i / points * 2 - Math.PI / 2));
  63. point_arr.push(x_point + out_radius/2);
  64. point_arr.push(y_point + out_radius/2);
  65. }
  66.  
  67. //---> Crate poligon image
  68. var img = gdi.CreateImage(out_radius, out_radius);
  69. var _gr = img.GetGraphics();
  70.  
  71. _gr.SetSmoothingMode(2);
  72. _gr.FillPolygon(fill_color, 1, point_arr);
  73.  
  74. if(line_thickness > 0)
  75. _gr.DrawPolygon(line_color, line_thickness, point_arr);
  76.  
  77. img.ReleaseGraphics(_gr);
  78.  
  79. //---> Draw image
  80. gr.DrawImage(img, x, y, out_radius, out_radius, 0, 0, out_radius, out_radius, angle, opacity);
  81. }
  82.  
  83. // ---> Volume funcs
  84. function pos2vol(p) {
  85. return (50 * Math.log(0.99 * p + 0.01) / Math.log(10));
  86. }
  87. function vol2pos(v) {
  88. return (((Math.pow(10, v / 50) - 0.01) / 0.99));
  89. }
  90.  
  91. // ---> Auto DJ functions
  92. function id_playlist(name){
  93. //fb.RunMainMenuCommand("Playback/Order/Default");
  94. var pl_dj;
  95. for (var i = 0; i <= plman.PlaylistCount; i++) {
  96. if (plman.GetPlaylistName(i) == name) {
  97. pl_dj = i;
  98. break;
  99. }
  100. }
  101. return pl_dj;
  102. }
  103.  
  104. function run_dj() {
  105. fb.RunMainMenuCommand("Playback/Order/Default");
  106. var pl_dj = id_playlist("Auto DJ");
  107. if ( pl_dj == "?" || !pl_dj ) { // is there a list like this?
  108. pl_dj = plman.PlaylistCount + 1;
  109. plman.CreatePlaylist(pl_dj, "Auto DJ");
  110. pl_dj = id_playlist("Auto DJ"); // double checking list id
  111. }
  112.  
  113. var items = plman.GetPlaylistItems(pl_dj);
  114.  
  115. if (items.count < 1) { // that playlist must be new, lets seed a track and start playback so foo_random_pools can start working
  116. //if ( plman.PlaylistItemCount(pl_dj) < 1 ) {
  117. var selection = fb.GetSelections(0);
  118. var pos = 0;
  119. plman.SetPlaylistFocusItem(pl_dj, pos);
  120. plman.InsertPlaylistItems(pl_dj, pos, selection);
  121. plman.ExecutePlaylistDefaultAction(pl_dj, items.count);
  122. }
  123.  
  124. plman.ActivePlaylist = pl_dj;
  125. //var items = plman.GetPlaylistItems(plman.ActivePlaylist);
  126. plman.ExecutePlaylistDefaultAction(plman.ActivePlaylist, items.count - 2);
  127.  
  128. //if ( items.count > 10 ) {
  129. if ( items.count > 3 && !CtrlDown ) { // clear the old playlist and start a new one (if CTRL is not down)
  130. plman.ClearPlaylistSelection(plman.ActivePlaylist);
  131. plman.SetPlaylistSelectionSingle(plman.ActivePlaylist, items.count - 2 , true); // fb.TitleFormat("%title%")
  132. plman.SetActivePlaylistContext();
  133. fb.RunMainMenuCommand("Edit/Selection/Crop");
  134. }
  135. }
  136.  
  137. // ---> Queue track functions
  138. function queue_track_last() {
  139. var selection = fb.GetSelections(0);
  140. var nowplaying = plman.GetPlayingItemLocation();
  141. var pid;
  142. if (fb.IsPlaying) {
  143. pid = nowplaying.PlaylistItemIndex;
  144. if(pid>=0 && pid<plman.PlaylistItemCount(plman.PlayingPlaylist)) {
  145. //plman.SetPlaylistFocusItem(plman.PlayingPlaylist, pid);
  146. CtrlDown ? plman.InsertPlaylistItems(plman.PlayingPlaylist, plman.PlaylistItemCount(plman.PlayingPlaylist) + 1, selection) : plman.InsertPlaylistItems(plman.PlayingPlaylist, pid + 1, selection);
  147. }
  148. } else {
  149. pid = plman.GetPlaylistFocusItemIndex(plman.PlayingPlaylist)
  150. plman.ExecutePlaylistDefaultAction(plman.PlayingPlaylist, pid);
  151. }
  152. }
  153. /*
  154. // ---> CPU profiling
  155. var UIHacks;
  156. uiHacks = utils.CheckComponent("foo_ui_hacks");
  157. if (uiHacks) {
  158. UIHacks = new ActiveXObject("UIHacks");
  159. }
  160. var g_foo_cpu_usage = "";
  161. UIHacks.CPUUsage;
  162. window.SetInterval(function () {
  163. if(utils.IsKeyPressed(VK_ALT)) {
  164. g_foo_cpu_usage = UIHacks.FoobarCPUUsage.toFixed(1)+'%';
  165. window.RepaintRect(10, 70, 50, 12);
  166. } else {
  167. g_foo_cpu_usage = "";
  168. }
  169. }, 1000);
  170. */
  171. // ================================================== //
  172. function on_draw(gr, x, x2, y, w, h, img, img2, op, state) {
  173. gr.DrawImage(img, Math.ceil(x), Math.ceil(y), Math.ceil(w), Math.ceil(h), 0, state*h, Math.ceil(w), Math.ceil(h), 0, 255); // creating background for buttons
  174. gr.DrawImage(img2, Math.ceil(x2), Math.ceil(y), Math.ceil(w), Math.ceil(h), 0, 0, Math.ceil(w), Math.ceil(h), 0, 200); // draw buttons
  175. }
  176. // ================================================== //
  177. // ---> Callbacks
  178. function on_paint (gr) {
  179.  
  180. gr.FillSolidRect(0,0,ww,wh,RGB(0,0,0))
  181. gr.FillGradRect(-1,-1,ww+1,20,90,RGB(240,240,240),RGB(170,170,170),1);
  182. gr.FillGradRect(-1,14,ww+1,wh-14,90,RGB(90,90,90),RGB(50,50,50),1);
  183. gr.FillSolidRect(-1,12,ww+1,1,RGB(225,225,225));
  184. gr.FillSolidRect(-1,13,ww+1,1,RGB(55,55,55));
  185.  
  186. // ---> FOO %cpu info
  187. //if(g_foo_cpu_usage.length > 0) gr.gdiDrawText(g_foo_cpu_usage, gdi.Font("arial", 9, 1), RGB(0,0,0), 10, 15, 30, 12, DT_LEFT | DT_TOP | DT_NOPREFIX | DT_END_ELLIPSIS);
  188.  
  189. // ---> Draw Volume
  190. /*
  191. vol_pos = vol_w * Math.exp(fb.Volume / 33.333);
  192. gr.DrawImage(VOL_L, vol_x+7, vol_y+7, vol_pos-4, VOL_L.height, 0, 0, VOL_L.width, VOL_L.height, 0, 255);
  193. gr.DrawImage(VOL, vol_x+vol_pos-4, vol_y+2, VOL.width, VOL.height/3, 0, (XYinVol && XYinVol_h) || vol_drag ? ( volstate ==2 || vol_drag ? 2*VOL.height/3 : 1*VOL.height/3) : 0*VOL.height/3, VOL.width, VOL.height/3, 0, 255);
  194. gr.DrawRoundRect(vol_x + 5, vol_y + 5, vol_w, 6, 2, 2, 1, RGBA(255, 255, 255, 50));
  195. gr.DrawRoundRect(vol_x + 6, vol_y + 6, vol_w - 2, 4, 2, 2, 1, RGBA(0, 0, 0, 50));
  196. */
  197. //if (fb.Volume > -1) var pos = vol_w-2;
  198. vol_pos = vol_w * vol2pos(fb.Volume);
  199. gr.DrawImage(VOL_L, vol_x+4, vol_y+7, vol_pos-4, VOL_L.height, 0, 0, VOL_L.width, VOL_L.height, 0, 255);
  200. gr.DrawImage(VOL, vol_x+vol_pos-4, vol_y+2, VOL.width, VOL.height/3, 0, (XYinVol && XYinVol_h) || vol_drag ? ( volstate ==2 || vol_drag ? 2*VOL.height/3 : 1*VOL.height/3) : 0*VOL.height/3, VOL.width, VOL.height/3, 0, 255);
  201. gr.DrawRoundRect(vol_x + 2, vol_y + 5, vol_w, 6, 2, 2, 1, RGBA(255, 255, 255, 50));
  202. gr.DrawRoundRect(vol_x + 3, vol_y + 6, vol_w - 2, 4, 2, 2, 1, RGBA(0, 0, 0, 90));
  203.  
  204. // ---> Draw buttons
  205. for (var i = 0; i < $buttons.length; i++) {
  206. $buttons[i].draw(gr);
  207. }
  208.  
  209. // ---> Draw Seek
  210. var s = seek_drag ? time_pos : fb.PlaybackTime;
  211. var hou = Math.floor((s % 86400) / 3600);
  212. var min = Math.floor(((s % 86400) % 3600) / 60) + ":";
  213. var sec = Math.floor(((s % 86400) % 3600) % 60);
  214. var hou = hou > 0 ? hou + ":" : "";
  215. var sec = sec < 10 ? "0" + sec : sec;
  216. var playback_time = hou + min + sec;
  217.  
  218. if (seek_w > 10) {
  219. gr.DrawRoundRect(seek_x, seek_y + 5, seek_w, 4, 2, 2, 1, RGBA(255, 255, 255, 50));
  220. gr.DrawRoundRect(seek_x + 1, seek_y + 6, seek_w - 2, 4, 1, 1, 1, RGBA(0, 0, 0, 90));
  221.  
  222. if (fb.IsPlaying && fb.PlaybackLength > 0 && !seek_drag) {
  223. seek_pos = seek_w * (fb.PlaybackTime / fb.PlaybackLength) + 1;
  224. }
  225.  
  226. if (fb.IsPlaying && fb.PlaybackLength > 0){
  227. if (seek_pos > 5) gr.DrawImage(SEEK_L1, seek_x + 2, seek_y + 6, seek_pos - 4, SEEK_L1.height, 0, 0, SEEK_L1.width, SEEK_L1.height, 0, 255);
  228.  
  229. if (!XYinSeek) {
  230. seek_pos < 18 ? se = 18 - seek_pos : se = 0;
  231. gr.DrawImage(SEEK_L2, seek_x + seek_pos - SEEK_L2.width + se, seek_y + 6, SEEK_L2.width, SEEK_L2.height, se, 0, SEEK_L2.width, SEEK_L2.height, 0, 255);
  232. } else {
  233. gr.DrawImage(SEEK, seek_x + seek_pos - SEEK.width / 2, seek_y + 4, SEEK.width, SEEK.height / 3, 0, XYinSeek_h || seek_drag ? (lbtn_down || seek_drag ? 2 * SEEK.height / 3 : 1 * SEEK.height / 3) : 0 * SEEK.height / 3, SEEK.width, SEEK.height / 3, 0, 255);
  234. }
  235. }
  236. }
  237.  
  238. // ---> Draw Text
  239. //if(ww > 564) {
  240. if (!volume_change) fb.IsPlaying ? str = fb.TitleFormat("[%playback_time%][ - %length%]").Eval() : str = d.toLocaleTimeString();
  241. //var txt_len = "[ - %length%]";
  242. //if (!volume_change) fb.IsPlaying ? str = fb.TitleFormat("[%playback_time%]" + txt_len).Eval() : str = d.toLocaleTimeString();
  243. if (seek_drag) var str = playback_time + fb.TitleFormat("[ / -%playback_time_remaining%]").Eval();
  244. if (volume_change) var str = Math.round(vol2pos(fb.Volume) * 100) + "% (" + Math.ceil(fb.Volume) + "db)";//Math.ceil(fb.Volume) + "db";
  245.  
  246. var time_font = gdi.font("lucida sans unicode", 13, 1);
  247. var time_font = gdi.font("arial", 13, 1);
  248.  
  249. gr.SetSmoothingMode(4);
  250. g_textrender.GlowText(RGBA(250, 250, 255, 220), RGBA(10, 10, 10, 22), 3);
  251. g_textrender.EnableShadow(true);
  252. g_textrender.ResetShadow();
  253. g_textrender.RenderStringRect(gr, str, time_font, time_x, time_y + 2, time_w, time_h, StringFormat(1, 1, 3, 0x1000));
  254. //}
  255.  
  256. // RATING
  257. if (g_metadb) {
  258. for (i = 1; i < 6; i++) {
  259. //img = DrawPolyStar(gr, R_hoffset+R_imgw*(i-1),R_voffset,22,2.62, 10, 1, RGB(40,40,40),
  260. img = DrawPolyStar(gr, R_hoffset+R_imgw*(i-1),R_voffset,22,1.94, 10, 1, RGB(40,40,40),
  261. ((i > ((g_drag && XYinRate ) ? lrating : rating)) ? RGB(110,110,110) : RGB(200,200,200) ));
  262. }
  263. };
  264. }
  265.  
  266. // ================================================== //
  267. function on_size() {
  268. ww = window.Width;
  269. wh = window.Height;
  270. if (ww <= 0 || wh <= 0) return;
  271.  
  272. seek_x = 10;
  273. seek_y = -2;
  274. seek_w = ww - seek_x*2;
  275. seek_h = 15;
  276.  
  277. //(ww/2 > 300) ? time_x = ww/2-300 : time_x = 0;
  278. time_x = ww/2-285;
  279. time_y = wh-40;
  280. time_w = 109;
  281. time_h = 20;
  282.  
  283. //var bd = 20;
  284. bx = ww/2-PLAY.width/2 ;
  285. by = wh-PLAY.height/3-4;
  286.  
  287. vol_x = ww/2+190;
  288. vol_y = by+12;
  289. vol_w = 70;
  290. vol_h = 17;
  291.  
  292. var MUTE = MUTE_ICO_3;
  293. if(fb.Volume < -10) MUTE = MUTE_ICO_2;
  294. if(fb.Volume < -23) MUTE = MUTE_ICO_1;
  295. if(fb.Volume < -80) MUTE = MUTE_ICO_0;
  296. if(fb.Volume == -100) MUTE = MUTE_ICO;
  297.  
  298. if(fb.PlaybackOrder == 4) S_ICO = SHUFFLE_ICO_; // Shuffle tracks
  299. if(fb.PlaybackOrder == 5) S_ICO = SHUFFLE_ICO_2; // Shuffle albums
  300. if(fb.PlaybackOrder != 4 && fb.PlaybackOrder != 5) S_ICO = SHUFFLE_ICO;
  301.  
  302. if(fb.PlaybackOrder == 2) R_ICO = REPEAT_ICO_; // Repaeat playlist
  303. if(fb.PlaybackOrder == 1) R_ICO = REPEAT_ICO_2; // Repeat track
  304. if(fb.PlaybackOrder != 1 && fb.PlaybackOrder != 2) R_ICO = REPEAT_ICO;
  305.  
  306. var DJ_ICO;
  307. if(plman.GetPlaylistName(fb.PlayingPlaylist) != "Auto DJ") DJ_ICO = adj_button_img;
  308. if(plman.GetPlaylistName(fb.PlayingPlaylist) == "Auto DJ") DJ_ICO = adj_button_down_img;
  309.  
  310. saci ? ST_ICO = STOP_ICO_2 : ST_ICO = STOP_ICO;
  311.  
  312. $buttons = [
  313.  
  314. new Button(bx-PLAY.width-PREV.width+11, bx-PLAY.width-PREV.width+11, by+8, B.width, B.height/3, B, fb.IsPlaying ? ST_ICO : STOP_ICO_, function () {
  315. CtrlDown == true ? fb.RunMainMenuCommand("Playback/Stop after current") : fb.Stop();
  316. },"Stop\n+Ctrl: Stop after current"),
  317. new Button(bx-PREV.width, bx-PREV.width+1, by+8, PREV.width, PREV.height/3, PREV, fb.IsPlaying ? PREV_ICO : PREV_ICO_, function () {
  318. fb.Prev();
  319. }),
  320. new Button(bx, bx+1, by, PLAY.width, PLAY.height / 3, PLAY, fb.IsPlaying ? (fb.IsPaused ? PLAY_ICO : PAUSE_ICO) : PLAY_ICO_, function () {
  321. fb.PlayOrPause();
  322. }),
  323. new Button(bx+PLAY.width, bx+PLAY.width-3, by+8, NEXT.width, NEXT.height/3, NEXT, fb.IsPlaying ? NEXT_ICO : NEXT_ICO_, function () {
  324. fb.Next();
  325. }),
  326. new Button(bx-155, bx-155, by+8, B.width, B.height/3, B, S_ICO, function () {
  327. fb.PlaybackOrder != 4 && fb.PlaybackOrder != 5 ? (CtrlDown ? fb.PlaybackOrder = 5 : fb.PlaybackOrder = 4) : (CtrlDown && fb.PlaybackOrder == 4) ? fb.PlaybackOrder = 5 : fb.PlaybackOrder = 0;
  328. },"Shuffle tracks\n+Ctrl: Shuffle albums"),
  329. new Button(bx-120, bx-120, by+8, B.width, B.height/3, B, R_ICO, function () {
  330. fb.PlaybackOrder != 1 && fb.PlaybackOrder != 2 ? (CtrlDown ? fb.PlaybackOrder = 1 : fb.PlaybackOrder = 2) : (CtrlDown && fb.PlaybackOrder == 2) ? fb.PlaybackOrder = 1 : fb.PlaybackOrder = 0;
  331. },"Repeat track\n+Ctrl: Repeat playlist"),
  332. new Button(bx+185, bx+185, by+8, B.width, B.height/3, B, MUTE, function () {
  333. fb.VolumeMute();
  334. },"Mute"),
  335.  
  336. new Button(bx+105, bx+105, by+8, B.width, B.height/3, B, fb.IsPlaying ? queue_button_img : queue_button_down_img, function () {
  337. queue_track_last();
  338. },"Queue track\n+Ctrl: Queue to the end of playlist"),
  339.  
  340. new Button(bx+145, bx+145, by+8, B.width, B.height/3, B, DJ_ICO, function () {
  341. run_dj();
  342. },"Auto DJ\n+Ctrl: Enable without clearing playlist"),
  343.  
  344. /*new Button(ww-135, ww-135, by+8, B.width, B.height/3, B, eq_button_img, function () {
  345. fb.RunMainMenuCommand("View/Equalizer");
  346. }),*/
  347. new Button(ww-75, ww-75, by+8, B.width, B.height/3, B, dsp_button_img, function () {
  348. CtrlDown == true ? fb.RunMainMenuCommand("View/Equalizer") : fb.RunMainMenuCommand("Playback/DSP settings/Preferences");
  349. },"DSP settings\n+Ctrl: Equalizer"),
  350.  
  351. new Button(ww-105, ww-105, by+8, B.width, B.height/3, B, output_button_img, function () {
  352. fb.RunMainMenuCommand("Playback/Device/Preferences...");
  353. },"Configure audio output"),
  354.  
  355. new Button(ww-45, ww-45, by+8, ww > 482 ? B.width : 0, ww > 482 ? B.height/3 : 0, B, /*fb.IsPlaying ?*/ MENU_ICO /*: MENU_ICO_*/, function () {
  356.  
  357. // ==================== Main Menu==================== //
  358. if (CtrlDown == true) {
  359. fb.RunMainMenuCommand("View/Layout/Enable layout editing mode");
  360. return;
  361. }
  362. var basemenu = window.CreatePopupMenu();
  363. var contextman = fb.CreateContextMenuManager();
  364.  
  365. contextman.InitNowPlaying();
  366.  
  367. var child1 = window.CreatePopupMenu(); //File
  368. var child2 = window.CreatePopupMenu(); //Edit
  369. var child3 = window.CreatePopupMenu(); //View
  370. var child4 = window.CreatePopupMenu(); //Playback
  371. var child5 = window.CreatePopupMenu(); //Library
  372. var child6 = window.CreatePopupMenu(); //Help
  373. var child7 = window.CreatePopupMenu(); //Now playing
  374.  
  375. var menuman1 = fb.CreateMainMenuManager();
  376. var menuman2 = fb.CreateMainMenuManager();
  377. var menuman3 = fb.CreateMainMenuManager();
  378. var menuman4 = fb.CreateMainMenuManager();
  379. var menuman5 = fb.CreateMainMenuManager();
  380. var menuman6 = fb.CreateMainMenuManager();
  381.  
  382. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child1.ID, "File");
  383. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child2.ID, "Edit");
  384. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child3.ID, "View");
  385. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child4.ID, "Playback");
  386. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child5.ID, "Library");
  387. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child6.ID, "Help");
  388. basemenu.AppendMenuItem(MF_STRING | MF_POPUP, child7.ID, "Now Playing");
  389.  
  390. menuman1.Init("file");
  391. menuman2.Init("edit");
  392. menuman3.Init("View");
  393. menuman4.Init("playback");
  394. menuman5.Init("library");
  395. menuman6.Init("help");
  396.  
  397. menuman1.BuildMenu(child1, 1, 200);
  398. menuman2.BuildMenu(child2, 201, 200);
  399. menuman3.BuildMenu(child3, 401, 200);
  400. menuman4.BuildMenu(child4, 601, 300);
  401. menuman5.BuildMenu(child5, 901, 300);
  402. menuman6.BuildMenu(child6, 1201, 100);
  403.  
  404. contextman.InitNowPlaying();
  405. contextman.BuildMenu(child7, 1301, -1);
  406. ret = 0;
  407.  
  408. ret = basemenu.TrackPopupMenu(ww-160, wh-200);
  409.  
  410. switch (true) {
  411.  
  412. case (ret >= 1 && ret < 201):
  413. menuman1.ExecuteByID(ret - 1);
  414. break;
  415. case (ret >= 201 && ret < 401):
  416. menuman2.ExecuteByID(ret - 201);
  417. break;
  418. case (ret >= 401 && ret < 601):
  419. menuman3.ExecuteByID(ret - 401);
  420. break;
  421. case (ret >= 601 && ret < 901):
  422. menuman4.ExecuteByID(ret - 601);
  423. break;
  424. case (ret >= 901 && ret < 1201):
  425. menuman5.ExecuteByID(ret - 901);
  426. break;
  427. case (ret >= 1201 && ret < 1301):
  428. menuman6.ExecuteByID(ret - 1201);
  429. break;
  430. case (ret >= 1301):
  431. contextman.ExecuteByID(ret - 1301);
  432. break;
  433. }
  434.  
  435. basemenu.Dispose();
  436. contextman.Dispose();
  437. menuman1.Dispose();
  438. menuman2.Dispose();
  439. menuman3.Dispose();
  440. menuman4.Dispose();
  441. menuman5.Dispose();
  442. menuman6.Dispose();
  443. },"Main menu\n+Ctrl: Toggle layout edditing mode")
  444. ]
  445. }
  446.  
  447. // ================================================== //
  448. //var voltimeout;
  449. function elements_on_mouse_move (x, y) {
  450. XYinVol = ((vol_x <= x) && (x <= vol_x + vol_w+5) && (vol_y <= y) && (y <= vol_y + vol_h));
  451. //XYinVol_h = ((vol_x+vol_pos-VOL.width/2 <= x) && (x <= vol_x+vol_pos-VOL.width/2 + VOL.width) && (vol_y <= y) && (y <= vol_y + vol_h));
  452. XYinSeek = ((seek_x <= x) && (x <= seek_x + seek_w) && (seek_y <= y) && (y <= seek_y + seek_h));
  453. XYinSeek_h = ((seek_x + seek_pos - SEEK.width / 2 <= x) && (x <= seek_x + seek_pos - SEEK.width / 2 + SEEK.width) && (seek_y <= y) && (y <= seek_y + seek_h));
  454. //window.RepaintRect(vol_x+vol_pos-VOL.width/2-3, vol_y, VOL.width+10, vol_h); // Repaint vol knob
  455. /*
  456. if (XYinVol && XYinVol_h) {
  457. window.RepaintRect(vol_x+vol_pos-VOL.width/2-3, vol_y, VOL.width+10, vol_h); // Repaint vol knob
  458. } else { // TEST THIS SHIT
  459. voltimeout = window.SetTimeout(function() {
  460. volstate = 0;
  461. window.RepaintRect(vol_x+vol_pos-VOL.width/2-3, vol_y, VOL.width+10, vol_h); // Repaint vol knob
  462. window.ClearInterval(voltimeout);
  463. }, 100);
  464. }
  465. */
  466. //var v = (x - vol_x) / vol_w;
  467. //if (vol_drag == true && v > 0) fb.Volume = Math.log(v) * 33.333;
  468. //if (vol_drag == true && v > 0) fb.Volume = pos2vol(v);
  469. var v = Math.max(0, Math.min(vol_w, x - vol_x)) / vol_w
  470. if (vol_drag == true && v >= 0) fb.Volume = pos2vol(v);
  471. if (vol_drag) window.RepaintRect(bx+185+B.width, by+8, vol_w+10, vol_h); // vol area; VOL.height
  472.  
  473. if (fb.PlaybackTime > 0 && XYinSeek && seek_drag) {
  474. seek_pos = seek_w * (x / seek_w) - seek_x;
  475. time_pos = fb.PlaybackLength * (x - seek_x) / seek_w;
  476. }
  477. if (seek_drag) window.RepaintRect(seek_x - 15, 0, ww, wh); //Repaint seek area;*/
  478. }
  479.  
  480. var rate_timer = rate_timeout = false;
  481. function rating_on_mouse_move (x, y) {
  482. XYinRate = ((R_hoffset <= x) && (x <= R_hoffset + R_w+5) && (R_voffset <= y) && (y <= R_voffset + R_imgw));
  483. if (g_metadb && XYinRate) {
  484. g_drag = 1;
  485. nrating = Math.ceil((x-R_hoffset)/R_imgw);
  486. if (nrating > 5) nrating = 5;
  487. if (nrating != lrating) {
  488. lrating = nrating;
  489. }
  490. }
  491. if (XYinRate) { // mouse enters stars area
  492. if (!rate_timer) rate_timer = window.SetInterval(function() {
  493. //if (g_metadb && XYinRate) {
  494. if (g_metadb) {
  495. window.RepaintRect(R_hoffset, R_voffset, R_imgw*5, R_imgw+5); //Repaint RATING area;
  496. }
  497. }, 80); // 80 ms refresh rate seems smooth enough
  498. } else { // mouse leaving stars area
  499. /*if (lrating !=rating) {
  500. g_drag = rating;
  501. };*/
  502. if (rate_timer) rate_timeout = window.SetTimeout(function() { // timeout to kill timer
  503. if (rate_timer) window.ClearInterval(rate_timer);
  504. rate_timer = false;
  505. //window.RepaintRect(R_hoffset, R_voffset, R_imgw*5, R_imgw+5); //Repaint RATING area;
  506. on_metadb_changed();
  507. //if (rate_timeout) window.ClearInterval(rate_timeout);
  508. }, 150);
  509. }
  510. }
  511.  
  512. function on_mouse_move(x, y) {
  513.  
  514. elements_on_mouse_move (x, y);
  515.  
  516. rating_on_mouse_move (x, y);
  517.  
  518. buttons_on_mouse_move(x, y);
  519.  
  520. if (XYinVol || XYinSeek || XYinRate) {
  521. window.SetCursor(32649);
  522. } else {
  523. if (!hbtn) {
  524. window.SetCursor(32512);
  525. }
  526. }
  527. }
  528.  
  529. // ================================================== //
  530.  
  531.  
  532. function on_volume_change(val) {
  533. volume_change = true;
  534.  
  535. //vol_timer = window.CreateTimerTimeout(2000); // window.SetInterval(2000); //
  536. vol_timer = window.SetTimeout(function() {
  537. //if (vol_timer && id == vol_timer.ID) {
  538. volume_change = false;
  539. window.ClearInterval(vol_timer);
  540. //window.RepaintRect(time_x, time_y, time_w, time_h); // time area
  541. //}
  542. }, 2000);
  543. window.RepaintRect(time_x, time_y, time_w, time_h); // time area
  544. window.RepaintRect(vol_x+vol_pos-VOL.width/2-3, vol_y, VOL.width+10, vol_h); // Repaint vol knob
  545. on_size();
  546. //window.RepaintRect(bx+100, by+5, 115, B.height/3+5);
  547. window.RepaintRect(bx+185, by+8, B.width+5, B.height/3+5); // vol button area
  548. }
  549.  
  550. // ================================================== //
  551.  
  552. function on_mouse_lbtn_down(x, y) {
  553. volstate == 1 ? volstate = 2: volstate = 0;
  554.  
  555. if (XYinVol) {
  556. vol_drag = true;
  557. //on_mouse_move(x, y);
  558. elements_on_mouse_move (x, y);
  559. }
  560.  
  561. if (XYinSeek && fb.Isplaying) {
  562. seek_drag = true;
  563. volume_change = false;
  564. if (fb.PlaybackTime > 0 && seek_drag) {
  565. //on_mouse_move(x, y);
  566. elements_on_mouse_move (x, y);
  567. }
  568. }
  569.  
  570. CtrlDown = utils.IsKeyPressed(0x11) ? true : false;
  571. buttons_on_mouse_lbtn_down(x, y);
  572. }
  573.  
  574. // ================================================== //
  575.  
  576. function on_mouse_lbtn_up(x, y) {
  577. volstate = 0;
  578. vol_drag = false;
  579.  
  580. lbtn_down = false;
  581. if (XYinSeek && seek_drag) {
  582. fb.PlaybackTime = fb.PlaybackLength * (x - seek_x) / seek_w;
  583.  
  584. }
  585. seek_drag = false;
  586. window.Repaint();
  587.  
  588. buttons_on_mouse_lbtn_up(x, y);
  589.  
  590. //RATING
  591. if (lrating !=rating && XYinRate) {if (g_metadb) {
  592. bool = g_metadb.UpdateFileInfoSimple("RATING",lrating);
  593. }}
  594.  
  595. }
  596.  
  597. // ================================================== //
  598.  
  599. function on_mouse_leave() {
  600. XYinVol_h = XYinVol = XYinSeek = seek_drag = lbtn_down = vol_drag = XYinRate = false;
  601.  
  602. //RATING
  603. //on_metadb_changed();
  604.  
  605. if(!vol_timer)
  606. volume_change = false;
  607. buttons_on_mouse_leave();
  608. }
  609.  
  610. function on_item_focus_change() {
  611. if (g_metadb) {window.UnwatchMetadb();}
  612. g_metadb = fb.GetFocusItem();
  613. if (fb.GetNowPlaying()) {g_metadb = fb.GetNowPlaying();}
  614. if (g_metadb) {
  615. on_metadb_changed();
  616. window.WatchMetadb(g_metadb);
  617. }
  618. window.RepaintRect(R_hoffset, R_voffset, R_imgw*5, R_imgw+5); //Repaint RATING area;
  619. }
  620. on_item_focus_change();
  621.  
  622. function on_metadb_changed() {
  623. g_drag = 0;
  624. //rating = g_rate.EvalWithMetadb(g_metadb);
  625. if (g_metadb) {rating = g_rate.EvalWithMetadb(g_metadb);}
  626. if (rating == "?") {rating = 0;}
  627. lrating = rating;
  628. //window.Repaint();
  629. window.RepaintRect(R_hoffset, R_voffset, R_imgw*5, R_imgw+5); //Repaint RATING area;
  630. }
  631.  
  632. // ================================================== //
  633.  
  634. function on_playback_pause(state) {
  635. on_size();
  636. window.RepaintRect(bx, by, PLAY.width, PLAY.height/3-3); // PLAY/PAUSE area
  637. }
  638.  
  639. // ================================================== //
  640.  
  641. function on_playback_stop(reason) {
  642. if (reason != 2) {
  643. saci = false;
  644. seek_pos = 0;
  645. on_size();
  646. window.Repaint();
  647. }
  648. }
  649.  
  650. // ================================================== //
  651.  
  652. function on_mouse_wheel(delta) {
  653. volume_change = true;
  654. fb.Volume = fb.Volume + delta * Math.exp(-fb.Volume / 33.333);
  655. }
  656.  
  657. // ================================================== //
  658.  
  659. function on_mouse_lbtn_dblclk(x, y) {
  660. if(!xy && !XYinVol && !XYinRate && !XYinSeek)
  661. fb.ShowPreferences();
  662. }
  663.  
  664. // ================================================== //
  665.  
  666. function on_mouse_rbtn_down(x, y) {
  667. ShiftDown = utils.IsKeyPressed(0x10) ? true : false;
  668. }
  669.  
  670. // ================================================== //
  671.  
  672. function on_playlist_stop_after_current_changed(state) {
  673. state ? sac = true : sac = false;
  674. if(sac == false) saci = false;
  675. on_size();
  676. window.RepaintRect(ww/2-110,22,32,32); // stop area
  677. }
  678.  
  679. // ================================================== //
  680.  
  681. function on_playback_time(time) {
  682. if (sac == true && Math.round(time % 2) == 1) {
  683. saci == false ? saci = true : saci = false;
  684. on_size();
  685. window.RepaintRect(ww/2-110,22,32,32); // stop area
  686. }
  687.  
  688. if(volume_change == false) window.RepaintRect(time_x, time_y, time_w, time_h); // display volume value in time area
  689. }
  690.  
  691. // ================================================== //
  692.  
  693. function on_playback_order_changed(new_order_index) {
  694. on_size();
  695. window.RepaintRect(bx-170, by+5, 70, B.height/3+5); // PBO
  696. }
  697. // ================================================== //
  698.  
  699. function on_playback_new_track() {
  700. window.RepaintRect(0, 0, ww, 20); //Repaint seek area;
  701.  
  702. //RATING
  703. if (rate_timer) { window.ClearInterval(rate_timer); rate_timer = false; }
  704. if (rate_timeout) { window.ClearInterval(rate_timeout); rate_timeout = false; }
  705. g_drag = 0;
  706. on_item_focus_change();
  707. }
  708. // ================================================== //
  709.  
  710. function on_mouse_rbtn_up(x, y) {
  711.  
  712. var Menu = window.CreatePopupMenu();
  713.  
  714. Menu.AppendMenuItem(MF_STRING, 1, "Google");
  715. Menu.AppendMenuItem(MF_STRING, 2, "Google Images");
  716. //Menu.AppendMenuItem(MF_STRING, 3, "Cover-Paradies");
  717. Menu.AppendMenuItem(MF_STRING, 4, "Wikipedia");
  718. Menu.AppendMenuItem(MF_STRING, 5, "YouTube");
  719. Menu.AppendMenuItem(MF_STRING, 6, "Last FM");
  720. Menu.AppendMenuItem(MF_STRING, 7, "Discogs");
  721. Menu.AppendMenuItem(MF_STRING, 8, "RuTracker");
  722.  
  723. if(ShiftDown){
  724.  
  725. Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  726.  
  727. Menu.AppendMenuItem(MF_STRING, 20, "Properties");
  728. Menu.AppendMenuItem(MF_STRING, 21, "Configure...");
  729.  
  730. }
  731. Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  732.  
  733. Menu.AppendMenuItem(MF_STRING, 22, "Console");
  734. Menu.AppendMenuItem(MF_STRING, 23, "Restart Foobar");
  735. //Menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  736.  
  737. switch (Menu.TrackPopupMenu(x, y)) {
  738. case 1:
  739. try {WshShell.run("http://images.google.com/search?q="+fb.TitleFormat("$replace(%artist%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  740. break;
  741. case 2:
  742. try {WshShell.run("http://images.google.com/images?hl=en&q="+fb.TitleFormat("$replace(%artist%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  743. break;
  744. //case 3:
  745. //try {WshShell.run("http://cover-paradies.to/?Module=ExtendedSearch&SearchString="+fb.TitleFormat("$replace(%artist%+%album%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  746. //break;
  747. case 4:
  748. try {WshShell.run("http://en.wikipedia.org/wiki/"+fb.TitleFormat("$replace(%artist%,' ','_','&','and')").Eval(true));} catch (e) {};
  749. break;
  750. case 5:
  751. try {WshShell.run("http://www.youtube.com/results?search_type=&search_query="+fb.TitleFormat("$replace(%artist%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  752. break;
  753. case 6:
  754. try {WshShell.run("http://www.last.fm/music/" + fb.TitleFormat("$replace(%artist%,' ','+','&','and','/','%252F')").Eval(true));} catch (e) {};
  755. break;
  756. case 7:
  757. try {WshShell.run("http://www.discogs.com/search?q=" + fb.TitleFormat("$replace(%artist%+%album%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  758. break;
  759. case 8:
  760. try {WshShell.run("http://rutracker.org/forum/tracker.php?nm=" + fb.TitleFormat("$replace(%artist%+%album%, ,+)&ie=utf-8").Eval(true));} catch (e) {};
  761. break;
  762. case 20:
  763. window.ShowProperties();
  764. break;
  765. case 21:
  766. window.ShowConfigure();
  767. break;
  768. case 22:
  769. fb.ShowConsole();
  770. break;
  771. case 23:
  772. fb.RunMainMenuCommand("File/Restart");
  773. break;
  774. }
  775.  
  776. Menu.Dispose();
  777. return true
  778.  
  779. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement