1
0

xuiprogressgrid.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <precomp.h>
  2. #include "xuiprogressgrid.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <bfc/string/stringdict.h>
  5. #include <api/core/api_core.h>
  6. #define ProgressGrid_TIMER_POS 1
  7. #define PROGRESSGRID_INTERVAL 500
  8. #ifndef _WASABIRUNTIME
  9. BEGIN_SERVICES(ProgressGrid_Svc);
  10. DECLARE_SERVICE(XuiObjectCreator<ProgressGridXuiSvc>);
  11. END_SERVICES(ProgressGrid_Svc, _ProgressGrid_Svc);
  12. #ifdef _X86_
  13. extern "C" { int _link_ProgressGridXuiSvc; }
  14. #else
  15. extern "C" { int __link_ProgressGridXuiSvc; }
  16. #endif
  17. #endif
  18. BEGIN_STRINGDICTIONARY(_pgorientationvalues)
  19. SDI(L"top", PROGRESSGRID_TOP);
  20. SDI(L"left", PROGRESSGRID_LEFT);
  21. SDI(L"right", PROGRESSGRID_RIGHT);
  22. SDI(L"bottom", PROGRESSGRID_BOTTOM);
  23. END_STRINGDICTIONARY(_pgorientationvalues, pgorientationvalues)
  24. // -----------------------------------------------------------------------
  25. const wchar_t ProgressGridXuiObjectStr[] = L"ProgressGrid"; // xml tag
  26. char ProgressGridXuiSvcName[] = "ProgressGrid xui object";
  27. XMLParamPair ProgressGrid::params[] = {
  28. { PROGRESSGRID_SETORIENTATION, L"ORIENTATION"},
  29. { PROGRESSGRID_SETINTERVAL, L"INTERVAL"},
  30. };
  31. // -----------------------------------------------------------------------
  32. ProgressGrid::ProgressGrid() {
  33. myxuihandle = newXuiHandle();
  34. CreateXMLParameters(myxuihandle);
  35. orientation = PROGRESSGRID_RIGHT;
  36. progress = 0;
  37. started = 0;
  38. update_interval = PROGRESSGRID_INTERVAL;
  39. }
  40. void ProgressGrid::CreateXMLParameters(int master_handle)
  41. {
  42. //PROGRESSGRID_PARENT::CreateXMLParameters(master_handle);
  43. int numParams = sizeof(params) / sizeof(params[0]);
  44. hintNumberOfParams(myxuihandle, numParams);
  45. for (int i = 0;i < numParams;i++)
  46. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  47. }
  48. // -----------------------------------------------------------------------
  49. ProgressGrid::~ProgressGrid() {
  50. killTimer(ProgressGrid_TIMER_POS);
  51. WASABI_API_MEDIACORE->core_delCallback(0, this);
  52. }
  53. // -----------------------------------------------------------------------
  54. int ProgressGrid::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  55. if (xuihandle != myxuihandle)
  56. return PROGRESSGRID_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  57. switch (xmlattributeid) {
  58. case PROGRESSGRID_SETORIENTATION:
  59. setOrientation(value);
  60. break;
  61. case PROGRESSGRID_SETINTERVAL:
  62. if ((update_interval = WTOI(value)) <= 20)
  63. update_interval = PROGRESSGRID_INTERVAL;
  64. break;
  65. default:
  66. return 0;
  67. }
  68. return 1;
  69. }
  70. // -----------------------------------------------------------------------
  71. void ProgressGrid::setOrientation(const wchar_t *or) {
  72. int a = pgorientationvalues.getId(or);
  73. if (orientation == a) return;
  74. orientation = a;
  75. invalidate();
  76. }
  77. // -----------------------------------------------------------------------
  78. void ProgressGrid::getGridRect(RECT *r) {
  79. RECT cr;
  80. getClientRect(&cr);
  81. float p = started ? progress : 0.0f;
  82. int height = (int)((float)(cr.bottom - cr.top) * p);
  83. int width = (int)((float)(cr.right - cr.left) * p);
  84. switch (orientation) {
  85. case PROGRESSGRID_LEFT: cr.left = cr.right - width; break;
  86. case PROGRESSGRID_TOP: cr.top = cr.bottom - height; break;
  87. case PROGRESSGRID_RIGHT: cr.right = cr.left + width; break;
  88. case PROGRESSGRID_BOTTOM: cr.bottom = cr.top + height; break;
  89. }
  90. *r = cr;
  91. }
  92. // -----------------------------------------------------------------------
  93. int ProgressGrid::onInit() {
  94. PROGRESSGRID_PARENT::onInit();
  95. timerCallback(ProgressGrid_TIMER_POS);
  96. setTimer(ProgressGrid_TIMER_POS, update_interval);
  97. WASABI_API_MEDIACORE->core_addCallback(0, this);
  98. if (WASABI_API_MEDIACORE->core_getStatus(0) != 0) started = 1; else started = 0;
  99. return 1;
  100. }
  101. // -----------------------------------------------------------------------
  102. int ProgressGrid::corecb_onSeeked(int newpos) {
  103. if(!started) corecb_onStarted();
  104. int len = WASABI_API_MEDIACORE->core_getLength(0);
  105. if (newpos == -1 || len <= 0) setProgress(0);
  106. else setProgress(((float)newpos/(float)len));
  107. return 0;
  108. }
  109. // -----------------------------------------------------------------------
  110. int ProgressGrid::corecb_onStarted() {
  111. started = 1;
  112. invalidate();
  113. return 0;
  114. }
  115. // -----------------------------------------------------------------------
  116. int ProgressGrid::corecb_onStopped() {
  117. started = 0;
  118. progress = 0.0f;
  119. invalidate();
  120. return 0;
  121. }
  122. void ProgressGrid::setProgress(float p) {
  123. if (progress == p) return;
  124. progress = p;
  125. invalidate();
  126. }
  127. void ProgressGrid::timerCallback(int id) {
  128. switch (id) {
  129. case ProgressGrid_TIMER_POS: {
  130. int playpos = WASABI_API_MEDIACORE->core_getPosition(0);
  131. corecb_onSeeked(playpos);
  132. }
  133. break;
  134. default:
  135. PROGRESSGRID_PARENT::timerCallback(id);
  136. }
  137. }