glowobject.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * glowobject.m
  3. *
  4. * @package com.winamp.maki.lib.community.glowobject
  5. * @author mpdeimos
  6. * @date 18/10/01
  7. * @version 1.0
  8. */
  9. #ifndef included
  10. #error This script can only be compiled as a #include
  11. #endif
  12. #define GLOW_TYPE_HOLD 0
  13. #define GLOW_TYPE_FLASH 1
  14. #define GLOW_TYPE_BOUNCE 2
  15. Class GuiObject GlowLayer;
  16. // {
  17. Member GuiObject GlowLayer.trigger;
  18. // }
  19. Class GuiObject GlowObject;
  20. // {
  21. Member float GlowObject.fadeInSpeed;
  22. Member float GlowObject.fadeOutSpeed;
  23. Member int GlowObject.glowType;
  24. Member boolean GlowObject.glowing;
  25. Member GuiObject GlowObject.glow;
  26. /**
  27. * constructor
  28. *
  29. * @param GuiObject that will be used to trigger the glow on mouse entering it's region
  30. * @param the glowing object
  31. * @ret GlowObject object
  32. */
  33. Function GlowObject GlowObject_construct(GlowObject trigger, GlowLayer glow);
  34. /**
  35. * sets fade in time
  36. *
  37. * @param GlowObject to act on
  38. * @param milliseconds till the glow is at alpha 255
  39. */
  40. Function GlowObject_setFadeInSpeed(GlowObject go, float ms);
  41. /**
  42. * sets fade out time
  43. *
  44. * @param GlowObject to act on
  45. * @param milliseconds till the glow is at alpha 0
  46. */
  47. Function GlowObject_setFadeOutSpeed(GlowObject go, float ms);
  48. /**
  49. * sets the glowtype used by this glow button.
  50. *
  51. * @param GlowObject to act on
  52. * @param glowType defined via GLOW_TYPE_*
  53. */
  54. Function GlowObject_setGlowType(GlowObject go, int glowType);
  55. /*
  56. * IMPLEMENTATION
  57. */
  58. GlowObject GlowObject_construct(GlowObject trigger, GlowLayer glow)
  59. {
  60. if (trigger == null)
  61. {
  62. debug("trigger");
  63. }
  64. if (glow == NULL)
  65. {
  66. debug("glow");
  67. }
  68. GlowObject go = trigger;
  69. go.fadeInSpeed = 0.3;
  70. go.fadeOutSpeed = 0.5;
  71. go.glow = glow;
  72. go.glowType = GLOW_TYPE_HOLD;
  73. go.glowing = false;
  74. glow.trigger = trigger;
  75. return go;
  76. }
  77. GlowObject_setFadeInSpeed(GlowObject go, float ms)
  78. {
  79. go.fadeInSpeed = ms;
  80. }
  81. GlowObject_setFadeOutSpeed(GlowObject go, float ms)
  82. {
  83. go.fadeOutSpeed = ms;
  84. }
  85. GlowObject_setGlowType(GlowObject go, int glowType)
  86. {
  87. go.glowType = glowType;
  88. }
  89. GlowObject.onEnterArea ()
  90. {
  91. GlowObject.glowing = true;
  92. GlowObject.glow.cancelTarget();
  93. GlowObject.glow.setTargetA(255);
  94. GlowObject.glow.setTargetSpeed(GlowObject.fadeInSpeed);
  95. GlowObject.glow.gotoTarget();
  96. }
  97. GlowObject.onLeaveArea ()
  98. {
  99. GlowObject.glowing = false;
  100. if (GlowObject.glowType != GLOW_TYPE_FLASH)
  101. {
  102. GlowObject.glow.cancelTarget();
  103. GlowObject.glow.setTargetA(0);
  104. GlowObject.glow.setTargetSpeed(GlowObject.fadeOutSpeed);
  105. GlowObject.glow.gotoTarget();
  106. }
  107. }
  108. GlowLayer.onTargetReached ()
  109. {
  110. GlowObject go = GlowLayer.trigger;
  111. if (go.glowType == GLOW_TYPE_HOLD)
  112. {
  113. return;
  114. }
  115. else if (go.glowType == GLOW_TYPE_FLASH)
  116. {
  117. if (GlowLayer.getAlpha() == 255)
  118. {
  119. GlowLayer.cancelTarget();
  120. GlowLayer.setTargetA(0);
  121. GlowLayer.setTargetSpeed(GlowObject.fadeOutSpeed);
  122. GlowLayer.gotoTarget();
  123. }
  124. }
  125. else if (go.glowType == GLOW_TYPE_BOUNCE)
  126. {
  127. if (GlowLayer.getAlpha() == 255)
  128. {
  129. GlowLayer.cancelTarget();
  130. GlowLayer.setTargetA(0);
  131. GlowLayer.setTargetSpeed(GlowObject.fadeOutSpeed);
  132. GlowLayer.gotoTarget();
  133. }
  134. else if (GlowLayer.getAlpha() == 0 && go.glowing)
  135. {
  136. GlowLayer.cancelTarget();
  137. GlowLayer.setTargetA(255);
  138. GlowLayer.setTargetSpeed(GlowObject.fadeInSpeed);
  139. GlowLayer.gotoTarget();
  140. }
  141. }
  142. }
  143. GlowObject.onSetVisible (Boolean onoff)
  144. {
  145. if (onoff)
  146. {
  147. GlowObject.glow.show();
  148. }
  149. else
  150. {
  151. GlowObject.glow.hide();
  152. }
  153. }
  154. // }