home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2004 March / PCNET_CD_2004_04_3.iso / skin / winamp / Devay.wal / scripts / AutoRepeatButton.m < prev    next >
Encoding:
Text File  |  2003-03-31  |  3.4 KB  |  101 lines

  1. //--------------------------------------------------------------------------------------------------
  2. // AutoRepeatButton.m   Orginal Code By Will Fisher, Concept By Eric Moore, Rewritten By Will Fisher
  3. //
  4. // Use like this:
  5. // #include </lib/AutoRepeatButton.m>
  6. // Global AutoRepeatButton MyButton, MyOtherButton; 
  7. // 
  8. // Fill in the buttons function into MyButton.OnLeftClick() as normal.
  9. //
  10. // Use AutoRepeat_ClickType to find the type of call to MyButton.onLeftClick() where
  11. //   AutoRepeat_ClickType==1 is the first call to onLeftClick
  12. //   AutoRepeat_ClickType==2 is a subsequent call to onLeftClick
  13. //   AutoRepeat_ClickType==0 is an erronious call to onLeftClick, you should usually ignore
  14. //                           MyButton.onLeftClick() in this case
  15. // See other functions below:
  16. //--------------------------------------------------------------------------------------------------
  17.  
  18. Function AutoRepeat_Load(); // ALWAYS call this in System.OnScriptLoaded()
  19. Function AutoRepeat_Unload(); // ALWAYS call this in System.OnScriptUnloading()
  20. Function AutoRepeat_Stop();  // stop the current button from autorepeating
  21.  
  22. Function Button AutoRepeat_GetCurrentButton(); /* returns the currently autorepeating button,
  23.                                                   returns NULL if no button is autorepeating */
  24.  
  25. Function AutoRepeat_SetInitalDelay(int millis);  /* set this for the first delay when the button is 
  26.                                                     pressed, defaults to 800ms (no need to use this
  27.                                                     unless other delay is required) */ 
  28.                                                  
  29. Function AutoRepeat_SetRepeatDelay(int millis);  /* set this for the subsequent delay, defaults to
  30.                                                     80ms (no need to use this unless other delay is
  31.                                                     required) */
  32.  
  33. Function Int AutoRepeat_GetInitalDelay();  // get the first delay length in millisecs 
  34. Function Int AutoRepeat_GetRepeatDelay();  // get the subsequent delay in millisecs
  35.  
  36. Class Button AutoRepeatButton;
  37.  
  38. Global Timer _autorepeatTimer;
  39. Global Int _InitialDelay;
  40. Global Int _RepeatDelay;
  41. Global Int AutoRepeat_ClickType;
  42. Global Button _Latched;
  43.  
  44. AutoRepeatButton.onLeftButtonDown(int x, int y) {
  45.   _Latched = AutoRepeatButton;
  46.   AutoRepeat_ClickType = 1; // first click
  47.   AutoRepeatButton.leftClick();
  48.   AutoRepeat_ClickType = 0; // no click
  49.   _autorepeatTimer.setDelay(_InitialDelay);
  50.   _autorepeatTimer.start();
  51. }
  52.  
  53. AutoRepeatButton.onLeftButtonUp(int x, int y) {
  54.   _AutoRepeatTimer.Stop();
  55.   _Latched = NULL;
  56. }
  57.  
  58. _AutoRepeatTimer.onTimer() {
  59.   if(_autorepeatTimer.getDelay() != _RepeatDelay) _autorepeatTimer.setDelay(_RepeatDelay);
  60.   AutoRepeat_ClickType = 2; // AutoRepeat
  61.   _Latched.LeftClick();
  62.   AutoRepeat_ClickType = 0; // no click
  63. }
  64.  
  65. AutoRepeat_Load() {
  66.   _autoRepeatTimer = new Timer;
  67.   _InitialDelay = 100;
  68.   _RepeatDelay = 50;
  69.   AutoRepeat_ClickType = 0;
  70. }
  71.  
  72. AutoRepeat_Unload() {
  73.   delete _autoRepeatTimer;
  74. }
  75.  
  76. AutoRepeat_SetInitalDelay(int millis) {
  77.   _InitialDelay = millis;
  78. }
  79.  
  80.  
  81. AutoRepeat_SetRepeatDelay(int millis) {
  82.   _RepeatDelay = millis;
  83. }
  84.  
  85. AutoRepeat_GetInitalDelay() {
  86.   return _InitialDelay;
  87. }
  88.  
  89. AutoRepeat_GetRepeatDelay() {
  90.   return _repeatDelay;
  91. }
  92.  
  93. AutoRepeat_Stop() {
  94.   _autorepeatTimer.stop();
  95.   _Latched = NULL;
  96. }
  97.  
  98. AutoRepeat_GetCurrentButton() {
  99.   return _Latched;
  100. }
  101.