1
0

dragvolume.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //----------------------------------------------------------------------------------------
  2. //
  3. // dragvolume.m
  4. //
  5. //----------------------------------------------------------------------------------------
  6. // Use like this :
  7. // #define DRAG_VOLUME_VAR MyVar
  8. // #include "dragvolume.m"
  9. //
  10. //
  11. // _MyVarInit(AnimatedLayer l); // init dragvolume
  12. // _MyVarSetMaxDistance(Int nPixels); // set 100% pixel distance
  13. //
  14. Global AnimatedLayer _##DRAG_VOLUME_VAR##AnimLayer;
  15. Global Int _##DRAG_VOLUME_VAR##Clicked;
  16. Global Int _##DRAG_VOLUME_VAR##Y;
  17. Global Int _##DRAG_VOLUME_VAR##V;
  18. Global Int _##DRAG_VOLUME_VAR##Max;
  19. Function _##DRAG_VOLUME_VAR##Init(AnimatedLayer l);
  20. Function _##DRAG_VOLUME_VAR##Update(int vol);
  21. Function _##DRAG_VOLUME_VAR##SetMaxDistance(int pixels);
  22. Function _##DRAG_VOLUME_VAR##UpdateY(int y);
  23. _##DRAG_VOLUME_VAR##Init(AnimatedLayer l) {
  24. _##DRAG_VOLUME_VAR##AnimLayer = l;
  25. _##DRAG_VOLUME_VAR##Update(getVolume());
  26. }
  27. _##DRAG_VOLUME_VAR##AnimLayer.onLeftButtonDown(int x, int y) {
  28. _##DRAG_VOLUME_VAR##Clicked = 1;
  29. _##DRAG_VOLUME_VAR##Y = y;
  30. _##DRAG_VOLUME_VAR##V = getVolume();
  31. }
  32. _##DRAG_VOLUME_VAR##AnimLayer.onMouseMove(int x, int y) {
  33. if (_##DRAG_VOLUME_VAR##Clicked) {
  34. _##DRAG_VOLUME_VAR##updateY(y);
  35. }
  36. }
  37. _##DRAG_VOLUME_VAR##AnimLayer.onLeftButtonUp(int x, int y) {
  38. _##DRAG_VOLUME_VAR##Clicked = 0;
  39. }
  40. _##DRAG_VOLUME_VAR##SetMaxDistance(int npix) {
  41. _##DRAG_VOLUME_VAR##Max = npix;
  42. }
  43. _##DRAG_VOLUME_VAR##UpdateY(int y) {
  44. float p = (_##DRAG_VOLUME_VAR##Y - y) / _##DRAG_VOLUME_VAR##Max;
  45. SetVolume(_##DRAG_VOLUME_VAR##V + p * 255); // range is checked
  46. }
  47. _##DRAG_VOLUME_VAR##Update(int vol) {
  48. float p = vol / 255;
  49. _##DRAG_VOLUME_VAR##AnimLayer.gotoFrame(p * (_##DRAG_VOLUME_VAR##AnimLayer.getLength()-1));
  50. }
  51. #ifndef _##DRAG_VOLUME_VAR##NOSYSTEMHOOK
  52. System.onVolumeChanged(int newvol) {
  53. _##DRAG_VOLUME_VAR##Update(newvol);
  54. }
  55. #endif