home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Util / Winamp / Skins / Anime_Shogo.wal / scripts / eqbyregion.m < prev    next >
Text File  |  2004-08-17  |  7KB  |  303 lines

  1. //-----------------------------------------------------------------------------
  2. // eqbyregion.m
  3. //
  4. // Example of Animated EQ bars using Regions
  5. //
  6. // written by FrisbeeMonkey
  7. //-----------------------------------------------------------------------------
  8.  
  9. // Never forget to include std.mi
  10. #include "../../../lib/std.mi"
  11.  
  12. // Declare local functions for use in script
  13. Function setEqAnim(int eqValue, Layer eqName);
  14. Function updateEqBand(Layer eqName, int eqNum, int x, int y);
  15.  
  16. // Declare global variables for use in script
  17. Global Layer EQPreamp, eq0, eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9;
  18. Global Map eqMap;
  19. Global Boolean eqChanging;
  20.  
  21. // When the script/skin is loaded, do this
  22. System.onScriptLoaded() {
  23.     Group eqLayout = getScriptGroup();
  24.  
  25.     //get Layers
  26.     EQPreamp = eqLayout.findObject("EQPreamp");
  27.     eq0 = eqLayout.findObject("EQBar0");
  28.     eq1 = eqLayout.findObject("EQBar1");
  29.     eq2 = eqLayout.findObject("EQBar2");
  30.     eq3 = eqLayout.findObject("EQBar3");
  31.     eq4 = eqLayout.findObject("EQBar4");
  32.     eq5 = eqLayout.findObject("EQBar5");
  33.     eq6 = eqLayout.findObject("EQBar6");
  34.     eq7 = eqLayout.findObject("EQBar7");
  35.     eq8 = eqLayout.findObject("EQBar8");
  36.     eq9 = eqLayout.findObject("EQBar9");
  37.  
  38.     //initialize Map
  39.     EQMap = new Map;
  40.     EQMap.loadMap("eq.bar.map");
  41.  
  42.     //initialize Band positions
  43.     setEqAnim(128 - System.getEqPreamp(), EQPreamp);
  44.     setEqAnim(128 - System.getEqBand(0), eq0);
  45.     setEqAnim(128 - System.getEqBand(1), eq1);
  46.     setEqAnim(128 - System.getEqBand(2), eq2);
  47.     setEqAnim(128 - System.getEqBand(3), eq3);
  48.     setEqAnim(128 - System.getEqBand(4), eq4);
  49.     setEqAnim(128 - System.getEqBand(5), eq5);
  50.     setEqAnim(128 - System.getEqBand(6), eq6);
  51.     setEqAnim(128 - System.getEqBand(7), eq7);
  52.     setEqAnim(128 - System.getEqBand(8), eq8);
  53.     setEqAnim(128 - System.getEqBand(9), eq9);
  54. }
  55.  
  56. //handles changes on Preamp(from Presets, etc)
  57. System.onEqPreampChanged(int newValue) {
  58.     setEqAnim(128 - newValue, EQPreamp);
  59. }
  60.  
  61. //handles changes on Bands(from Presets, etc)
  62. System.onEqBandChanged(int band, int newValue) {
  63.     if (band == 0) {
  64.         setEqAnim(128 - newValue, eq0);
  65.     } else if (band == 1) {
  66.         setEqAnim(128 - newValue, eq1);
  67.     } else if (band == 2) {
  68.         setEqAnim(128 - newValue, eq2);
  69.     } else if (band == 3) {
  70.         setEqAnim(128 - newValue, eq3);
  71.     } else if (band == 4) {
  72.         setEqAnim(128 - newValue, eq4);
  73.     } else if (band == 5) {
  74.         setEqAnim(128 - newValue, eq5);
  75.     } else if (band == 6) {
  76.         setEqAnim(128 - newValue, eq6);
  77.     } else if (band == 7) {
  78.         setEqAnim(128 - newValue, eq7);
  79.     } else if (band == 8) {
  80.         setEqAnim(128 - newValue, eq8);
  81.     } else if (band == 9) {
  82.         setEqAnim(128 - newValue, eq9);
  83.     }
  84. }
  85.  
  86. // Sets Region to Display Partial Bar
  87. setEqAnim(int eqValue, Layer eqName) {
  88.     Region r = new Region;
  89.     r.loadFromMap(EQMap, eqValue, 0);
  90.     eqName.setRegion(r);
  91.     delete r;
  92. }
  93.  
  94. // Handles Preamp Mouse Events
  95. eqPreamp.onLeftButtonDown(int x, int y) {
  96.     updateEQBand(eqPreamp, 10, x, y);
  97.     EqChanging = 1;
  98. }
  99. eqPreamp.onLeftButtonUp(int x, int y) {
  100.     if (EQChanging) {
  101.         EQChanging = 0;
  102.     }
  103. }
  104. eqPreamp.onMouseMove(int x, int y) {
  105.     if (EQChanging) {
  106.         updateEQBand(eqPreamp, 10, x, y);
  107.     }
  108. }
  109.  
  110. // Handles Band 0 Mouse Events
  111. eq0.onLeftButtonDown(int x, int y) {
  112.     updateEQBand(eq0, 0, x, y);
  113.     EqChanging = 1;
  114. }
  115. eq0.onLeftButtonUp(int x, int y) {
  116.     if (EQChanging) {
  117.         EQChanging = 0;
  118.     }
  119. }
  120. eq0.onMouseMove(int x, int y) {
  121.     if (EQChanging) {
  122.         updateEQBand(eq0, 0, x, y);
  123.     }
  124. }
  125.  
  126. // Handles Band 1 Mouse Events
  127. eq1.onLeftButtonDown(int x, int y) {
  128.     updateEQBand(eq1, 1, x, y);
  129.     EqChanging = 1;
  130. }
  131. eq1.onLeftButtonUp(int x, int y) {
  132.     if (EQChanging) {
  133.         EQChanging = 0;
  134.     }
  135. }
  136. eq1.onMouseMove(int x, int y) {
  137.     if (EQChanging) {
  138.         updateEQBand(eq1, 1, x, y);
  139.     }
  140. }
  141.  
  142. // Handles Band 2 Mouse Events
  143. eq2.onLeftButtonDown(int x, int y) {
  144.     updateEQBand(eq2, 2, x, y);
  145.     EqChanging = 1;
  146. }
  147. eq2.onLeftButtonUp(int x, int y) {
  148.     if (EQChanging) {
  149.         EQChanging = 0;
  150.     }
  151. }
  152. eq2.onMouseMove(int x, int y) {
  153.     if (EQChanging) {
  154.         updateEQBand(eq2, 2, x, y);
  155.     }
  156. }
  157.  
  158. // Handles Band 3 Mouse Events
  159. eq3.onLeftButtonDown(int x, int y) {
  160.     updateEQBand(eq3, 3, x, y);
  161.     EqChanging = 1;
  162. }
  163. eq3.onLeftButtonUp(int x, int y) {
  164.     if (EQChanging) {
  165.         EQChanging = 0;
  166.     }
  167. }
  168. eq3.onMouseMove(int x, int y) {
  169.     if (EQChanging) {
  170.         updateEQBand(eq3, 3, x, y);
  171.     }
  172. }
  173.  
  174. // Handles Band 4 Mouse Events
  175. eq4.onLeftButtonDown(int x, int y) {
  176.     updateEQBand(eq4, 4, x, y);
  177.     EqChanging = 1;
  178. }
  179. eq4.onLeftButtonUp(int x, int y) {
  180.     if (EQChanging) {
  181.         EQChanging = 0;
  182.     }
  183. }
  184. eq4.onMouseMove(int x, int y) {
  185.     if (EQChanging) {
  186.         updateEQBand(eq4, 4, x, y);
  187.     }
  188. }
  189.  
  190. // Handles Band 5 Mouse Events
  191. eq5.onLeftButtonDown(int x, int y) {
  192.     updateEQBand(eq5, 5, x, y);
  193.     EqChanging = 1;
  194. }
  195. eq5.onLeftButtonUp(int x, int y) {
  196.     if (EQChanging) {
  197.         EQChanging = 0;
  198.     }
  199. }
  200. eq5.onMouseMove(int x, int y) {
  201.     if (EQChanging) {
  202.         updateEQBand(eq5, 5, x, y);
  203.     }
  204. }
  205.  
  206. // Handles Band 6 Mouse Events
  207. eq6.onLeftButtonDown(int x, int y) {
  208.     updateEQBand(eq6, 6, x, y);
  209.     EqChanging = 1;
  210. }
  211. eq6.onLeftButtonUp(int x, int y) {
  212.     if (EQChanging) {
  213.         EQChanging = 0;
  214.     }
  215. }
  216. eq6.onMouseMove(int x, int y) {
  217.     if (EQChanging) {
  218.         updateEQBand(eq6, 6, x, y);
  219.     }
  220. }
  221.  
  222. // Handles Band 7 Mouse Events
  223. eq7.onLeftButtonDown(int x, int y) {
  224.     updateEQBand(eq7, 7, x, y);
  225.     EqChanging = 1;
  226. }
  227. eq7.onLeftButtonUp(int x, int y) {
  228.     if (EQChanging) {
  229.         EQChanging = 0;
  230.     }
  231. }
  232. eq7.onMouseMove(int x, int y) {
  233.     if (EQChanging) {
  234.         updateEQBand(eq7, 7, x, y);
  235.     }
  236. }
  237.  
  238. // Handles Band 8 Mouse Events
  239. eq8.onLeftButtonDown(int x, int y) {
  240.     updateEQBand(eq8, 8, x, y);
  241.     EqChanging = 1;
  242. }
  243. eq8.onLeftButtonUp(int x, int y) {
  244.     if (EQChanging) {
  245.         EQChanging = 0;
  246.     }
  247. }
  248. eq8.onMouseMove(int x, int y) {
  249.     if (EQChanging) {
  250.         updateEQBand(eq8, 8, x, y);
  251.     }
  252. }
  253.  
  254. // Handles Band 9 Mouse Events
  255. eq9.onLeftButtonDown(int x, int y) {
  256.     updateEQBand(eq9, 9, x, y);
  257.     EqChanging = 1;
  258. }
  259. eq9.onLeftButtonUp(int x, int y) {
  260.     if (EQChanging) {
  261.         EQChanging = 0;
  262.     }
  263. }
  264. eq9.onMouseMove(int x, int y) {
  265.     if (EQChanging) {
  266.         updateEQBand(eq9, 9, x, y);
  267.     }
  268. }
  269.  
  270.  
  271. // Updates EQ Band Image and System Value
  272. updateEQBand(Layer eqName, int eqNum, int x, int y) {
  273.     int newValue = eqMap.getValue(x - eqName.getLeft(), y - eqName.getTop());
  274.     newValue = 128 - newValue;
  275.     if (eqNum == 0) {
  276.         System.setEqBand(0, newValue);
  277.     } else if (eqNum == 1) {
  278.         System.setEqBand(1, newValue);
  279.     } else if (eqNum == 2) {
  280.         System.setEqBand(2, newValue);
  281.     } else if (eqNum == 3) {
  282.         System.setEqBand(3, newValue);
  283.     } else if (eqNum == 4) {
  284.         System.setEqBand(4, newValue);
  285.     } else if (eqNum == 5) {
  286.         System.setEqBand(5, newValue);
  287.     } else if (eqNum == 6) {
  288.         System.setEqBand(6, newValue);
  289.     } else if (eqNum == 7) {
  290.         System.setEqBand(7, newValue);
  291.     } else if (eqNum == 8) {
  292.         System.setEqBand(8, newValue);
  293.     } else if (eqNum == 9) {
  294.         System.setEqBand(9, newValue);
  295.     } else if (eqNum == 10) {
  296.         System.setEqPreamp(newValue);
  297.     }
  298. }
  299.  
  300. System.onScriptUnloading() {
  301.     delete eqMap;
  302. }
  303.