customseek.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //----------------------------------------------------------------------------------------
  2. //
  3. // customseek.m
  4. //
  5. //----------------------------------------------------------------------------------------
  6. // Use like this :
  7. // #define CUSTOM_SEEK_VAR MyVar
  8. // #include "customseek.m"
  9. //
  10. //
  11. // What you need :
  12. // _MyVarInit(Layer seeksurface, Layer seekghost, Map seekmap);
  13. // _MyVarShutdown();
  14. //
  15. Global Layer _##CUSTOM_SEEK_VAR##Surface;
  16. Global Layer _##CUSTOM_SEEK_VAR##Ghost;
  17. Global Map _##CUSTOM_SEEK_VAR##Map;
  18. Global Int _##CUSTOM_SEEK_VAR##Clicked;
  19. Global Timer _##CUSTOM_SEEK_VAR##Timer;
  20. Global Int _##CUSTOM_SEEK_VAR##CurPos;
  21. Function _##CUSTOM_SEEK_VAR##Init(Layer s, Layer g, Map m);
  22. Function _##CUSTOM_SEEK_VAR##Update(int newpos);
  23. Function _##CUSTOM_SEEK_VAR##UpdateXY(int x, int y);
  24. Function _##CUSTOM_SEEK_VAR##SeekTo(int x, int y);
  25. Function _##CUSTOM_SEEK_VAR##Shutdown();
  26. _##CUSTOM_SEEK_VAR##Init(Layer s, Layer g, Map m) {
  27. _##CUSTOM_SEEK_VAR##Surface = s;
  28. _##CUSTOM_SEEK_VAR##Ghost = g;
  29. _##CUSTOM_SEEK_VAR##Map = m;
  30. _##CUSTOM_SEEK_VAR##Update(0);
  31. _##CUSTOM_SEEK_VAR##Timer = new Timer;
  32. _##CUSTOM_SEEK_VAR##Timer.setDelay(500);
  33. _##CUSTOM_SEEK_VAR##Timer.start();
  34. }
  35. _##CUSTOM_SEEK_VAR##Shutdown() {
  36. delete _##CUSTOM_SEEK_VAR##Timer;
  37. }
  38. _##CUSTOM_SEEK_VAR##Surface.onLeftButtonDown(int x, int y) {
  39. if (getPlayItemLength() <= 0) return;
  40. if (Strleft(getPlayItemString(), 4) == "http") return;
  41. _##CUSTOM_SEEK_VAR##Clicked = 1;
  42. _##CUSTOM_SEEK_VAR##UpdateXY(x, y);
  43. }
  44. _##CUSTOM_SEEK_VAR##Surface.onMouseMove(int x, int y) {
  45. if (_##CUSTOM_SEEK_VAR##Clicked) {
  46. if (getPlayItemLength() == 0) {
  47. _##CUSTOM_SEEK_VAR##Clicked = 0;
  48. return;
  49. }
  50. _##CUSTOM_SEEK_VAR##UpdateXY(x, y);
  51. }
  52. }
  53. _##CUSTOM_SEEK_VAR##Surface.onLeftButtonUp(int x, int y) {
  54. if (!_##CUSTOM_SEEK_VAR##Clicked) return;
  55. _##CUSTOM_SEEK_VAR##Clicked = 0;
  56. _##CUSTOM_SEEK_VAR##SeekTo(x, y);
  57. }
  58. _##CUSTOM_SEEK_VAR##SeekTo(int x, int y) {
  59. int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  60. seekTo(getPlayItemLength() * (n / 255));
  61. }
  62. _##CUSTOM_SEEK_VAR##UpdateXY(int x, int y) {
  63. int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  64. Region r = new Region;
  65. r.loadFromMap(_##CUSTOM_SEEK_VAR##Map, n, 1);
  66. r.offset(-_##CUSTOM_SEEK_VAR##Ghost.getLeft(), -_##CUSTOM_SEEK_VAR##Ghost.getTop());
  67. _##CUSTOM_SEEK_VAR##Ghost.setRegion(r);
  68. #ifdef CUSTOM_SEEK_CALLBACK
  69. int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  70. _##CUSTOM_SEEK_VAR##OnUpdate(r, getPlayItemLength() * (n / 255));
  71. #endif
  72. delete r;
  73. }
  74. _##CUSTOM_SEEK_VAR##Update(int newpos) {
  75. float p;
  76. int l = getPlayItemLength();
  77. if (l == 0) p = 0;
  78. else p = newpos / l * 255;
  79. Region r = new Region;
  80. r.loadFromMap(_##CUSTOM_SEEK_VAR##Map, p, 1);
  81. _##CUSTOM_SEEK_VAR##CurPos = p;
  82. r.offset(-_##CUSTOM_SEEK_VAR##Ghost.getLeft(), -_##CUSTOM_SEEK_VAR##Ghost.getTop());
  83. _##CUSTOM_SEEK_VAR##Ghost.setRegion(r);
  84. #ifdef CUSTOM_SEEK_CALLBACK
  85. _##CUSTOM_SEEK_VAR##OnUpdate(r, newpos);
  86. #endif
  87. delete r;
  88. }
  89. _##CUSTOM_SEEK_VAR##Timer.onTimer() {
  90. if (_##CUSTOM_SEEK_VAR##Clicked) return;
  91. int l = getPlayItemLength();
  92. if (l > 0) {
  93. int p = getPosition() / l * 255;
  94. if (p != _##CUSTOM_SEEK_VAR##CurPos) {
  95. _##CUSTOM_SEEK_VAR##Update(getPosition());
  96. }
  97. } else {
  98. if (_##CUSTOM_SEEK_VAR##CurPos != 0)
  99. _##CUSTOM_SEEK_VAR##Update(0);
  100. _##CUSTOM_SEEK_VAR##CurPos = 0;
  101. }
  102. }