• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Small footprint UI library for hardware accelerated games & applications


Commit MetaInfo

Revision39faea391e72bbedf1d6278827cfb4708597dace (tree)
Time2016-11-06 04:38:51
AuthorEmil Segerås <emilsegers@gmai...>
CommiterEmil Segerås

Log Message

Moved paint related arguments into TBPaintProps.

Change Summary

Incremental Difference

--- a/src/tb/tb_style_edit.cpp
+++ b/src/tb/tb_style_edit.cpp
@@ -657,9 +657,7 @@ TBTextProps::Data *TBTextProps::Push()
657657 return nullptr;
658658 }
659659 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;
663661 data = next;
664662 return data;
665663 }
@@ -1128,10 +1126,16 @@ void TBBlock::BuildSelectionRegion(int32 translate_x, int32 translate_y, TBTextP
11281126 if (!styledit->selection.IsBlockSelected(this))
11291127 return;
11301128
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+
11311135 TBTextFragment *fragment = fragments.GetFirst();
11321136 while (fragment)
11331137 {
1134- fragment->BuildSelectionRegion(this, translate_x, translate_y + ypos, props, bg_region, fg_region);
1138+ fragment->BuildSelectionRegion(&paint_props, bg_region, fg_region);
11351139 fragment = fragment->GetNext();
11361140 }
11371141 }
@@ -1140,10 +1144,16 @@ void TBBlock::Paint(int32 translate_x, int32 translate_y, TBTextProps *props)
11401144 {
11411145 TMPDEBUG(styledit->listener->DrawRect(TBRect(translate_x, translate_y + ypos, styledit->layout_width, height), TBColor(255, 200, 0, 128)));
11421146
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+
11431153 TBTextFragment *fragment = fragments.GetFirst();
11441154 while (fragment)
11451155 {
1146- fragment->Paint(this, translate_x, translate_y + ypos, props);
1156+ fragment->Paint(&paint_props);
11471157 fragment = fragment->GetNext();
11481158 }
11491159 }
@@ -1170,15 +1180,15 @@ void TBTextFragment::UpdateContentPos(const TBBlock *block)
11701180 content->UpdatePos(block, xpos, ypos + block->ypos);
11711181 }
11721182
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)
11751184 {
1185+ const TBBlock *block = props->block;
11761186 if (!block->styledit->selection.IsFragmentSelected(block, this))
11771187 return;
11781188
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();
11821192
11831193 if (content)
11841194 {
@@ -1201,18 +1211,19 @@ void TBTextFragment::BuildSelectionRegion(const TBBlock *block, int32 translate_
12011211 bg_region.IncludeRect(TBRect(x + s1x, y, s2x, GetHeight(block, font)));
12021212 }
12031213
1204-void TBTextFragment::Paint(const TBBlock *block, int32 translate_x, int32 translate_y, TBTextProps *props)
1214+void TBTextFragment::Paint(const TBPaintProps *props)
12051215 {
1206- TBStyleEditListener *listener = block->styledit->listener;
1216+ TBStyleEditListener *listener = props->block->styledit->listener;
12071217
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;
12121223
12131224 if (content)
12141225 {
1215- content->Paint(block, this, translate_x, translate_y, props);
1226+ content->Paint(props, this);
12161227 return;
12171228 }
12181229 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
12381249 else if (!IsTab() && !IsBreak() && !IsSpace())
12391250 listener->DrawString(x, y, font, color, Str(block), len);
12401251
1241- if (props->data->underline)
1252+ if (props->props->data->underline)
12421253 {
12431254 int line_h = font->GetHeight() / 16;
12441255 line_h = MAX(line_h, 1);
--- a/src/tb/tb_style_edit.h
+++ b/src/tb/tb_style_edit.h
@@ -166,6 +166,17 @@ public:
166166 Data *data;
167167 };
168168
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+
169180 /** A block of text (a line, that might be wrapped) */
170181
171182 class TBBlock : public TBLinkOf<TBBlock>
@@ -280,9 +291,8 @@ public:
280291
281292 void UpdateContentPos(const TBBlock *block);
282293
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);
286296 void Click(const TBBlock *block, int button, uint32 modifierkeys);
287297
288298 bool IsText() const { return !IsEmbedded(); }
@@ -308,8 +318,7 @@ public:
308318 public:
309319 int16 xpos, ypos;
310320 uint16 ofs, len;
311- uint16 line_ypos;
312- uint16 line_height;
321+ uint16 line_ypos, line_height;
313322 union {
314323 struct {
315324 uint32 is_break : 1;
--- a/src/tb/tb_style_edit_content.cpp
+++ b/src/tb/tb_style_edit_content.cpp
@@ -52,16 +52,16 @@ TBTextFragmentContentHR::TBTextFragmentContentHR(int32 width_in_percent, int32 h
5252 {
5353 }
5454
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)
5656 {
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;
5959
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;
6262
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);
6565 }
6666
6767 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,
7070
7171 // ============================================================================
7272
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)
7474 {
75- if (TBTextProps::Data *data = props->Push())
75+ if (TBTextProps::Data *data = props->props->Push())
7676 data->underline = true;
7777 }
7878
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)
8080 {
81- if (TBTextProps::Data *data = props->Push())
81+ if (TBTextProps::Data *data = props->props->Push())
8282 data->text_color = color;
8383 }
8484
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)
8686 {
87- props->Pop();
87+ props->props->Pop();
8888 }
8989
9090 } // namespace tb
--- a/src/tb/tb_style_edit_content.h
+++ b/src/tb/tb_style_edit_content.h
@@ -22,7 +22,7 @@ public:
2222 /** Update the position of the content, relative to the first line of text (no scrolling applied). */
2323 virtual void UpdatePos(const TBBlock *block, int x, int y) {}
2424
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) {}
2626 virtual void Click(const TBBlock *block, TBTextFragment *fragment, int button, uint32 modifierkeys) {}
2727 virtual int32 GetWidth(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment) { return 0; }
2828 virtual int32 GetHeight(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment) { return 0; }
@@ -41,7 +41,7 @@ class TBTextFragmentContentHR : public TBTextFragmentContent
4141 public:
4242 TBTextFragmentContentHR(int32 width_in_percent, int32 height);
4343
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);
4545 virtual int32 GetWidth(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment);
4646 virtual int32 GetHeight(const TBBlock *block, TBFontFace *font, TBTextFragment *fragment);
4747 private:
@@ -54,7 +54,7 @@ class TBTextFragmentContentUnderline : public TBTextFragmentContent
5454 {
5555 public:
5656 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);
5858 virtual bool GetAllowBreakBefore(const TBBlock *block) { return true; }
5959 virtual bool GetAllowBreakAfter(const TBBlock *block) { return false; }
6060 };
@@ -66,7 +66,7 @@ class TBTextFragmentContentTextColor : public TBTextFragmentContent
6666 public:
6767 TBColor color;
6868 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);
7070 virtual bool GetAllowBreakBefore(const TBBlock *block) { return true; }
7171 virtual bool GetAllowBreakAfter(const TBBlock *block) { return false; }
7272 };
@@ -76,7 +76,7 @@ public:
7676 class TBTextFragmentContentStylePop : public TBTextFragmentContent
7777 {
7878 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);
8080 virtual bool GetAllowBreakBefore(const TBBlock *block) { return false; }
8181 virtual bool GetAllowBreakAfter(const TBBlock *block) { return true; }
8282 };