1
0

textbase.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. #include <precomp.h>
  2. #include <api.h>
  3. #include "textbase.h"
  4. #include <api/skin/skinparse.h>
  5. #include <api/skin/skinelem.h>
  6. #include <api/service/svcs/svc_action.h>
  7. #include <api/script/vcpu.h>
  8. #define COLORMODE_RGB 0
  9. #define COLORMODE_SKINCOLOR 1
  10. XMLParamPair TextBase::params[] =
  11. {
  12. {TEXTBASE_RCLICKPARAM, L"RCLICKPARAM"},
  13. {TEXTBASE_DBLCLICKPARAM, L"DBLCLICKPARAM"},
  14. {TEXTBASE_SETALIGN, L"ALIGN"},
  15. {TEXTBASE_SETALTANTIALIAS, L"ALTANTIALIAS"},
  16. {TEXTBASE_SETALTBOLD, L"ALTBOLD"},
  17. {TEXTBASE_SETALTCOLOR, L"ALTCOLOR"},
  18. {TEXTBASE_SETALTFONT, L"ALTFONT"},
  19. {TEXTBASE_SETALTFONTSIZE, L"ALTFONTSIZE"},
  20. {TEXTBASE_SETALTITALIC, L"ALTITALIC"},
  21. {TEXTBASE_SETANTIALIAS, L"ANTIALIAS"},
  22. {TEXTBASE_SETBOLD, L"BOLD"},
  23. {TEXTBASE_SETCOLOR, L"COLOR"},
  24. {TEXTBASE_SETDBLCLKACTION, L"DBLCLICKACTION"},
  25. {TEXTBASE_SETFONT, L"FONT"},
  26. {TEXTBASE_SETFONTSIZE, L"FONTSIZE"},
  27. {TEXTBASE_SETITALIC, L"ITALIC"},
  28. {TEXTBASE_SETLPADDING, L"LEFTPADDING"},
  29. {TEXTBASE_SETRCLKACTION, L"RIGHTCLICKACTION"},
  30. {TEXTBASE_SETRPADDING, L"RIGHTPADDING"},
  31. };
  32. TextBase::TextBase()
  33. {
  34. color[0].setColorGroup(L"Text");
  35. color[1].setColorGroup(L"Text");
  36. color[0].setColor(RGB(255, 255, 255));
  37. color[1].setColor(RGB(255, 255, 255));
  38. color_mode[0] = COLORMODE_RGB;
  39. color_mode[1] = COLORMODE_RGB;
  40. fontsize[0] = fontsize[1] = 14;
  41. font[0] = wasabi_default_fontnameW;
  42. font[1] = wasabi_default_fontnameW;
  43. bold[0] = 0;
  44. bold[1] = 0;
  45. italic[0] = 0;
  46. italic[1] = 0;
  47. antialias[0] = 1;
  48. antialias[1] = 1;
  49. align = ALIGN_LEFT;
  50. lpadding = rpadding = 0;
  51. grab = 0;
  52. /* register XML parameters */
  53. xuihandle = newXuiHandle();
  54. CreateXMLParameters(xuihandle);
  55. }
  56. void TextBase::CreateXMLParameters(int master_handle)
  57. {
  58. //TEXTBASE_PARENT::CreateXMLParameters(master_handle);
  59. int numParams = sizeof(params) / sizeof(params[0]);
  60. hintNumberOfParams(xuihandle, numParams);
  61. for (int i = 0;i < numParams;i++)
  62. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  63. }
  64. TextBase::~TextBase()
  65. {
  66. WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<SkinCallbackI*>(this));
  67. }
  68. int TextBase::onInit()
  69. {
  70. TEXTBASE_PARENT::onInit();
  71. WASABI_API_SYSCB->syscb_registerCallback(static_cast<SkinCallbackI*>(this));
  72. return 1;
  73. }
  74. int TextBase::skincb_onColorThemeChanged(const wchar_t *newcolortheme)
  75. {
  76. invalidateTextBuffer();
  77. return 0;
  78. }
  79. ARGB32 TextBase::GetColor(int alt)
  80. {
  81. if (alt < 0 || alt > 1) alt = 0;
  82. if (color_mode[alt] == COLORMODE_SKINCOLOR)
  83. return scolor[alt];
  84. return color[alt].getColor();
  85. }
  86. void TextBase::SetTextColor(ARGB32 c, int alt)
  87. {
  88. if (alt < 0 || alt > 1) alt = 0;
  89. color_mode[alt] = COLORMODE_RGB;
  90. color[alt].setColor(c);
  91. invalidateTextBuffer();
  92. if (alt == 0) SetTextColor(c, 1);
  93. }
  94. void TextBase::SetFontSize(const wchar_t *strvalue, int alt)
  95. {
  96. if (alt < 0 || alt > 1) alt = 0;
  97. if (!strvalue || !*strvalue) return ;
  98. if (*strvalue == '+')
  99. fontsize[alt] += WTOI(strvalue + 1);
  100. else if (*strvalue == '-')
  101. fontsize[alt] -= WTOI(strvalue + 1);
  102. else if (*strvalue == '*')
  103. fontsize[alt] *= WTOI(strvalue + 1);
  104. else if (*strvalue == '/')
  105. fontsize[alt] /= WTOI(strvalue + 1);
  106. else
  107. fontsize[alt] = WTOI(strvalue);
  108. invalidateTextBuffer();
  109. if (alt == 0) SetFontSize(strvalue, 1);
  110. }
  111. void TextBase::GetFontInfo(Wasabi::FontInfo *_font, int alt)
  112. {
  113. _font->opaque=false;
  114. _font->color = GetColor(alt);
  115. _font->pointSize = fontsize[alt];
  116. _font->face = font[alt];
  117. _font->bold = bold[alt];
  118. _font->italic = !!italic[alt];
  119. _font->antialias = antialias[alt];
  120. _font->alignFlags = align;
  121. }
  122. void TextBase::SetFont(const wchar_t *name, int alt)
  123. {
  124. if (alt < 0 || alt > 1) alt = 0;
  125. font[alt] = name;
  126. invalidateTextBuffer();
  127. if (alt == 0) SetFont(name, 1);
  128. }
  129. void TextBase::SetAntialias(int a, int alt)
  130. {
  131. antialias[alt] = a;
  132. if (alt==0)
  133. antialias[1] = antialias[0];
  134. invalidateTextBuffer();
  135. }
  136. void TextBase::SetFontAlign(int al)
  137. {
  138. align = al;
  139. invalidateTextBuffer();
  140. }
  141. int TextBase::setXuiParam(int _xuihandle, int attrid, const wchar_t *name, const wchar_t *strval)
  142. {
  143. if (xuihandle != _xuihandle) return TEXTBASE_PARENT::setXuiParam(_xuihandle, attrid, name, strval);
  144. switch (attrid)
  145. {
  146. case TEXTBASE_SETCOLOR:
  147. if (WASABI_API_PALETTE->getColorElementRef(strval))
  148. {
  149. color_mode[0] = COLORMODE_SKINCOLOR;
  150. scolor[0] = strval;
  151. color_mode[1] = COLORMODE_SKINCOLOR;
  152. scolor[1] = strval;
  153. }
  154. else
  155. SetTextColor(SkinParser::parseColor(strval), 0);
  156. break;
  157. case TEXTBASE_SETALTCOLOR:
  158. if (WASABI_API_PALETTE->getColorElementRef(strval))
  159. {
  160. color_mode[1] = COLORMODE_SKINCOLOR;
  161. scolor[1] = strval;
  162. }
  163. else
  164. SetTextColor(SkinParser::parseColor(strval), 1);
  165. break;
  166. case TEXTBASE_SETFONTSIZE:
  167. SetFontSize(strval);
  168. break;
  169. case TEXTBASE_SETFONT:
  170. SetFont(strval);
  171. break;
  172. case TEXTBASE_SETALTFONT:
  173. SetFont(strval, 1);
  174. break;
  175. case TEXTBASE_SETALTFONTSIZE:
  176. SetFontSize(strval, 1);
  177. break;
  178. case TEXTBASE_SETBOLD:
  179. bold[0] = WTOI(strval);
  180. bold[1] = bold[0];
  181. break;
  182. case TEXTBASE_SETALTBOLD:
  183. bold[1] = WTOI(strval);
  184. break;
  185. case TEXTBASE_SETITALIC:
  186. italic[0] = WTOI(strval);
  187. italic[1] = italic[0];
  188. break;
  189. case TEXTBASE_SETALTITALIC:
  190. italic[1] = WTOI(strval);
  191. break;
  192. case TEXTBASE_SETANTIALIAS:
  193. SetAntialias(WTOI(strval));
  194. invalidateTextBuffer();
  195. break;
  196. case TEXTBASE_SETALTANTIALIAS:
  197. SetAntialias(WTOI(strval), 1);
  198. invalidateTextBuffer();
  199. break;
  200. case TEXTBASE_SETDBLCLKACTION:
  201. dblClickAction = strval;
  202. break;
  203. case TEXTBASE_DBLCLICKPARAM:
  204. setDblClickParam(strval);
  205. break;
  206. case TEXTBASE_RCLICKPARAM:
  207. setRClickParam(strval);
  208. break;
  209. case TEXTBASE_SETRCLKACTION:
  210. rClickAction = strval;
  211. break;
  212. case TEXTBASE_SETALIGN:
  213. SetFontAlign(SkinParser::getAlign(strval));
  214. break;
  215. case TEXTBASE_SETLPADDING:
  216. lpadding = WTOI(strval);
  217. break;
  218. case TEXTBASE_SETRPADDING:
  219. rpadding = WTOI(strval);
  220. break;
  221. default:
  222. return 0;
  223. }
  224. return 1;
  225. }
  226. void TextBase::setDblClickParam(const wchar_t *p)
  227. {
  228. dblclickparam=p;
  229. }
  230. const wchar_t *TextBase::getDblClickParam()
  231. {
  232. return dblclickparam;
  233. }
  234. void TextBase::setRClickParam(const wchar_t *p)
  235. {
  236. rclickparam=p;
  237. }
  238. const wchar_t *TextBase::getRClickParam()
  239. {
  240. return rclickparam;
  241. }
  242. int TextBase::onLeftButtonDblClk(int x, int y)
  243. {
  244. TEXTBASE_PARENT::onLeftButtonDblClk(x, y);
  245. int r = 1;
  246. grab = 0;
  247. if (!dblClickAction.isempty() && !VCPU::getComplete())
  248. {
  249. #ifdef WASABI_COMPILE_WNDMGR
  250. const wchar_t *toCheck = L"SWITCH;";
  251. if (!_wcsnicmp(dblClickAction, toCheck, 7))
  252. {
  253. onLeftButtonUp(x, y);
  254. getGuiObject()->guiobject_getParentGroup()->getParentContainer()->switchToLayout(dblClickAction.getValue() + 7);
  255. }
  256. else
  257. {
  258. #endif
  259. svc_action *act = ActionEnum(dblClickAction).getNext();
  260. if (act)
  261. {
  262. int _x = x;
  263. int _y = y;
  264. clientToScreen(&_x, &_y);
  265. act->onAction(dblClickAction, getDblClickParam(), _x, _y, NULL, 0, this);
  266. SvcEnum::release(act);
  267. }
  268. #ifdef WASABI_COMPILE_WNDMGR
  269. }
  270. #endif
  271. }
  272. return r;
  273. }
  274. int TextBase::onRightButtonDown(int x, int y)
  275. {
  276. TEXTBASE_PARENT::onRightButtonDown(x, y);
  277. if (!rClickAction.isempty())
  278. {
  279. svc_action *act = ActionEnum(rClickAction).getNext();
  280. if (act)
  281. {
  282. int _x = x;
  283. int _y = y;
  284. clientToScreen(&_x, &_y);
  285. act->onAction(rClickAction, getRClickParam(), _x, _y, NULL, 0, this);
  286. SvcEnum::release(act);
  287. }
  288. }
  289. return 1;
  290. }