sstatus.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include <precomp.h>
  2. #include <api/wndmgr/layout.h>
  3. #include "sstatus.h"
  4. #include <api/core/api_core.h>
  5. const wchar_t statusXuiStr[] = L"Status"; // This is the xml tag
  6. char statusXuiSvcName[] = "Status xui object"; // this is the name of the xuiservice
  7. XMLParamPair SStatus::params[] = {
  8. {SSTATUS_SETPLAYBITMAP, L"PLAYBITMAP"},
  9. {SSTATUS_SETSTOPBITMAP, L"STOPBITMAP"},
  10. {SSTATUS_SETPAUSEBITMAP, L"PAUSEBITMAP"},
  11. };
  12. SStatus::SStatus() {
  13. getScriptObject()->vcpu_setInterface(statusGuid, (void *)static_cast<SStatus *>(this));
  14. getScriptObject()->vcpu_setClassName(L"Status");
  15. getScriptObject()->vcpu_setController(statusController);
  16. currentStatus = -666;
  17. xuihandle = newXuiHandle();
  18. CreateXMLParameters(xuihandle);
  19. }
  20. void SStatus::CreateXMLParameters(int master_handle)
  21. {
  22. //SSTATUS_PARENT::CreateXMLParameters(master_handle);
  23. int numParams = sizeof(params) / sizeof(params[0]);
  24. hintNumberOfParams(xuihandle, numParams);
  25. for (int i = 0;i < numParams;i++)
  26. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  27. }
  28. SStatus::~SStatus() {
  29. WASABI_API_MEDIACORE->core_delCallback(0, this);
  30. }
  31. int SStatus::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *strval) {
  32. if (_xuihandle != xuihandle) return SSTATUS_PARENT::setXuiParam(_xuihandle, attrid, name, strval);
  33. switch (attrid) {
  34. case SSTATUS_SETPLAYBITMAP:
  35. setPlayBitmap(strval);
  36. break;
  37. case SSTATUS_SETSTOPBITMAP:
  38. setStopBitmap(strval);
  39. break;
  40. case SSTATUS_SETPAUSEBITMAP:
  41. setPauseBitmap(strval);
  42. break;
  43. default:
  44. return 0;
  45. }
  46. return 1;
  47. }
  48. int SStatus::getPreferences(int what) {
  49. if (what == SUGGESTED_W) return getWidth();
  50. if (what == SUGGESTED_H) return getHeight();
  51. return SSTATUS_PARENT::getPreferences(what);
  52. }
  53. int SStatus::getWidth() {
  54. if (!playBitmap.getBitmap()) return 16;
  55. return playBitmap.getWidth();
  56. }
  57. int SStatus::getHeight() {
  58. if (!playBitmap.getBitmap()) return 16;
  59. return playBitmap.getHeight();
  60. }
  61. int SStatus::onInit() {
  62. SSTATUS_PARENT::onInit();
  63. WASABI_API_MEDIACORE->core_addCallback(0, this);
  64. currentStatus=WASABI_API_MEDIACORE->core_getStatus(0);
  65. return 1;
  66. }
  67. int SStatus::onPaint(Canvas *canvas) {
  68. PaintBltCanvas paintcanvas;
  69. if (canvas == NULL) {
  70. if (!paintcanvas.beginPaint(this)) return 0;
  71. canvas = &paintcanvas;
  72. }
  73. SSTATUS_PARENT::onPaint(canvas);
  74. RECT r;
  75. getClientRect(&r);
  76. AutoSkinBitmap *rb = NULL;
  77. switch(currentStatus) {
  78. case -1: rb = &pauseBitmap; break;
  79. case 0: rb = &stopBitmap; break;
  80. case 1: rb = &playBitmap; break;
  81. }
  82. if (rb != NULL && rb->getBitmap() != NULL) rb->stretchToRect(canvas, &r);
  83. return 1;
  84. }
  85. int SStatus::corecb_onStarted() { currentStatus=1; invalidate(); return 0; }
  86. int SStatus::corecb_onStopped() { currentStatus=0; invalidate(); return 0; }
  87. int SStatus::corecb_onPaused() { currentStatus=-1; invalidate(); return 0; }
  88. int SStatus::corecb_onUnpaused() { currentStatus=1; invalidate(); return 0; }
  89. void SStatus::setPlayBitmap(const wchar_t *name)
  90. {
  91. playBitmap=name;
  92. }
  93. void SStatus::setPauseBitmap(const wchar_t *name) {
  94. pauseBitmap=name;
  95. }
  96. void SStatus::setStopBitmap(const wchar_t *name) {
  97. stopBitmap=name;
  98. }
  99. StatusScriptController _statusController;
  100. StatusScriptController *statusController=&_statusController;
  101. // -- Functions table -------------------------------------
  102. function_descriptor_struct StatusScriptController::exportedFunction[] = {
  103. {L"fake", 0, (void*)SStatus::script_vcpu_fake },
  104. };
  105. // --------------------------------------------------------
  106. const wchar_t *StatusScriptController::getClassName() {
  107. return L"Status";
  108. }
  109. const wchar_t *StatusScriptController::getAncestorClassName() {
  110. return L"GuiObject";
  111. }
  112. ScriptObject *StatusScriptController::instantiate() {
  113. SStatus *st = new SStatus;
  114. ASSERT(st != NULL);
  115. return st->getScriptObject();
  116. }
  117. void StatusScriptController::destroy(ScriptObject *o) {
  118. SStatus *st = static_cast<SStatus*>(o->vcpu_getInterface(statusGuid));
  119. ASSERT(st != NULL);
  120. delete st;
  121. }
  122. void *StatusScriptController::encapsulate(ScriptObject *o) {
  123. return NULL; // no encapsulation for status yet
  124. }
  125. void StatusScriptController::deencapsulate(void *o) {
  126. }
  127. int StatusScriptController::getNumFunctions() {
  128. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  129. }
  130. const function_descriptor_struct *StatusScriptController::getExportedFunctions() {
  131. return exportedFunction;
  132. }
  133. GUID StatusScriptController::getClassGuid() {
  134. return statusGuid;
  135. }
  136. scriptVar SStatus::script_vcpu_fake(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  137. SCRIPT_FUNCTION_INIT
  138. RETURN_SCRIPT_VOID;
  139. }