videoresize.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /********************************************************\
  2. ** Filename: videoresize.m **
  3. ** Version: 1.0 **
  4. ** Date: 23. Jan. 2008 - 11:23 **
  5. **********************************************************
  6. ** Type: winamp.wasabi/maki **
  7. ** Project: Bento **
  8. **********************************************************
  9. ** Author: Martin Poehlmann aka Deimos **
  10. ** E-Mail: [email protected] **
  11. ** Internet: http://www.skinconsortium.com **
  12. ** http://home.cs.tum.edu/~poehlman **
  13. \********************************************************/
  14. #include <lib/std.mi>
  15. #include attribs/init_Autoresize.m
  16. Function adjust(int x, int y);
  17. Function fade(GuiObject o, int a);
  18. Class GuiObject Mousetrap;
  19. Global Mousetrap resizer;
  20. Global Mousetrap wdh, outer, bg;
  21. Global Group sg;
  22. Global Int sx, sy, ox, oy, dx, dy;
  23. Global Boolean move;
  24. Global Timer refresh;
  25. System.onScriptLoaded ()
  26. {
  27. initAttribs_Autoresize();
  28. sg = getScriptGroup();
  29. wdh = sg.getObject("wdh");
  30. resizer = sg.getObject("wdh.drag");
  31. outer = sg.getObject("wdh.outer");
  32. bg = sg.getObject("bg");
  33. refresh = new Timer;
  34. refresh.setDelay(133);
  35. video_inframe_attrib.onDataChanged ();
  36. }
  37. System.onScriptUnloading ()
  38. {
  39. refresh.stop();
  40. delete refresh;
  41. }
  42. resizer.onLeftButtonDown (int x, int y)
  43. {
  44. move = true;
  45. sx = x;
  46. sy = y;
  47. ox = wdh.getGuiX();
  48. oy = wdh.getGuiY();
  49. refresh.start();
  50. }
  51. resizer.onLeftButtonUp (int x, int y)
  52. {
  53. move = false;
  54. refresh.stop();
  55. }
  56. resizer.onMouseMove (int x, int y)
  57. {
  58. if (!move) return;
  59. dx = sx - x;
  60. dy = sy - y;
  61. }
  62. // handle the resizing with a timer in order to prevent jittering
  63. refresh.onTimer ()
  64. {
  65. adjust(dx, dy);
  66. }
  67. adjust (int x, int y)
  68. {
  69. int nx = ox + x;
  70. int ny = oy + y;
  71. // Ensure we don't get out of the bounds
  72. if (nx < 5)
  73. {
  74. nx = 5;
  75. }
  76. if (ny < 5)
  77. {
  78. ny = 5;
  79. }
  80. // Minimum h/w: aligned with Nullsoft Video Symbol
  81. if (sg.getHeight() - 2*ny < 64)
  82. {
  83. ny = (64 - sg.getHeight())/(-2);
  84. }
  85. if (sg.getWidth() - 2*nx < 100)
  86. {
  87. nx = (100 - sg.getWidth())/(-2);
  88. }
  89. outer.setXmlParam("x", integerToString(nx-1));
  90. outer.setXmlParam("w", integerToString(-2*(nx-1)));
  91. outer.setXmlParam("y", integerToString(ny-1));
  92. outer.setXmlParam("h", integerToString(-2*(ny-1)));
  93. wdh.setXmlParam("x", integerToString(nx));
  94. wdh.setXmlParam("w", integerToString(-(2*nx)));
  95. wdh.setXmlParam("y", integerToString(ny));
  96. wdh.setXmlParam("h", integerToString(-(2*ny)));
  97. resizer.setXmlParam("x", integerToString(-nx));
  98. resizer.setXmlParam("y", integerToString(-ny));
  99. }
  100. video_inframe_attrib.onDataChanged ()
  101. {
  102. if (getData() == "1")
  103. {
  104. outer.show();
  105. resizer.show();
  106. outer.setXmlParam("x", integerToString(4));
  107. outer.setXmlParam("w", integerToString(-8));
  108. outer.setXmlParam("y", integerToString(4));
  109. outer.setXmlParam("h", integerToString(-8));
  110. wdh.setXmlParam("x", integerToString(5));
  111. wdh.setXmlParam("w", integerToString(-10));
  112. wdh.setXmlParam("y", integerToString(5));
  113. wdh.setXmlParam("h", integerToString(-10));
  114. resizer.setXmlParam("x", integerToString(-5));
  115. resizer.setXmlParam("y", integerToString(-5));
  116. }
  117. else
  118. {
  119. outer.hide();
  120. resizer.hide();
  121. wdh.setXmlParam("x", integerToString(0));
  122. wdh.setXmlParam("w", integerToString(0));
  123. wdh.setXmlParam("y", integerToString(0));
  124. wdh.setXmlParam("h", integerToString(0));
  125. }
  126. }
  127. /*
  128. Mousetrap.onEnterArea ()
  129. {
  130. if (outer.getAlpha() == 255) return;
  131. if (video_inframe_attrib.getData() == "1")
  132. {
  133. fade(outer, 255);
  134. fade(resizer, 255);
  135. }
  136. }
  137. Mousetrap.onLeaveArea ()
  138. {
  139. if (move) return;
  140. for ( int i = 0; i < sg.getNumObjects(); i++ )
  141. {
  142. if (sg.enumObject(i).isMouseOver(getMousePosX(), getMousePosY())) return;
  143. }
  144. if (video_inframe_attrib.getData() == "1")
  145. {
  146. fade(outer, 0);
  147. fade(resizer, 0);
  148. }
  149. }
  150. fade (GuiObject o, int a)
  151. {
  152. o.cancelTarget();
  153. o.setTargetX(o.getGuiX());
  154. o.setTargetY(o.getGuiY());
  155. o.setTargetH(o.getGuiH());
  156. o.setTargetW(o.getGuiW());
  157. o.setTargetA(a);
  158. o.setTargetSpeed(0.3);
  159. o.gotoTarget();
  160. }*/