Small footprint UI library for hardware accelerated games & applications
Revision | 39faea391e72bbedf1d6278827cfb4708597dace (tree) |
---|---|
Time | 2016-11-06 04:38:51 |
Author | Emil Segerås <emilsegers@gmai...> |
Commiter | Emil Segerås |
Moved paint related arguments into TBPaintProps.
@@ -657,9 +657,7 @@ TBTextProps::Data *TBTextProps::Push() | ||
657 | 657 | return nullptr; |
658 | 658 | } |
659 | 659 | Data *next = list.Get(next_index++); |
660 | - next->font_desc = data->font_desc; | |
661 | - next->text_color = data->text_color; | |
662 | - next->underline = data->underline; | |
660 | + *next = *data; | |
663 | 661 | data = next; |
664 | 662 | return data; |
665 | 663 | } |
@@ -1128,10 +1126,16 @@ void TBBlock::BuildSelectionRegion(int32 translate_x, int32 translate_y, TBTextP | ||
1128 | 1126 | if (!styledit->selection.IsBlockSelected(this)) |
1129 | 1127 | return; |
1130 | 1128 | |
1129 | + TBPaintProps paint_props; | |
1130 | + paint_props.block = this; | |
1131 | + paint_props.props = props; | |
1132 | + paint_props.translate_x = translate_x; | |
1133 | + paint_props.translate_y = translate_y + ypos; | |
1134 | + | |
1131 | 1135 | TBTextFragment *fragment = fragments.GetFirst(); |
1132 | 1136 | while (fragment) |
1133 | 1137 | { |
1134 | - fragment->BuildSelectionRegion(this, translate_x, translate_y + ypos, props, bg_region, fg_region); | |
1138 | + fragment->BuildSelectionRegion(&paint_props, bg_region, fg_region); | |
1135 | 1139 | fragment = fragment->GetNext(); |
1136 | 1140 | } |
1137 | 1141 | } |
@@ -1140,10 +1144,16 @@ void TBBlock::Paint(int32 translate_x, int32 translate_y, TBTextProps *props) | ||
1140 | 1144 | { |
1141 | 1145 | TMPDEBUG(styledit->listener->DrawRect(TBRect(translate_x, translate_y + ypos, styledit->layout_width, height), TBColor(255, 200, 0, 128))); |
1142 | 1146 | |
1147 | + TBPaintProps paint_props; | |
1148 | + paint_props.block = this; | |
1149 | + paint_props.props = props; | |
1150 | + paint_props.translate_x = translate_x; | |
1151 | + paint_props.translate_y = translate_y + ypos; | |
1152 | + | |
1143 | 1153 | TBTextFragment *fragment = fragments.GetFirst(); |
1144 | 1154 | while (fragment) |
1145 | 1155 | { |
1146 | - fragment->Paint(this, translate_x, translate_y + ypos, props); | |
1156 | + fragment->Paint(&paint_props); | |
1147 | 1157 | fragment = fragment->GetNext(); |
1148 | 1158 | } |
1149 | 1159 | } |
@@ -1170,15 +1180,15 @@ void TBTextFragment::UpdateContentPos(const TBBlock *block) | ||
1170 | 1180 | content->UpdatePos(block, xpos, ypos + block->ypos); |
1171 | 1181 | } |
1172 | 1182 | |
1173 | -void TBTextFragment::BuildSelectionRegion(const TBBlock *block, int32 translate_x, int32 translate_y, TBTextProps *props, | |
1174 | - TBRegion &bg_region, TBRegion &fg_region) | |
1183 | +void TBTextFragment::BuildSelectionRegion(const TBPaintProps *props, TBRegion &bg_region, TBRegion &fg_region) | |
1175 | 1184 | { |
1185 | + const TBBlock *block = props->block; | |
1176 | 1186 | if (!block->styledit->selection.IsFragmentSelected(block, this)) |
1177 | 1187 | return; |
1178 | 1188 | |
1179 | - int x = translate_x + xpos; | |
1180 | - int y = translate_y + ypos; | |
1181 | - TBFontFace *font = props->GetFont(); | |
1189 | + const int x = props->translate_x + xpos; | |
1190 | + const int y = props->translate_y + ypos; | |
1191 | + TBFontFace *font = props->props->GetFont(); | |
1182 | 1192 | |
1183 | 1193 | if (content) |
1184 | 1194 | { |
@@ -1201,18 +1211,19 @@ void TBTextFragment::BuildSelectionRegion(const TBBlock *block, int32 translate_ | ||
1201 | 1211 | bg_region.IncludeRect(TBRect(x + s1x, y, s2x, GetHeight(block, font))); |
1202 | 1212 | } |
1203 | 1213 | |
1204 | -void TBTextFragment::Paint(const TBBlock *block, int32 translate_x, int32 translate_y, TBTextProps *props) | |
1214 | +void TBTextFragment::Paint(const TBPaintProps *props) | |
1205 | 1215 | { |
1206 | - TBStyleEditListener *listener = block->styledit->listener; | |
1216 | + TBStyleEditListener *listener = props->block->styledit->listener; | |
1207 | 1217 | |
1208 | - int x = translate_x + xpos; | |
1209 | - int y = translate_y + ypos; | |
1210 | - TBColor color = props->data->text_color; | |
1211 | - TBFontFace *font = props->GetFont(); | |
1218 | + const int x = props->translate_x + xpos; | |
1219 | + const int y = props->translate_y + ypos; | |
1220 | + const TBColor color = props->props->data->text_color; | |
1221 | + TBFontFace *font = props->props->GetFont(); | |
1222 | + TBBlock *block = props->block; | |
1212 | 1223 | |
1213 | 1224 | if (content) |
1214 | 1225 | { |
1215 | - content->Paint(block, this, translate_x, translate_y, props); | |
1226 | + content->Paint(props, this); | |
1216 | 1227 | return; |
1217 | 1228 | } |
1218 | 1229 | TMPDEBUG(listener->DrawRect(TBRect(x, y, GetWidth(block, font), GetHeight(block, font)), TBColor(255, 255, 255, 128))); |
@@ -1238,7 +1249,7 @@ void TBTextFragment::Paint(const TBBlock *block, int32 translate_x, int32 transl | ||
1238 | 1249 | else if (!IsTab() && !IsBreak() && !IsSpace()) |
1239 | 1250 | listener->DrawString(x, y, font, color, Str(block), len); |
1240 | 1251 | |
1241 | - if (props->data->underline) | |
1252 | + if (props->props->data->underline) | |
1242 | 1253 | { |
1243 | 1254 | int line_h = font->GetHeight() / 16; |
1244 | 1255 | line_h = MAX(line_h, 1); |
@@ -166,6 +166,17 @@ public: | ||
166 | 166 | Data *data; |
167 | 167 | }; |
168 | 168 | |
169 | +/** TBPaintProps holds paint related data during paint of TBStyleEdit. */ | |
170 | + | |
171 | +class TBPaintProps | |
172 | +{ | |
173 | +public: | |
174 | + TBBlock *block; | |
175 | + TBTextProps *props; | |
176 | + int32 translate_x; | |
177 | + int32 translate_y; | |
178 | +}; | |
179 | + | |
169 | 180 | /** A block of text (a line, that might be wrapped) */ |
170 | 181 | |
171 | 182 | class TBBlock : public TBLinkOf<TBBlock> |
@@ -280,9 +291,8 @@ public: | ||
280 | 291 | |
281 | 292 | void UpdateContentPos(const TBBlock *block); |
282 | 293 | |
283 | - void BuildSelectionRegion(const TBBlock *block, int32 translate_x, int32 translate_y, TBTextProps *props, | |
284 | - TBRegion &bg_region, TBRegion &fg_region); | |
285 | - void Paint(const TBBlock *block, int32 translate_x, int32 translate_y, TBTextProps *props); | |
294 | + void BuildSelectionRegion(const TBPaintProps *props, TBRegion &bg_region, TBRegion &fg_region); | |
295 | + void Paint(const TBPaintProps *props); | |
286 | 296 | void Click(const TBBlock *block, int button, uint32 modifierkeys); |
287 | 297 | |
288 | 298 | bool IsText() const { return !IsEmbedded(); } |
@@ -308,8 +318,7 @@ public: | ||
308 | 318 | public: |
309 | 319 | int16 xpos, ypos; |
310 | 320 | uint16 ofs, len; |
311 | - uint16 line_ypos; | |
312 | - uint16 line_height; | |
321 | + uint16 line_ypos, line_height; | |
313 | 322 | union { |
314 | 323 | struct { |
315 | 324 | uint32 is_break : 1; |
@@ -52,16 +52,16 @@ TBTextFragmentContentHR::TBTextFragmentContentHR(int32 width_in_percent, int32 h | ||
52 | 52 | { |
53 | 53 | } |
54 | 54 | |
55 | -void TBTextFragmentContentHR::Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) | |
55 | +void TBTextFragmentContentHR::Paint(const TBPaintProps *props, TBTextFragment *fragment) | |
56 | 56 | { |
57 | - int x = translate_x + fragment->xpos; | |
58 | - int y = translate_y + fragment->ypos; | |
57 | + int x = props->translate_x + fragment->xpos; | |
58 | + int y = props->translate_y + fragment->ypos; | |
59 | 59 | |
60 | - int w = block->styledit->layout_width * width_in_percent / 100; | |
61 | - x += (block->styledit->layout_width - w) / 2; | |
60 | + int w = props->block->styledit->layout_width * width_in_percent / 100; | |
61 | + x += (props->block->styledit->layout_width - w) / 2; | |
62 | 62 | |
63 | - TBStyleEditListener *listener = block->styledit->listener; | |
64 | - listener->DrawRectFill(TBRect(x, y, w, height), props->data->text_color); | |
63 | + TBStyleEditListener *listener = props->block->styledit->listener; | |
64 | + listener->DrawRectFill(TBRect(x, y, w, height), props->props->data->text_color); | |
65 | 65 | } |
66 | 66 | |
67 | 67 | int32 TBTextFragmentContentHR::GetWidth(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment) { return Max(block->styledit->layout_width, 0); } |
@@ -70,21 +70,21 @@ int32 TBTextFragmentContentHR::GetHeight(const TBBlock *block, TBFontFace *font, | ||
70 | 70 | |
71 | 71 | // ============================================================================ |
72 | 72 | |
73 | -void TBTextFragmentContentUnderline::Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) | |
73 | +void TBTextFragmentContentUnderline::Paint(const TBPaintProps *props, TBTextFragment *fragment) | |
74 | 74 | { |
75 | - if (TBTextProps::Data *data = props->Push()) | |
75 | + if (TBTextProps::Data *data = props->props->Push()) | |
76 | 76 | data->underline = true; |
77 | 77 | } |
78 | 78 | |
79 | -void TBTextFragmentContentTextColor::Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) | |
79 | +void TBTextFragmentContentTextColor::Paint(const TBPaintProps *props, TBTextFragment *fragment) | |
80 | 80 | { |
81 | - if (TBTextProps::Data *data = props->Push()) | |
81 | + if (TBTextProps::Data *data = props->props->Push()) | |
82 | 82 | data->text_color = color; |
83 | 83 | } |
84 | 84 | |
85 | -void TBTextFragmentContentStylePop::Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) | |
85 | +void TBTextFragmentContentStylePop::Paint(const TBPaintProps *props, TBTextFragment *fragment) | |
86 | 86 | { |
87 | - props->Pop(); | |
87 | + props->props->Pop(); | |
88 | 88 | } |
89 | 89 | |
90 | 90 | } // namespace tb |
@@ -22,7 +22,7 @@ public: | ||
22 | 22 | /** Update the position of the content, relative to the first line of text (no scrolling applied). */ |
23 | 23 | virtual void UpdatePos(const TBBlock *block, int x, int y) {} |
24 | 24 | |
25 | - virtual void Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props) {} | |
25 | + virtual void Paint(const TBPaintProps *props, TBTextFragment *fragment) {} | |
26 | 26 | virtual void Click(const TBBlock *block, TBTextFragment *fragment, int button, uint32 modifierkeys) {} |
27 | 27 | virtual int32 GetWidth(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment) { return 0; } |
28 | 28 | virtual int32 GetHeight(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment) { return 0; } |
@@ -41,7 +41,7 @@ class TBTextFragmentContentHR : public TBTextFragmentContent | ||
41 | 41 | public: |
42 | 42 | TBTextFragmentContentHR(int32 width_in_percent, int32 height); |
43 | 43 | |
44 | - virtual void Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props); | |
44 | + virtual void Paint(const TBPaintProps *props, TBTextFragment *fragment); | |
45 | 45 | virtual int32 GetWidth(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment); |
46 | 46 | virtual int32 GetHeight(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment); |
47 | 47 | private: |
@@ -54,7 +54,7 @@ class TBTextFragmentContentUnderline : public TBTextFragmentContent | ||
54 | 54 | { |
55 | 55 | public: |
56 | 56 | TBTextFragmentContentUnderline() {} |
57 | - virtual void Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props); | |
57 | + virtual void Paint(const TBPaintProps *props, TBTextFragment *fragment); | |
58 | 58 | virtual bool GetAllowBreakBefore(const TBBlock *block) { return true; } |
59 | 59 | virtual bool GetAllowBreakAfter(const TBBlock *block) { return false; } |
60 | 60 | }; |
@@ -66,7 +66,7 @@ class TBTextFragmentContentTextColor : public TBTextFragmentContent | ||
66 | 66 | public: |
67 | 67 | TBColor color; |
68 | 68 | TBTextFragmentContentTextColor(const TBColor &color) : color(color) {} |
69 | - virtual void Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props); | |
69 | + virtual void Paint(const TBPaintProps *props, TBTextFragment *fragment); | |
70 | 70 | virtual bool GetAllowBreakBefore(const TBBlock *block) { return true; } |
71 | 71 | virtual bool GetAllowBreakAfter(const TBBlock *block) { return false; } |
72 | 72 | }; |
@@ -76,7 +76,7 @@ public: | ||
76 | 76 | class TBTextFragmentContentStylePop : public TBTextFragmentContent |
77 | 77 | { |
78 | 78 | public: |
79 | - virtual void Paint(const TBBlock *block, TBTextFragment *fragment, int32 translate_x, int32 translate_y, TBTextProps *props); | |
79 | + virtual void Paint(const TBPaintProps *props, TBTextFragment *fragment); | |
80 | 80 | virtual bool GetAllowBreakBefore(const TBBlock *block) { return false; } |
81 | 81 | virtual bool GetAllowBreakAfter(const TBBlock *block) { return true; } |
82 | 82 | }; |