1
0

fillbar.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * fillbar.m
  3. *
  4. * Manages custom fillbars.
  5. *
  6. * @package com.winamp.maki.lib.community.fillbar
  7. * @author mpdeimos
  8. * @date 08/10/01
  9. * @version 1.0
  10. */
  11. #ifndef included
  12. #error This script can only be compiled as a #include
  13. #endif
  14. Class Layer FillBar;
  15. // {
  16. Member Map FillBar.fillmap;
  17. Member int FillBar.pos;
  18. Member boolean Fillbar.reverse;
  19. // User dragging stuff
  20. Member boolean Fillbar.dragable;
  21. Member boolean Fillbar.dragging;
  22. /**
  23. * constructor
  24. *
  25. * @param layer that should be handled like a fillbar
  26. * @param bitmapID that should be used as region map
  27. * @ret FillBar object
  28. */
  29. Function FillBar FillBar_construct(Layer l, String bitmapID);
  30. Function FillBar_setMap(FillBar fb, String bitmapID);
  31. /**
  32. * destructor, always call on script unloading
  33. *
  34. */
  35. Function FillBar_destruct(FillBar fb);
  36. /**
  37. * sets the region
  38. *
  39. * @param fillbar to act on
  40. * @param threshold of the map to generate a region
  41. */
  42. Function FillBar_setPosition(FillBar fb, int threshold);
  43. /**
  44. * called each time the users drags the fillbar
  45. *
  46. * @param The dragged FillBar
  47. * @param The alue the FillBar was dragged to.
  48. * @ret FALSE if you do not want to allow dragging.
  49. */
  50. Function boolean FillBar_onDrag(FillBar fb, int pos);
  51. /*
  52. * called each time the users ends dragging the fillbar
  53. *
  54. * @param The dragged FillBar
  55. * @param The alue the FillBar was dragged to.
  56. * @ret FALSE if you do not want to allow dragging.
  57. */
  58. Function boolean FillBar_onEndDrag(FillBar fb, int pos);
  59. /*
  60. * IMPLEMENTATION
  61. */
  62. FillBar FillBar_construct(Layer l, String bitmapID)
  63. {
  64. FillBar fb = l;
  65. fb.reverse = TRUE;
  66. fb.fillmap = new Map;
  67. fb.fillmap.loadMap(bitmapID);
  68. return fb;
  69. }
  70. FillBar_setMap(Fillbar fb, String bitmapID)
  71. {
  72. if (fb.fillmap != NULL)
  73. {
  74. delete fb.fillmap;
  75. }
  76. fb.fillmap = new Map;
  77. fb.fillmap.loadMap(bitmapID);
  78. }
  79. FillBar_destruct(FillBar fb)
  80. {
  81. Map tmp = fb.fillmap;
  82. delete tmp;
  83. }
  84. FillBar_setPosition(FillBar fb, int threshold)
  85. {
  86. fb.pos = threshold;
  87. fb.setRegionFromMap(fb.fillmap, threshold, fb.reverse);
  88. }
  89. // User dragging handles
  90. FillBar.onLeftButtonDown (int x, int y)
  91. {
  92. if (!FillBar.dragable)
  93. {
  94. return;
  95. }
  96. Fillbar.dragging = TRUE;
  97. }
  98. FillBar.onMouseMove (int x, int y)
  99. {
  100. if (!FillBar.dragable || !Fillbar.dragging)
  101. {
  102. return;
  103. }
  104. int mouseLeft = x - FillBar.getLeft();
  105. int mouseTop = y - Fillbar.getTop();
  106. if (!FillBar.fillMap.inRegion(mouseLeft, mouseTop))
  107. {
  108. return;
  109. }
  110. int position = FillBar.fillMap.getValue(mouseLeft, mouseTop);
  111. int update = FillBar_onDrag(FillBar, position);
  112. if (update)
  113. {
  114. FillBar_setPosition(FillBar, position);
  115. }
  116. }
  117. Fillbar.onLeftButtonUp (int x, int y)
  118. {
  119. if (!FillBar.dragable || !Fillbar.dragging)
  120. {
  121. return;
  122. }
  123. int mouseLeft = x - FillBar.getLeft();
  124. int mouseTop = y - Fillbar.getTop();
  125. int position = FillBar.fillMap.getValue(mouseLeft, mouseTop);
  126. if (!FillBar.fillMap.inRegion(mouseLeft, mouseTop))
  127. {
  128. position = fb.pos;
  129. }
  130. int update = FillBar_onEndDrag(FillBar, position);
  131. if (update)
  132. {
  133. FillBar_setPosition(FillBar, position);
  134. }
  135. Fillbar.dragging = FALSE;
  136. }
  137. // Callback Stubs
  138. boolean FillBar_onDrag(Fillbar fb, int pos) { return TRUE; }
  139. boolean FillBar_onEndDrag(Fillbar fb, int pos) { return TRUE; }
  140. // }