1
0

AutoRepeatButton.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Function AutoRepeat_Load(); // ALWAYS call this in System.OnScriptLoaded()
  18. Function AutoRepeat_Unload(); // ALWAYS call this in System.OnScriptUnloading()
  19. Function AutoRepeat_Stop(); // stop the current button from autorepeating
  20. Function Button AutoRepeat_GetCurrentButton(); /* returns the currently autorepeating button,
  21. returns NULL if no button is autorepeating */
  22. Function AutoRepeat_SetInitalDelay(int millis); /* set this for the first delay when the button is
  23. pressed, defaults to 800ms (no need to use this
  24. unless other delay is required) */
  25. Function AutoRepeat_SetRepeatDelay(int millis); /* set this for the subsequent delay, defaults to
  26. 80ms (no need to use this unless other delay is
  27. required) */
  28. Function Int AutoRepeat_GetInitalDelay(); // get the first delay length in millisecs
  29. Function Int AutoRepeat_GetRepeatDelay(); // get the subsequent delay in millisecs
  30. Class Button AutoRepeatButton;
  31. Global Timer _autorepeatTimer;
  32. Global Int _InitialDelay;
  33. Global Int _RepeatDelay;
  34. Global Int AutoRepeat_ClickType;
  35. Global Button _Latched;
  36. AutoRepeatButton.onLeftButtonDown(int x, int y) {
  37. _Latched = AutoRepeatButton;
  38. AutoRepeat_ClickType = 1; // first click
  39. AutoRepeatButton.leftClick();
  40. AutoRepeat_ClickType = 0; // no click
  41. _autorepeatTimer.setDelay(_InitialDelay);
  42. _autorepeatTimer.start();
  43. }
  44. AutoRepeatButton.onLeftButtonUp(int x, int y) {
  45. _AutoRepeatTimer.Stop();
  46. _Latched = NULL;
  47. }
  48. _AutoRepeatTimer.onTimer() {
  49. if(_autorepeatTimer.getDelay() != _RepeatDelay) _autorepeatTimer.setDelay(_RepeatDelay);
  50. AutoRepeat_ClickType = 2; // AutoRepeat
  51. _Latched.LeftClick();
  52. AutoRepeat_ClickType = 0; // no click
  53. }
  54. AutoRepeat_Load() {
  55. _autoRepeatTimer = new Timer;
  56. _InitialDelay = 800;
  57. _RepeatDelay = 80;
  58. AutoRepeat_ClickType = 0;
  59. }
  60. AutoRepeat_Unload() {
  61. delete _autoRepeatTimer;
  62. }
  63. AutoRepeat_SetInitalDelay(int millis) {
  64. _InitialDelay = millis;
  65. }
  66. AutoRepeat_SetRepeatDelay(int millis) {
  67. _RepeatDelay = millis;
  68. }
  69. AutoRepeat_GetInitalDelay() {
  70. return _InitialDelay;
  71. }
  72. AutoRepeat_GetRepeatDelay() {
  73. return _repeatDelay;
  74. }
  75. AutoRepeat_Stop() {
  76. _autorepeatTimer.stop();
  77. _Latched = NULL;
  78. }
  79. AutoRepeat_GetCurrentButton() {
  80. return _Latched;
  81. }