Advertisement
Guest User

Untitled

a guest
Feb 13th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.05 KB | None | 0 0
  1. // ==PREPROCESSOR==
  2. // @name "DarkOne Cover Panel"
  3. // @version "3.1"
  4. // @author "tedGo, includes partial code by T.P Wang"
  5. // @import "%fb2k_path%themes\DarkOne\Others\WSH Scripts\DO Global Script.js"
  6. // ==/PREPROCESSOR==
  7.  
  8. // ----- VARIABLES -----
  9. var g_font = gdi.Font("Arial", 32, 1);
  10. var g_textrender = gdi.CreateStyleTextRender();
  11. var g_img = descr_timer = cycle_timer = null;
  12. var g_active = false;
  13. var g_fade = 255;
  14. var g_state = 0;
  15. var metadb;
  16.  
  17. // ----- CREATE OPTIONS -----
  18. var a_arr = new Array("Picture 1", "Picture 2", "Picture 3", "Picture 4", "Picture 5");
  19. var b_arr = new Array("Front cover", "Back cover", "Disc", "Icon", "Artist");
  20.  
  21. function artType() {
  22. at = window.GetProperty("Enable Custom Pictures", false);
  23. c_arr = at ? a_arr : b_arr;
  24. }
  25.  
  26. artType();
  27.  
  28. function aspectRatio() {
  29. ar = window.GetProperty("Aspect ratio", 0);
  30. if (typeof ar < 0 || ar > 2) ar = 0;
  31. return ar;
  32. }
  33.  
  34. aspectRatio();
  35.  
  36. // ----- GET PICTURE -----
  37. var imgPath = configPath + "Images\\";
  38. var a_img = gdi.Image(imgPath + "DarkOne.png");
  39. var b_img = gdi.Image(imgPath + "Radio.png");
  40. var c_img = gdi.Image(imgPath + "AudioCD.png");
  41. var d_img = gdi.Image(imgPath + "NoImage.png");
  42.  
  43. var e_arr = [];
  44. e_arr[0] = gdi.Image(imgPath + "NoFront.png");
  45. e_arr[1] = gdi.Image(imgPath + "NoBack.png");
  46. e_arr[2] = gdi.Image(imgPath + "NoDisc.png");
  47. e_arr[3] = gdi.Image(imgPath + "NoIcon.png");
  48. e_arr[4] = gdi.Image(imgPath + "NoArtist.png");
  49.  
  50. var f_arr = [];
  51. f_arr[0] = window.GetProperty(a_arr[0],"");
  52. f_arr[1] = window.GetProperty(a_arr[1],"");
  53. f_arr[2] = window.GetProperty(a_arr[2],"");
  54. f_arr[3] = window.GetProperty(a_arr[3],"");
  55. f_arr[4] = window.GetProperty(a_arr[4],"");
  56.  
  57. var g_ext = window.GetProperty("File extension order", "jpg|png|gif|bmp|tif");
  58. var g_arr = g_ext.split("|");
  59.  
  60. var g_art = null;
  61.  
  62. function getRightImage(switchstate) {
  63. metadb = fb.GetNowPlaying();
  64.  
  65. if (g_art) {
  66. g_img.Dispose();
  67. g_art = null;
  68. }
  69.  
  70. if (metadb) {
  71. var f_img = null;
  72. if (fb.PlaybackLength <= 0) {
  73. f_img = b_img;
  74. g_active = false;
  75. } else if (metadb.RawPath.indexOf("cdda://") == 0) {
  76. f_img = c_img;
  77. g_active = false;
  78. } else {
  79. var old_state = g_state;
  80. do {
  81. switchstate && switchState();
  82. if (at) {
  83. var arr = utils.Glob(fb.TitleFormat(f_arr[g_state]).Eval() + ".*").toArray();
  84. var g_break = false;
  85. for (var n = 0; n < g_arr.length && !g_break; n++) {
  86. for (var i = 0; i < arr.length; i++) {
  87. var re = new RegExp("\." + g_arr[n] + "$", "i");
  88. if (arr[i].match(re)) {
  89. g_art = gdi.Image(arr[i]);
  90. g_break = true;
  91. break;
  92. }
  93. }
  94. }
  95. f_img = g_art;
  96. } else {
  97. g_art = utils.GetAlbumArtV2(metadb, g_state);
  98. f_img = g_art;
  99. }
  100. }
  101. while (switchstate && old_state != g_state && !f_img);
  102. g_active = true;
  103. }
  104. } else {
  105. f_img = a_img;
  106. g_active = false;
  107. }
  108.  
  109. if (f_img) g_img = f_img;
  110. else if (!switchstate) g_img = at ? d_img : e_arr[g_state];
  111.  
  112. return g_img ? true : false;
  113. }
  114.  
  115. getRightImage(false);
  116.  
  117. // ----- CREATE ACTIONS -----
  118. function getTimer() {
  119. if (descr_timer) {
  120. window.ClearTimeout(descr_timer);
  121. descr_timer = null;
  122. }
  123.  
  124. descr_timer = window.SetTimeout(
  125. function () {
  126. window.RepaintRect(0, wh / 2, ww, wh / 2);
  127. window.ClearTimeout(descr_timer);
  128. descr_timer = null;
  129. }, 1500);
  130.  
  131. window.Repaint();
  132. }
  133.  
  134. function switchState() {
  135. if (g_state == 4) g_state = 0;
  136. else g_state++;
  137. }
  138.  
  139. function switchType() {
  140. window.SetProperty("Enable Custom Pictures", at ? false : true);
  141. artType();
  142. g_state = 0;
  143. getRightImage(false);
  144. if (g_active && !g_art) getRightImage(true);
  145. getTimer();
  146. }
  147.  
  148. // ----- CREATE MENU -----
  149. function CustomMenu(x, y) {
  150. var a = window.CreatePopupMenu();
  151. var b = window.CreatePopupMenu();
  152. var idx;
  153.  
  154. if (!ac) {
  155. for (var i = 0; i < c_arr.length; i++) {
  156. b.AppendMenuItem(0, 101 + i, c_arr[i]);
  157. }
  158. b.CheckMenuRadioItem(101, 105, g_state + 101);
  159. }
  160.  
  161. a.AppendMenuItem(0, 1, "Keep aspect ratio");
  162. a.AppendMenuItem(0, 2, "Noexpansion");
  163. a.AppendMenuItem(0, 3, "Stretch");
  164. a.CheckMenuRadioItem(1, 3, ar + 1);
  165. a.AppendMenuSeparator();
  166. a.AppendMenuItem(0, 4, at ? "Album art" : "Custom pictures");
  167. a.AppendMenuSeparator();
  168. b.AppendTo(a, 0 | 16, at ? "Pictures" : "Artwork type");
  169. a.AppendMenuSeparator();
  170. a.AppendMenuItem(ac ? 8 : 0, 5, "Auto cycle image");
  171. ac && a.AppendMenuItem(ct ? 8 : 0, 6, "Faded transition");
  172. a.AppendMenuSeparator();
  173. a.AppendMenuItem(0, 7, "Manage attached pictures");
  174. a.AppendMenuItem(0, 8, "Remove all pictures");
  175. a.AppendMenuSeparator();
  176. a.AppendMenuItem(0, 9, "Properties");
  177. a.AppendMenuItem(0, 10, "Configure...");
  178.  
  179. idx = a.TrackPopupMenu(x, y);
  180.  
  181. switch (true) {
  182. case (idx >= 101 && idx <= 105):
  183. g_state = idx - 101;
  184. getRightImage(false);
  185. getTimer();
  186. break;
  187.  
  188. case (idx >= 1 && idx <= 3):
  189. window.SetProperty("Aspect ratio", idx - 1);
  190. aspectRatio();
  191. window.Repaint();
  192. break;
  193.  
  194. case (idx == 4):
  195. switchType();
  196. break;
  197.  
  198. case (idx == 5):
  199. window.SetProperty("Auto Cycle Image", ac ? false : true);
  200. ac = window.GetProperty("Auto Cycle Image");
  201. break;
  202.  
  203. case (idx == 6):
  204. window.SetProperty("Auto Cycle Transition Fader on", ct ? false : true);
  205. ct = window.GetProperty("Auto Cycle Transition Fader on");
  206. break;
  207.  
  208. case (idx == 7):
  209. fb.RunContextCommand("Manage attached pictures");
  210. break;
  211.  
  212. case (idx == 8):
  213. fb.RunContextCommand("Remove all pictures");
  214. break;
  215.  
  216. case (idx == 9):
  217. window.ShowProperties();
  218. break;
  219.  
  220. case (idx == 10):
  221. window.ShowConfigure();
  222. break;
  223. }
  224.  
  225. a.Dispose();
  226. }
  227.  
  228. // ----- DRAW -----
  229. var overlay_active = window.GetProperty("Back Overlay: Activate", true);
  230. var overlay_colour = window.GetProperty("Back Overlay: Colour", "63-100-127-72");
  231. var g_acol = CustomColour(overlay_colour);
  232.  
  233. var descr_tcolour = window.GetProperty("Description: Text Colour", "191-224-255-255");
  234. var g_bcol = CustomColour(descr_tcolour);
  235.  
  236. var descr_bcolour = window.GetProperty("Description: Back Colour", "31-50-63-255");
  237. var g_ccol = CustomColour(descr_bcolour);
  238.  
  239. function on_paint(gr) {
  240. !window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, ui_backcol);
  241. fb.IsPlaying && overlay_active && gr.FillSolidRect(0, 0, ww, wh, g_acol);
  242.  
  243. if (g_img) {
  244. var w, h, x, y;
  245. if (ar == 0 || ar == 1 && (g_img.Width > ww || g_img.Height > wh)) {
  246. var img_scale = Math.min(ww / g_img.Width, wh / g_img.Height);
  247. w = g_img.Width * img_scale;
  248. h = g_img.Height * img_scale;
  249. x = (ww - w) / 2;
  250. y = (wh - h) / 2;
  251. } else if (ar == 1) {
  252. w = g_img.Width;
  253. h = g_img.Height;
  254. x = (ww - w) / 2;
  255. y = (wh - h) / 2;
  256. } else {
  257. w = ww;
  258. h = wh;
  259. x = y = 0;
  260. }
  261. gr.DrawImage(g_img, x, y, w, h, 0, 0, g_img.Width, g_img.Height, 0, Math.abs(g_fade));
  262. }
  263.  
  264. if (descr_timer) {
  265. gr.SetTextRenderingHint(5);
  266. gr.SetSmoothingMode(4);
  267. gr.SetInterpolationMode(7);
  268. gr.FillGradRect(-1, wh / 2, ww + 1, wh / 2, 90, 0, g_ccol);
  269. g_textrender.GlowText(g_bcol, RGBA(128, 192, 255, 4), 32);
  270. g_textrender.EnableShadow(true);
  271. g_textrender.ResetShadow();
  272. g_textrender.RenderStringRect(gr, c_arr[g_state], g_font, 0, wh - 50, ww, 30, 0x11005000);
  273. }
  274. }
  275.  
  276. // ----- MOUSE ACTIONS -----
  277. function on_mouse_move(x, y) {
  278. !ac && g_active && window.SetCursor(32649);
  279. }
  280.  
  281. function on_mouse_lbtn_down(x, y) {
  282. if (!ac && g_active) {
  283. getRightImage(true);
  284. getTimer();
  285. }
  286. }
  287.  
  288. function on_mouse_mbtn_down(x, y) {
  289. g_active && switchType();
  290. }
  291.  
  292. function on_mouse_rbtn_up(x, y) {
  293. if (g_active) {
  294. CustomMenu(x, y);
  295. return true;
  296. }
  297. }
  298.  
  299. function on_mouse_wheel(step) {
  300. if (!ac && g_active) {
  301. g_state -= step;
  302. if (g_state < 0 ) g_state = 4;
  303. else if (g_state > 4) g_state = 0;
  304. getRightImage(false);
  305. getTimer();
  306. }
  307. }
  308.  
  309. // ----- EVENTS -----
  310. var ac = window.GetProperty("Auto Cycle Image", false);
  311. var ci = window.GetProperty("Auto Cycle Interval in s", 15);
  312. var ct = window.GetProperty("Auto Cycle Transition Fader on", false);
  313.  
  314. function on_size() {
  315. ww = window.Width;
  316. wh = window.Height;
  317. }
  318.  
  319. function on_playback_new_track(metadb) {
  320. getRightImage(false);
  321. window.Repaint();
  322. }
  323.  
  324. function on_playback_time(time) {
  325. if (ac && g_active && g_art && time > 1 && Math.round(time % ci) == 1) {
  326. if (ct) {
  327. if (cycle_timer) {
  328. window.ClearInterval(cycle_timer);
  329. cycle_timer = null;
  330. }
  331. cycle_timer = window.SetInterval(
  332. function () {
  333. g_fade -= 51;
  334. if (g_fade <= -255) {
  335. g_fade = 255;
  336. window.ClearInterval(cycle_timer);
  337. cycle_timer = null;
  338. }
  339. if (g_fade == 0) getRightImage(true);
  340. window.Repaint();
  341. }, 50);
  342. } else {
  343. getRightImage(true);
  344. window.Repaint();
  345. }
  346. }
  347. }
  348.  
  349. function on_playback_stop(reason) {
  350. if (cycle_timer) {
  351. window.ClearInterval(cycle_timer);
  352. cycle_timer = null;
  353. g_fade = 255;
  354. }
  355.  
  356. if (descr_timer) {
  357. window.ClearTimeout(descr_timer);
  358. descr_timer = null;
  359. }
  360.  
  361. if (reason != 2) {
  362. getRightImage(false);
  363. window.Repaint();
  364. }
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement