status.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #include <precomp.h>
  2. #include "status.h"
  3. #include <tataki/color/skinclr.h>
  4. #include <tataki/canvas/canvas.h>
  5. #include <api/wnd/wndclass/buttbar.h>
  6. #include <api/wnd/wndclass/buttwnd.h>
  7. #include <api/wndmgr/appcmds.h>
  8. #include <bfc/parse/paramparser.h>
  9. #include <api/script/objects/c_script/c_text.h>
  10. #define STATUS_TIMER_DECAY 1
  11. #define COMPLETED_WIDTH 96
  12. static SkinColor textcolor(L"wasabi.statusbar.text");
  13. class CmdButton : public ButtonWnd
  14. {
  15. public:
  16. CmdButton(const wchar_t *name, AppCmds *_cmd, int _id) : ButtonWnd(name), cmd(_cmd), id(_id) {}
  17. virtual void onLeftPush(int x, int y) {
  18. cmd->appcmds_onCommand(id, &windowRect(), AppCmds::LEFT_CLICK);
  19. }
  20. virtual void onRightPush(int x, int y) {
  21. cmd->appcmds_onCommand(id, &windowRect(), AppCmds::RIGHT_CLICK);
  22. }
  23. virtual int wantAutoContextMenu() { return 0; }
  24. AppCmds *cmd;
  25. int id;
  26. };
  27. StatusBar::StatusBar() {
  28. overtimer = 0;
  29. max = 0;
  30. completed = 0;
  31. progress_width = 0;
  32. bg.setContent(L"wasabi.statusbar");
  33. bbleft = bbright = NULL;
  34. }
  35. StatusBar::~StatusBar()
  36. {
  37. killTimer(STATUS_TIMER_DECAY);
  38. delete bbleft;
  39. delete bbright;
  40. }
  41. int StatusBar::onInit() {
  42. STATUSBAR_PARENT::onInit();
  43. bg.init(this);
  44. #ifdef WASABI_COMPILE_WNDMGR
  45. getGuiObject()->guiobject_registerStatusCB(this); // watched
  46. #endif
  47. regenerate();
  48. return 1;
  49. }
  50. void StatusBar::timerCallback(int id) {
  51. switch (id) {
  52. case STATUS_TIMER_DECAY: {
  53. killTimer(STATUS_TIMER_DECAY);
  54. onSetStatusText(status_text, FALSE); // revert to main text
  55. }
  56. break;
  57. default:
  58. STATUSBAR_PARENT::timerCallback(id);
  59. break;
  60. }
  61. }
  62. void StatusBar::pushCompleted(int _max) {
  63. max = MAX(_max, 0);
  64. completed = 0;
  65. GuiObject *outer = bg.findObject(L"wasabi.statusbar.progress.outline");
  66. outer->guiobject_setXmlParam(L"visible", L"0");
  67. ASSERT(outer != NULL);
  68. ifc_window *outerw = outer->guiobject_getRootWnd();
  69. RECT cr;
  70. outerw->getClientRect(&cr);
  71. progress_width = cr.right - cr.left;
  72. outerw->setVisible(TRUE);//CUT
  73. outer->guiobject_setTargetA(255);
  74. outer->guiobject_setTargetSpeed(0.1f);
  75. outer->guiobject_gotoTarget();
  76. GuiObject *inner = bg.findObject(L"wasabi.statusbar.progress.inside");
  77. inner->guiobject_setTargetA(255);
  78. inner->guiobject_setTargetSpeed(1.0f);
  79. inner->guiobject_gotoTarget();
  80. inner->guiobject_setXmlParam(L"visible", L"0");
  81. incCompleted(0);
  82. }
  83. void StatusBar::incCompleted(int add) {
  84. setCompleted(completed + add);
  85. }
  86. void StatusBar::setCompleted(int _completed) {
  87. completed = _completed;
  88. GuiObject *inner = bg.findObject(L"wasabi.statusbar.progress.inside");
  89. ASSERT(inner != NULL);
  90. if (!inner->guiobject_getRootWnd()->isVisible(1)) {
  91. inner->guiobject_setXmlParam(L"visible", L"1");
  92. inner->guiobject_setTargetA(255);
  93. inner->guiobject_setTargetSpeed(0.75);
  94. inner->guiobject_gotoTarget();
  95. }
  96. int pos = (int)(((float)completed / (float)max)*(float)progress_width);
  97. inner->guiobject_setXmlParam(L"w", StringPrintfW(L"%d", pos));
  98. }
  99. void StatusBar::popCompleted() {
  100. completed = 0;
  101. max = 0;
  102. GuiObject *inner = bg.findObject(L"wasabi.statusbar.progress.inside");
  103. inner->guiobject_setXmlParam(L"w", L"0");
  104. inner->guiobject_setTargetA(0);
  105. inner->guiobject_setTargetSpeed(0.75);
  106. inner->guiobject_gotoTarget();
  107. //CUT later
  108. inner->guiobject_setXmlParam(L"visible", L"0");
  109. GuiObject *outer = bg.findObject(L"wasabi.statusbar.progress.outline");
  110. outer->guiobject_setXmlParam(L"visible", L"0");
  111. }
  112. int StatusBar::onResize() {
  113. STATUSBAR_PARENT::onResize();
  114. RECT cr = clientRect();
  115. bbleft->resize(cr.left, cr.top, bbleft->getWidth(), cr.bottom - cr.top);
  116. bbright->resize(cr.right-bbright->getWidth(), cr.top, bbright->getWidth(), cr.bottom - cr.top);
  117. cr.left += bbleft->getWidth();
  118. cr.right -= bbright->getWidth();
  119. bg.resizeToRect(&cr); // put bg group in place
  120. invalidate();
  121. return 1;
  122. }
  123. void StatusBar::onSetStatusText(const wchar_t *text, int overlay)
  124. {
  125. killTimer(STATUS_TIMER_DECAY);
  126. if (!overlay)
  127. status_text = text;
  128. else setTimer(STATUS_TIMER_DECAY, 4000);
  129. ScriptObject *tx = bg.findScriptObject(L"wasabi.statusbar.text");
  130. if (tx == NULL) return;
  131. C_Text(tx).setText(text ? text : L"");
  132. }
  133. void StatusBar::onAddAppCmds(AppCmds *commands) {
  134. if (appcmds.haveItem(commands)) appcmds.removeItem(commands);
  135. appcmds.addItem(commands);
  136. regenerate();
  137. }
  138. void StatusBar::onRemoveAppCmds(AppCmds *commands) {
  139. if (appcmds.haveItem(commands)) {
  140. appcmds.removeItem(commands);
  141. regenerate();
  142. }
  143. }
  144. void StatusBar::regenerate() {
  145. if (!isInited()) return;
  146. delete bbleft; bbleft = new ButtBar;
  147. delete bbright; bbright = new ButtBar;
  148. bbleft->init(this);
  149. bbright->init(this);
  150. ParamParser exclude(exclude_list, L";");
  151. ParamParser showonly(include_only, L";");
  152. foreach(appcmds)
  153. int n = appcmds.getfor()->appcmds_getNumCmds();
  154. for (int i = 0; i < n; i++) {
  155. int side, id;
  156. const wchar_t *name = appcmds.getfor()->appcmds_enumCmd(i, &side, &id);
  157. if (name == NULL) break;
  158. if (exclude.hasString(name)) continue; // exclusion list
  159. if (showonly.getNumItems()) {
  160. if (!showonly.hasString(name)) continue; // include-only list
  161. }
  162. CmdButton *cb = new CmdButton(name, appcmds.getfor(), id);
  163. // cb->setXmlParam("wantfocus", "1");
  164. if (side == AppCmds::SIDE_LEFT) bbleft->addChild(cb);
  165. else bbright->addChild(cb);
  166. }
  167. endfor
  168. if (isPostOnInit())
  169. onResize();
  170. }
  171. void StatusBar::fakeButtonPush(const wchar_t *name) {
  172. if (!fakeButtonPush(bbleft, name))
  173. fakeButtonPush(bbright, name);
  174. }
  175. int StatusBar::fakeButtonPush(ButtBar *bb, const wchar_t *name)
  176. {
  177. for (int i = 0; i < bb->getNumChildren(); i++) {
  178. ButtonWnd *cmdb = bb->enumChild(i);
  179. if (!WCSICMP(cmdb->getName(), name)) {
  180. int x, y;
  181. Wasabi::Std::getMousePos(&x, &y);
  182. cmdb->screenToClient(&x, &y);
  183. cmdb->onLeftPush(x, y);
  184. return 1;
  185. }
  186. }
  187. return 0;
  188. }
  189. void StatusBar::setExclude(const wchar_t *val) {
  190. exclude_list = val;
  191. regenerate();
  192. }
  193. void StatusBar::setIncludeOnly(const wchar_t *val) {
  194. include_only = val;
  195. regenerate();
  196. }