Skip to content

Commit d414f54

Browse files
committed
Common: GUIButton supports wrapping text
1 parent 23959e9 commit d414f54

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

Common/gui/guibutton.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ Rect GUIButton::CalcGraphicRect(bool clipped)
168168
frame.Left++;
169169
frame.Top++;
170170
}
171-
rc = SumRects(rc, GUI::CalcTextGraphicalRect(_textToDraw, Font, frame, TextAlignment));
171+
172+
Rect text_rc = IsWrapText() ?
173+
GUI::CalcTextGraphicalRect(Lines.GetVector(), Lines.Count(), Font, get_font_linespacing(Font), frame, TextAlignment) :
174+
GUI::CalcTextGraphicalRect(_textToDraw, Font, frame, TextAlignment);
175+
rc = SumRects(rc, text_rc);
172176
}
173177
return rc;
174178
}
@@ -275,6 +279,15 @@ void GUIButton::SetText(const String &text)
275279
MarkChanged();
276280
}
277281

282+
void GUIButton::SetWrapText(bool on)
283+
{
284+
if (on != ((Flags & kGUICtrl_WrapText) != 0))
285+
{
286+
Flags = (Flags & ~kGUICtrl_WrapText) | kGUICtrl_WrapText * on;
287+
MarkChanged();
288+
}
289+
}
290+
278291
bool GUIButton::OnMouseDown()
279292
{
280293
if (!IsImageButton())
@@ -502,7 +515,12 @@ void GUIButton::DrawText(Bitmap *ds, int x, int y, bool draw_disabled)
502515
color_t text_color = ds->GetCompatibleColor(TextColor);
503516
if (draw_disabled)
504517
text_color = ds->GetCompatibleColor(8);
505-
GUI::DrawTextAligned(ds, _textToDraw, Font, text_color, frame, TextAlignment);
518+
519+
if (IsWrapText())
520+
GUI::DrawTextLinesAligned(ds, Lines.GetVector(), Lines.Count(), Font, get_font_linespacing(Font), text_color,
521+
frame, TextAlignment);
522+
else
523+
GUI::DrawTextAligned(ds, _textToDraw, Font, text_color, frame, TextAlignment);
506524
}
507525

508526
void GUIButton::DrawTextButton(Bitmap *ds, int x, int y, bool draw_disabled)

Common/gui/guibutton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class GUIButton : public GUIObject
8888
void SetPushedImage(int32_t image);
8989
void SetImages(int32_t normal, int32_t over, int32_t pushed);
9090
void SetText(const String &text);
91+
void SetWrapText(bool on);
9192

9293
// Events
9394
bool OnMouseDown() override;

Common/gui/guidefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ enum GUIControlFlags
139139
kGUICtrl_Clip = 0x0020, // only button
140140
kGUICtrl_Clickable = 0x0040,
141141
kGUICtrl_Translated = 0x0080, // 3.3.0.1132
142+
kGUICtrl_WrapText = 0x0100, // 3.6.2
142143
kGUICtrl_Deleted = 0x8000, // unused (probably remains from the old editor?)
143144

144145
kGUICtrl_DefFlags = kGUICtrl_Enabled | kGUICtrl_Visible | kGUICtrl_Clickable |

Common/gui/guiobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GUIObject
5151
bool IsEnabled() const { return (Flags & kGUICtrl_Enabled) != 0; }
5252
bool IsTranslated() const { return (Flags & kGUICtrl_Translated) != 0; }
5353
bool IsVisible() const { return (Flags & kGUICtrl_Visible) != 0; }
54+
bool IsWrapText() const { return (Flags & kGUICtrl_WrapText) != 0; }
5455
// overridable routine to determine whether the mouse is over the control
5556
virtual bool IsOverControl(int x, int y, int leeway) const;
5657
Size GetSize() const { return Size(_width, _height); }

Engine/gui/gui_engine.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,16 @@ void GUIListBox::PrepareTextToDraw(const String &text)
187187

188188
void GUIButton::PrepareTextToDraw()
189189
{
190-
_textToDraw = GUI::TransformTextForDrawing(_text, (Flags & kGUICtrl_Translated) != 0,
191-
(loaded_game_file_version >= kGameVersion_361));
190+
if (IsWrapText())
191+
{
192+
_textToDraw = _text;
193+
GUI::SplitLinesForDrawing(_text, (Flags & kGUICtrl_Translated) != 0, Lines, Font, _width);
194+
}
195+
else
196+
{
197+
_textToDraw = GUI::TransformTextForDrawing(_text, (Flags & kGUICtrl_Translated) != 0,
198+
(loaded_game_file_version >= kGameVersion_361));
199+
}
192200
}
193201

194202
} // namespace Common

0 commit comments

Comments
 (0)