home *** CD-ROM | disk | FTP | other *** search
/ Minami 40 / MINAMI40.ISO / Extra / winamp3_0-full.exe / Lib / customseek.m < prev    next >
Text File  |  2002-05-30  |  4KB  |  119 lines

  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.  
  16.  
  17.  
  18. Global Layer _##CUSTOM_SEEK_VAR##Surface;
  19. Global Layer _##CUSTOM_SEEK_VAR##Ghost;
  20. Global Map _##CUSTOM_SEEK_VAR##Map;
  21. Global Int _##CUSTOM_SEEK_VAR##Clicked;
  22. Global Timer _##CUSTOM_SEEK_VAR##Timer;
  23. Global Int _##CUSTOM_SEEK_VAR##CurPos;
  24.  
  25. Function _##CUSTOM_SEEK_VAR##Init(Layer s, Layer g, Map m);
  26. Function _##CUSTOM_SEEK_VAR##Update(int newpos);
  27. Function _##CUSTOM_SEEK_VAR##UpdateXY(int x, int y);
  28. Function _##CUSTOM_SEEK_VAR##SeekTo(int x, int y);
  29. Function _##CUSTOM_SEEK_VAR##Shutdown();
  30.  
  31. _##CUSTOM_SEEK_VAR##Init(Layer s, Layer g, Map m) {
  32.   _##CUSTOM_SEEK_VAR##Surface = s;
  33.   _##CUSTOM_SEEK_VAR##Ghost = g;
  34.   _##CUSTOM_SEEK_VAR##Map = m;
  35.   _##CUSTOM_SEEK_VAR##Update(0);
  36.   _##CUSTOM_SEEK_VAR##Timer = new Timer;
  37.   _##CUSTOM_SEEK_VAR##Timer.setDelay(500);
  38.   _##CUSTOM_SEEK_VAR##Timer.start();
  39. }
  40.  
  41. _##CUSTOM_SEEK_VAR##Shutdown() {
  42.   delete _##CUSTOM_SEEK_VAR##Timer;
  43. }
  44.  
  45. _##CUSTOM_SEEK_VAR##Surface.onLeftButtonDown(int x, int y) {
  46.   if (getPlayItemLength() <= 0) return;
  47.   if (Strleft(getPlayItemString(), 4) == "http") return;
  48.   _##CUSTOM_SEEK_VAR##Clicked = 1;
  49.   _##CUSTOM_SEEK_VAR##UpdateXY(x, y);
  50. }
  51.  
  52. _##CUSTOM_SEEK_VAR##Surface.onMouseMove(int x, int y) {
  53.   if (_##CUSTOM_SEEK_VAR##Clicked) {
  54.     if (getPlayItemLength() == 0) {
  55.       _##CUSTOM_SEEK_VAR##Clicked = 0;
  56.       return;
  57.     }
  58.     _##CUSTOM_SEEK_VAR##UpdateXY(x, y);
  59.   }
  60. }
  61.  
  62. _##CUSTOM_SEEK_VAR##Surface.onLeftButtonUp(int x, int y) {
  63.   if (!_##CUSTOM_SEEK_VAR##Clicked) return;  
  64.   _##CUSTOM_SEEK_VAR##Clicked = 0;
  65.   _##CUSTOM_SEEK_VAR##SeekTo(x, y);
  66. }
  67.  
  68. _##CUSTOM_SEEK_VAR##SeekTo(int x, int y) {
  69.   int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  70.   seekTo(getPlayItemLength() * (n / 255));
  71. }
  72.  
  73. _##CUSTOM_SEEK_VAR##UpdateXY(int x, int y) {
  74.   int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  75.   Region r = new Region;
  76.   r.loadFromMap(_##CUSTOM_SEEK_VAR##Map, n, 1);
  77.   r.offset(-_##CUSTOM_SEEK_VAR##Ghost.getLeft(), -_##CUSTOM_SEEK_VAR##Ghost.getTop());
  78.   _##CUSTOM_SEEK_VAR##Ghost.setRegion(r);
  79.   #ifdef CUSTOM_SEEK_CALLBACK
  80.   int n = _##CUSTOM_SEEK_VAR##Map.getValue(x, y);
  81.   _##CUSTOM_SEEK_VAR##OnUpdate(r, getPlayItemLength() * (n / 255));
  82.   #endif
  83.   delete r;
  84. }
  85.  
  86. _##CUSTOM_SEEK_VAR##Update(int newpos) {
  87.   float p;
  88.   int l = getPlayItemLength();
  89.   if (l == 0) p = 0;
  90.   else p = newpos / l * 255;
  91.   Region r = new Region;
  92.   r.loadFromMap(_##CUSTOM_SEEK_VAR##Map, p, 1);
  93.   _##CUSTOM_SEEK_VAR##CurPos = p;
  94.   r.offset(-_##CUSTOM_SEEK_VAR##Ghost.getLeft(), -_##CUSTOM_SEEK_VAR##Ghost.getTop());
  95.   _##CUSTOM_SEEK_VAR##Ghost.setRegion(r);
  96.   #ifdef CUSTOM_SEEK_CALLBACK
  97.   _##CUSTOM_SEEK_VAR##OnUpdate(r, newpos);
  98.   #endif
  99.   delete r;
  100. }
  101.  
  102. _##CUSTOM_SEEK_VAR##Timer.onTimer() {
  103.   if (_##CUSTOM_SEEK_VAR##Clicked) return;
  104.   int l = getPlayItemLength();
  105.   if (l > 0) {
  106.     int p = getPosition() / l * 255;
  107.     if (p != _##CUSTOM_SEEK_VAR##CurPos) {
  108.       _##CUSTOM_SEEK_VAR##Update(getPosition());
  109.     }
  110.   } else {
  111.     if (_##CUSTOM_SEEK_VAR##CurPos != 0)
  112.       _##CUSTOM_SEEK_VAR##Update(0);
  113.       _##CUSTOM_SEEK_VAR##CurPos = 0;
  114.   }
  115. }
  116.  
  117.  
  118.  
  119.