Advertisement
Guest User

Untitled

a guest
Aug 4th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.32 KB | None | 0 0
  1. // ==PREPROCESSOR==
  2. // @import "%fb2k_profile_path%marc2003\common.js"
  3. // @name "Thumbs2"
  4. // @author "marc2003"
  5. // ==/PREPROCESSOR==
  6.  
  7. var panel_id = window.GetProperty("panel_id", window.id);
  8. var cycle_tf_file = settings_path + panel_id + "cycle";
  9. var cycle_tf = read(cycle_tf_file);
  10.  
  11. var g_img = arr = new Array();
  12. var artist = '';
  13. var folder = '';
  14. var index = 0;
  15. var offset = 0;
  16. var my_y = 0;
  17. var but_y = 0;
  18. var x_off = 0;
  19. var images_width = 0;
  20. var working = false;
  21. var blacklist_file = '';
  22. var back_img = gdi.Image(images_path + "back.png");
  23. var forward_img = gdi.Image(images_path + "forward.png");
  24.  
  25. var thumb_size = window.GetProperty("thumb_size", 75);
  26. var square = window.GetProperty("square", false);
  27. var cycle = window.GetProperty("cycle", 200) - 200;
  28. var limit = window.GetProperty("limit", 305) - 300;
  29. window.GetProperty("bl", true);
  30. window.GetProperty("auto", true);
  31. window.GetProperty("mode", 101);
  32.  
  33. on_item_focus_change();
  34.  
  35. function on_playback_time(time) {
  36. if(cycle > 0 && arr.length > 1 && (time % cycle == 0)) on_mouse_wheel(-1);
  37. if(window.GetProperty("mode") == 101 && time == 1 && arr.length == 0 && window.GetProperty("auto")) download_images();
  38. }
  39.  
  40. function on_mouse_move(x, y) {
  41. my_y = y;
  42. switch(true) {
  43. case (!g_metadb):
  44. case (g_img.length == 0):
  45. window.SetCursor(IDC_ARROW);
  46. break;
  47. case (g_img.length == 1):
  48. case (g_img.length > columns && offset > 0 && x > (x_off - 25) && x< x_off - 5 && y > but_y && y < but_y + 20):
  49. case (g_img.length > columns && offset < g_img.length - columns && x > x_off + images_width + 5 && x < x_off + images_width + 25 && y > but_y && y < but_y + 20):
  50. case (y > 20 && y < wh - (thumb_size + 30)):
  51. case (y > wh - thumb_size - 12 && x > x_off && x < x_off + images_width):
  52. window.SetCursor(IDC_HAND);
  53. break;
  54. default:
  55. window.SetCursor(IDC_ARROW);
  56. }
  57. }
  58.  
  59. function on_mouse_lbtn_up(x,y) {
  60. switch(true) {
  61. case (!g_metadb):
  62. case (g_img.length == 0):
  63. return;
  64. case (g_img.length == 1):
  65. case (y > 10 && y < wh - (thumb_size + 30)):
  66. try { WshShell.Run("\"" + arr[index] + "\""); } catch(e) {}
  67. break;
  68. case (y > wh - thumb_size - 12 && x > x_off && x < x_off + images_width):
  69. index = Math.floor(((x - x_off) / (thumb_size + 10)) + offset);
  70. window.RepaintRect(0, 0, ww, wh - thumb_size - 15);
  71. break;
  72. case (g_img.length > columns && offset > 0 && x > (x_off - 25) && x< x_off - 5 && y > but_y && y < but_y + 20):
  73. offset--;
  74. window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
  75. break;
  76. case (g_img.length > columns && offset < g_img.length - columns && x > x_off + images_width + 5 && x < x_off + images_width + 25 && y > but_y && y < but_y + 20):
  77. offset++;
  78. window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
  79. break;
  80. default:
  81. }
  82. }
  83.  
  84. function clear_cache() {
  85. if(g_img.length == 0) return;
  86. for(i = 0; i < g_img.length; i++) {
  87. g_img[i].Dispose();
  88. }
  89. g_img = new Array();
  90. window.Repaint();
  91. }
  92.  
  93. function on_playback_new_track() {
  94. on_item_focus_change();
  95. }
  96.  
  97. function on_metadb_changed() {
  98. if(window.GetProperty("mode") == 101 && artist == fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb)) return;
  99. if(window.GetProperty("mode") == 102 && folder == fb.TitleFormat(cycle_tf).EvalWithMetadb(g_metadb)) return;
  100. update_image();
  101. }
  102.  
  103. function update_image() {
  104. if(!g_metadb) return;
  105. clear_cache();
  106. if(window.GetProperty("mode") == 101) {
  107. artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
  108. folder = data_folder + fb.TitleFormat("$crc32(%artist%)").EvalWithMetadb(g_metadb);
  109. bl();
  110. } else {
  111. folder = fb.TitleFormat(cycle_tf).EvalWithMetadb(g_metadb);
  112. }
  113. arr = read_images();
  114. offset = 0;
  115. index = 0;
  116. load_image();
  117. }
  118.  
  119. function load_image() {
  120. g_img = new Array();
  121. for(i = 0; i < arr.length; i++) {
  122. g_img[i] = gdi.Image(arr[i]);
  123. }
  124. window.Repaint();
  125. }
  126.  
  127. function on_mouse_wheel(delta) {
  128. if(!g_metadb || g_img.length < 2) return;
  129. if(my_y < wh - (thumb_size + 30)) {
  130. index += -delta;
  131. if(index < 0) index = g_img.length - 1;
  132. if(index >= g_img.length) index = 0;
  133. window.RepaintRect(0, 0, ww, wh - thumb_size - 15);
  134. } else {
  135. if(g_img.length < columns) return;
  136. offset += -delta;
  137. if(offset < 0) offset = 0;
  138. if(offset > g_img.length - columns) offset = g_img.length - columns;
  139. window.RepaintRect(0, wh - thumb_size - 15, ww, thumb_size + 15);
  140. }
  141. }
  142.  
  143. function on_size() {
  144. ww = window.width;
  145. wh = window.height;
  146. columns = Math.floor((ww - 50) / (thumb_size + 10));
  147. offset = 0;
  148. }
  149.  
  150. function on_paint(gr) {
  151. gr.SetInterpolationMode(6);
  152. gr.FillSolidRect(0, 0, ww, wh, g_backcolor);
  153. switch(true) {
  154. case (!g_metadb):
  155. gr.GdiDrawText("[no selection]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  156. break;
  157. case (working):
  158. gr.GdiDrawText("[fetching images]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  159. break;
  160. case (g_img.length == 0):
  161. gr.GdiDrawText("[no image]", g_font, g_textcolor, 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
  162. break;
  163. case (g_img.length == 1):
  164. scale2(gr, g_img[0], 10, 10, ww - 20, wh - 20, false);
  165. break;
  166. default:
  167. temp = Math.min(columns, g_img.length);
  168. images_width = (thumb_size * temp) + (temp > 1 ? (temp - 1) * 10 : 0);
  169. x_off = Math.round((ww - images_width) / 2);
  170. current_image = offset;
  171. for(col = 0; col < temp; col++) {
  172. g_img[current_image] && scale2(gr, g_img[current_image], x_off + (col * (thumb_size + 10)), wh - thumb_size - 10, thumb_size, thumb_size, square);
  173. current_image++;
  174. }
  175. scale2(gr, g_img[index], 10, 20, ww - 20, wh - thumb_size - 50, false);
  176. if(g_img.length > columns) {
  177. but_y = wh - thumb_size - 10 + (Math.round((thumb_size - 20) / 2));
  178. if(offset > 0) gr.DrawImage(back_img, x_off - 25, but_y, 20, 20, 0, 0, 20, 20);
  179. if(offset < g_img.length - columns) gr.DrawImage(forward_img, x_off + images_width + 5, but_y, 20, 20, 0, 0, 20, 20);
  180. }
  181. break;
  182. }
  183. }
  184.  
  185. function on_mouse_rbtn_up(x, y) {
  186. var _menu = window.CreatePopupMenu();
  187. var _lastfm_options = window.CreatePopupMenu();
  188. var _limit = window.CreatePopupMenu();
  189. var _thumb = window.CreatePopupMenu();
  190. var _mode = window.CreatePopupMenu();
  191. var _cycle = window.CreatePopupMenu();
  192. var _selection = window.CreatePopupMenu();
  193. var idx;
  194. if(window.GetProperty("mode") == 101) {
  195. _menu.AppendMenuItem(g_metadb ? MF_STRING : MF_GRAYED, 11, "Download artist art from Last.fm");
  196. _lastfm_options.AppendMenuItem(MF_STRING, 1000, "Automatically download");
  197. _lastfm_options.CheckMenuItem(1000, window.GetProperty("auto"));
  198. _limit.AppendMenuItem(MF_STRING, 301, "1");
  199. _limit.AppendMenuItem(MF_STRING, 303, "3");
  200. _limit.AppendMenuItem(MF_STRING, 305, "5");
  201. _limit.AppendMenuItem(MF_STRING, 310, "10");
  202. _limit.AppendMenuItem(MF_STRING, 320, "20");
  203. _limit.CheckMenuRadioItem(301, 320, window.GetProperty("limit"));
  204. _lastfm_options.AppendMenuItem(MF_STRING | MF_POPUP, _limit.ID, "Limit");
  205. _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
  206. _lastfm_options.AppendMenuItem(MF_STRING, 1001, "Blacklist deleted images");
  207. _lastfm_options.CheckMenuItem(1001, window.GetProperty("bl"));
  208. _lastfm_options.AppendMenuItem(fso.FileExists(blacklist_file) ? MF_STRING : MF_GRAYED, 1002, "Clear blacklist for this artist");
  209. _lastfm_options.AppendMenuItem(MF_SEPARATOR, 0, 0);
  210. _lastfm_options.AppendMenuItem(MF_STRING, 1003, "Explain blacklisting");
  211. _menu.AppendMenuItem(MF_STRING | MF_POPUP, _lastfm_options.ID, "Last.fm options");
  212. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  213. }
  214. _thumb.AppendMenuItem(MF_STRING, 1075, "75px");
  215. _thumb.AppendMenuItem(MF_STRING, 1100, "100px");
  216. _thumb.AppendMenuItem(MF_STRING, 1150, "150px");
  217. _thumb.AppendMenuItem(MF_STRING, 1200, "200px");
  218. _thumb.AppendMenuItem(MF_SEPARATOR, 0, 0);
  219. _thumb.AppendMenuItem(MF_STRING, 2000, "Square");
  220. _thumb.CheckMenuItem(2000, square);
  221. _thumb.CheckMenuRadioItem(1075, 1200, window.GetProperty("thumb_size") + 1000);
  222. _menu.AppendMenuItem(MF_STRING | MF_POPUP, _thumb.ID, "Thumbnails");
  223. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  224. _cycle.AppendMenuItem(MF_STRING, 200, "Off");
  225. _cycle.AppendMenuItem(MF_STRING, 205, "5 seconds");
  226. _cycle.AppendMenuItem(MF_STRING, 210, "10 seconds");
  227. _cycle.AppendMenuItem(MF_STRING, 220, "20 seconds");
  228. _cycle.CheckMenuRadioItem(200, 220, window.GetProperty("cycle"));
  229. _menu.AppendMenuItem(MF_STRING | MF_POPUP, _cycle.ID, "Cycle");
  230. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  231. _menu.AppendMenuItem(g_metadb && fso.FolderExists(folder) ? MF_STRING : MF_GRAYED, 12, "Open containing folder");
  232. if(g_img.length > 0 && y < wh - 40 - thumb_size) _menu.AppendMenuItem(MF_STRING, 15, "Delete this image");
  233. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  234. _mode.AppendMenuItem(MF_STRING, 101, "Last.fm Artist Art");
  235. _mode.AppendMenuItem(MF_STRING, 102, "Custom Folder");
  236. _mode.AppendMenuItem(MF_SEPARATOR, 0, 0);
  237. _mode.CheckMenuRadioItem(101, 102, window.GetProperty("mode"));
  238. _mode.AppendMenuItem(window.GetProperty("mode") == 102 ? MF_STRING : MF_GRAYED, 21, "Set Custom Folder....");
  239. _menu.AppendMenuItem(MF_STRING | MF_POPUP, _mode.ID, "Mode");
  240. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  241. _menu.AppendMenuItem(MF_STRING | MF_POPUP, _selection.ID, "Selection mode");
  242. _selection.AppendMenuItem(MF_STRING, 900, "Use display preferences");
  243. _selection.AppendMenuItem(MF_STRING, 901, "Prefer now playing");
  244. _selection.AppendMenuItem(MF_STRING, 902, "Follow selected track");
  245. _selection.CheckMenuRadioItem(900, 903, selection_mode + 900);
  246. _menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
  247. if(utils.IsKeyPressed(0x10)) _menu.AppendMenuItem(MF_STRING, 99, "Properties");
  248. _menu.AppendMenuItem(MF_STRING, 100, "Configure...");
  249. idx = _menu.TrackPopupMenu(x, y);
  250. switch(idx) {
  251. case 101:
  252. case 102:
  253. window.SetProperty("mode", idx);
  254. update_image();
  255. break;
  256. case 200:
  257. case 205:
  258. case 210:
  259. case 220:
  260. window.SetProperty("cycle", idx);
  261. cycle = idx - 200;
  262. break;
  263. case 301:
  264. case 303:
  265. case 305:
  266. case 310:
  267. case 320:
  268. window.SetProperty("limit", idx);
  269. limit = idx - 300;
  270. break;
  271. case 11:
  272. download_images();
  273. break;
  274. case 12:
  275. try { WshShell.Run("explorer \"" + folder + "\""); } catch(e) {}
  276. break;
  277. case 15:
  278. clear_cache();
  279. try {
  280. if(window.GetProperty("mode") == 101 && window.GetProperty("bl") == true) {
  281. ts = fso.OpenTextFile(blacklist_file, 2, true, -1);
  282. ts.WriteLine(blacklist + arr[index] + "|") ;
  283. ts.close();
  284. }
  285. fso.DeleteFile(arr[index]);
  286. } catch(e) {
  287. fb.trace("Error: Could not delete " + arr[index]);
  288. }
  289. update_image();
  290. break;
  291. case 21:
  292. cycle_tf = text_input_box("Thumbs2", "Enter title formatting or an absolute path to a folder.\n\nYou can specify multiple folders using | as a separator.", cycle_tf_file);
  293. update_image();
  294. break;
  295. case 99:
  296. window.ShowProperties();
  297. break;
  298. case 100:
  299. window.ShowConfigure();
  300. break;
  301. case 1000:
  302. window.SetProperty("auto", !window.GetProperty("auto"));
  303. break;
  304. case 1001:
  305. window.SetProperty("bl", !window.GetProperty("bl"));
  306. break;
  307. case 1002:
  308. try { fso.DeleteFile(blacklist_file); } catch(e) {}
  309. break;
  310. case 1003:
  311. fb.ShowPopupMessage("When you delete an image, there is no way for this script to prevent it being downloaded again. As a workaround, you can \"blacklist\" images you don't want and they will be deleted after downloading is complete.", "Thumbs2");
  312. break;
  313. case 1075:
  314. case 1100:
  315. case 1150:
  316. case 1200:
  317. window.SetProperty("thumb_size", idx -1000);
  318. thumb_size = window.GetProperty("thumb_size");
  319. columns = Math.floor((ww - 50) / (thumb_size + 10));
  320. offset = 0;
  321. window.Repaint();
  322. break;
  323. case 2000:
  324. window.SetProperty("square",!square);
  325. square = window.GetProperty("square");
  326. window.Repaint();
  327. break;
  328. case 900:
  329. case 901:
  330. case 902:
  331. window.SetProperty("selection_mode", idx - 900);
  332. selection_mode = window.GetProperty("selection_mode");
  333. on_item_focus_change();
  334. break;
  335. }
  336. _selection.Dispose();
  337. _mode.Dispose();
  338. _limit.Dispose();
  339. _lastfm_options.Dispose();
  340. _thumb.Dispose();
  341. _cycle.Dispose();
  342. _menu.Dispose();
  343. return true;
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement