1
0

xuirect.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include <precomp.h>
  2. #include "xuirect.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <bfc/parse/paramparser.h>
  5. #include <api/skin/skinfilter.h>
  6. #include <api/wnd/PaintCanvas.h>
  7. #define BLTSIZE 1
  8. namespace RectEdges
  9. {
  10. enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
  11. };
  12. using namespace RectEdges;
  13. XMLParamPair ScriptRect::params[] = {
  14. {SCRIPTRECT_SETCOLOR, L"COLOR"},
  15. {SCRIPTRECT_EDGES, L"EDGES"},
  16. {SCRIPTRECT_SETFILLED, L"FILLED"},
  17. {SCRIPTRECT_GAMMAGROUP, L"GAMMAGROUP"},
  18. {SCRIPTRECT_THICKNESS, L"THICKNESS"},
  19. };
  20. ScriptRect::ScriptRect()
  21. : pixel(BLTSIZE, BLTSIZE, NULL)
  22. {
  23. filled = 0;
  24. myxuihandle = newXuiHandle();
  25. CreateXMLParameters(myxuihandle);
  26. color.setColorGroup(L"");
  27. resetPixel();
  28. edges = LEFT | RIGHT | TOP | BOTTOM;
  29. thickness = 1;
  30. }
  31. void ScriptRect::CreateXMLParameters(int master_handle)
  32. {
  33. //SCRIPTRECT_PARENT::CreateXMLParameters(master_handle);
  34. int numParams = sizeof(params) / sizeof(params[0]);
  35. hintNumberOfParams(myxuihandle, numParams);
  36. for (int i = 0;i < numParams;i++)
  37. if (params[i].id == SCRIPTRECT_SETCOLOR)
  38. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_REQUIRED);
  39. else
  40. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  41. }
  42. ScriptRect::~ScriptRect()
  43. {}
  44. int ScriptRect::onInit()
  45. {
  46. SCRIPTRECT_PARENT::onInit();
  47. return 1;
  48. }
  49. int ScriptRect::onPaint(Canvas *c)
  50. {
  51. if (c == NULL)
  52. {
  53. PaintCanvas pc;
  54. if (!pc.beginPaint(this)) return 0;
  55. return ScriptRect::onPaint(&pc);
  56. }
  57. // check for colors changing on us
  58. if (!color.iteratorValid()) resetPixel();
  59. //RECT src = {0, 0, BLTSIZE, BLTSIZE};
  60. if (filled)
  61. {
  62. RECT dst;
  63. getClientRect(&dst);
  64. c->fillRectAlpha(&dst, color.v(), getPaintingAlpha());
  65. // pixel./*getSkinBitmap()->*/stretchToRectAlpha(c, &src, &dst, getPaintingAlpha());
  66. }
  67. else
  68. {
  69. RECT dst, odst;
  70. getClientRect(&odst);
  71. if (edges & TOP)
  72. {
  73. dst = odst;
  74. dst.bottom = dst.top + thickness;
  75. c->fillRectAlpha(&dst, color.v(), getPaintingAlpha());
  76. //pixel./*getSkinBitmap()->*/stretchToRectAlpha(c, &src, &dst, getPaintingAlpha());
  77. }
  78. if (edges & BOTTOM)
  79. {
  80. dst = odst;
  81. dst.top = dst.bottom - thickness;
  82. c->fillRectAlpha(&dst, color.v(), getPaintingAlpha());
  83. //pixel./*getSkinBitmap()->*/stretchToRectAlpha(c, &src, &dst, getPaintingAlpha());
  84. }
  85. if (edges & RIGHT)
  86. {
  87. dst = odst;
  88. dst.top++; dst.bottom--;
  89. dst.left = dst.right - thickness;
  90. c->fillRectAlpha(&dst, color.v(), getPaintingAlpha());
  91. //pixel./*getSkinBitmap()->*/stretchToRectAlpha(c, &src, &dst, getPaintingAlpha());
  92. }
  93. if (edges & LEFT)
  94. {
  95. dst = odst;
  96. dst.right = dst.left + thickness;
  97. c->fillRectAlpha(&dst, color.v(), getPaintingAlpha());
  98. //pixel./*getSkinBitmap()->*/stretchToRectAlpha(c, &src, &dst, getPaintingAlpha());
  99. }
  100. }
  101. return 1;
  102. }
  103. int ScriptRect::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value)
  104. {
  105. if (xuihandle != myxuihandle)
  106. return SCRIPTRECT_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  107. switch (xmlattributeid)
  108. {
  109. case SCRIPTRECT_SETCOLOR:
  110. {
  111. ARGB32 prev_color = color;
  112. color.setElementName(value);
  113. //CUT color = WASABI_API_SKIN->skin_getColorElement((char*)value);
  114. if (color.v() != prev_color)
  115. {
  116. //CUT? ApplySkinFilters::apply(NULL, getXmlParamByName("gammagroup"), &color, BLTSIZE, BLTSIZE);
  117. resetPixel();
  118. invalidate();
  119. }
  120. }
  121. break;
  122. case SCRIPTRECT_GAMMAGROUP:
  123. {
  124. ARGB32 prev_color = color;
  125. color.setColorGroup(value);
  126. if (color.v() != prev_color)
  127. {
  128. resetPixel();
  129. invalidate();
  130. }
  131. }
  132. break;
  133. case SCRIPTRECT_SETFILLED:
  134. {
  135. int was_filled = filled;
  136. filled = WTOI(value);
  137. if (was_filled != filled) invalidate();
  138. }
  139. break;
  140. case SCRIPTRECT_EDGES:
  141. {
  142. int prev_edges = edges;
  143. ParamParser pp((const wchar_t *)value);
  144. edges = 0;
  145. edges |= !!pp.hasString(L"left") * LEFT;
  146. edges |= !!pp.hasString(L"right") * RIGHT;
  147. edges |= !!pp.hasString(L"top") * TOP;
  148. edges |= !!pp.hasString(L"bottom") * BOTTOM;
  149. if (edges != prev_edges) invalidate();
  150. }
  151. break;
  152. case SCRIPTRECT_THICKNESS:
  153. {
  154. int prev_thickness = thickness;
  155. thickness = WTOI(value);
  156. if (thickness < 1) thickness = 1;
  157. if (thickness != prev_thickness) invalidate();
  158. }
  159. break;
  160. default:
  161. return 0;
  162. }
  163. return 1;
  164. }
  165. void ScriptRect::resetPixel()
  166. {
  167. pixel.fillBits(0xFF000000 | RGBTOBGR(color.v()));
  168. }