xuiwa2slider.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include <precomp.h>
  2. #include "xuiwa2slider.h"
  3. #include <tataki/canvas/canvas.h>
  4. #include <tataki/bitmap/bitmap.h>
  5. #include <api/core/api_core.h>
  6. #define WA2SLIDER_SEEK_INTERVAL 500
  7. const wchar_t Wa2SliderXuiObjectStr[] = L"images"; // This is the xml tag
  8. char Wa2SliderXuiSvcName[] = "Images XuiObject Service";
  9. XMLParamPair Wa2Slider::params[] =
  10. {
  11. {WA2SLIDER_IMAGES, L"IMAGES"},
  12. {WA2SLIDER_IMAGESSPACING, L"IMAGESSPACING"},
  13. {WA2SLIDER_SOURCE, L"SOURCE"},
  14. };
  15. Wa2Slider::Wa2Slider()
  16. : started(false)
  17. {
  18. realpos = 0;
  19. imagesBitmap = 0;
  20. spacing = 0;
  21. action = ACT_NONE;
  22. xuihandle = newXuiHandle();
  23. CreateXMLParameters(xuihandle);
  24. }
  25. void Wa2Slider::CreateXMLParameters(int master_handle)
  26. {
  27. //WA2SLIDER_PARENT::CreateXMLParameters(master_handle);
  28. int numParams = sizeof(params) / sizeof(params[0]);
  29. hintNumberOfParams(xuihandle, numParams);
  30. for (int i = 0;i < numParams;i++)
  31. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  32. }
  33. Wa2Slider::~Wa2Slider()
  34. {
  35. killTimer(Wa2Slider_TIMER_POS);
  36. WASABI_API_MEDIACORE->core_delCallback(0, this);
  37. delete(imagesBitmap);
  38. }
  39. int Wa2Slider::setXuiParam(int _xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value)
  40. {
  41. if (xuihandle == _xuihandle)
  42. {
  43. switch (xmlattributeid)
  44. {
  45. case WA2SLIDER_IMAGES: images = value; return 1;
  46. case WA2SLIDER_IMAGESSPACING: spacing = WTOI(value); return 1;
  47. case WA2SLIDER_SOURCE:
  48. if (!_wcsicmp(value, L"volume")) action = ACT_VOLUME;
  49. if (!_wcsicmp(value, L"balance")) action = ACT_BALANCE;
  50. if (!_wcsicmp(value, L"seek")) action = ACT_SEEK;
  51. return 1;
  52. }
  53. }
  54. return WA2SLIDER_PARENT::setXuiParam(_xuihandle, xmlattributeid, xmlattributename, value);
  55. }
  56. int Wa2Slider::onInit()
  57. {
  58. WA2SLIDER_PARENT::onInit();
  59. imagesBitmap = new SkinBitmap(images);
  60. if (action == ACT_VOLUME)
  61. corecb_onVolumeChange(WASABI_API_MEDIACORE->core_getVolume(0));
  62. if (action == ACT_BALANCE)
  63. corecb_onPanChange(WASABI_API_MEDIACORE->core_getPan(0));
  64. if (action == ACT_SEEK)
  65. {
  66. corecb_onSeeked(WASABI_API_MEDIACORE->core_getPosition(0));
  67. started = (WASABI_API_MEDIACORE->core_getStatus(0) != 0);
  68. setTimer(Wa2Slider_TIMER_POS, WA2SLIDER_SEEK_INTERVAL);
  69. }
  70. WASABI_API_MEDIACORE->core_addCallback(0, this);
  71. return 0;
  72. }
  73. int Wa2Slider::onPaint(Canvas *canvas)
  74. {
  75. if (imagesBitmap->getHeight() && spacing)
  76. {
  77. RECT r, r2;
  78. getClientRect(&r2);
  79. int nb = (imagesBitmap->getHeight() / spacing) - 1;
  80. int which = 0;
  81. switch (action)
  82. {
  83. case ACT_BALANCE:
  84. {
  85. int p = realpos;
  86. int f = 32768; //FULL/2;
  87. if (p > f)
  88. {
  89. which = (realpos - f) * nb / f;
  90. }
  91. else if (p < f)
  92. {
  93. which = (f - realpos) * nb / f;
  94. }
  95. else which = 0;
  96. }
  97. break;
  98. case ACT_SEEK:
  99. if (!started)
  100. which = 0;
  101. else
  102. which = realpos * nb / 65536;
  103. break;
  104. case ACT_VOLUME:
  105. which = realpos * nb / 65536;
  106. break;
  107. }
  108. r.left = 0;
  109. r.top = which * spacing;
  110. r.bottom = which * spacing + (r2.bottom - r2.top);
  111. r.right = r2.right - r2.left;
  112. imagesBitmap->blitToRect(canvas, &r, &r2);
  113. }
  114. return WA2SLIDER_PARENT::onPaint(canvas);
  115. }
  116. int Wa2Slider::corecb_onVolumeChange(int newvol)
  117. {
  118. if (action != ACT_VOLUME) return 0;
  119. realpos = (int)(((double)newvol * 65535.f) / 255.f);
  120. invalidate();
  121. return 0;
  122. }
  123. int Wa2Slider::corecb_onPanChange(int newpan)
  124. {
  125. if (action != ACT_BALANCE) return 0;
  126. realpos = (int)(((double)(newpan + 127) * 65535.f) / 255.f);
  127. invalidate();
  128. return 0;
  129. }
  130. int Wa2Slider::corecb_onSeeked(int newpos)
  131. {
  132. if (action != ACT_SEEK) return 0;
  133. int len = WASABI_API_MEDIACORE->core_getLength(0);
  134. realpos = (int)(((float)(newpos) * 65535.f) / (float)len);
  135. invalidate();
  136. return 0;
  137. }
  138. int Wa2Slider::corecb_onStarted()
  139. {
  140. started = true;
  141. corecb_onSeeked(0);
  142. invalidate();
  143. return 0;
  144. }
  145. int Wa2Slider::corecb_onStopped()
  146. {
  147. started = false;
  148. corecb_onSeeked(0);
  149. invalidate();
  150. return 0;
  151. }
  152. void Wa2Slider::timerCallback(int id)
  153. {
  154. switch (id)
  155. {
  156. case Wa2Slider_TIMER_POS:
  157. corecb_onSeeked(WASABI_API_MEDIACORE->core_getPosition(0));
  158. break;
  159. default:
  160. WA2SLIDER_PARENT::timerCallback(id);
  161. }
  162. }