mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-18 03:59:09 +00:00
Codechange: Add version of DrawStringMultiLine that performs clipping test. (#14189)
Normally DrawStringMultiLine does not perform any clipping, as the return value may be needed if it the text is not drawn. In some specific cases the height is already known, so it is possible to test for clipping, which can cut down on layouting time for text which won't be visible.
This commit is contained in:
@@ -194,14 +194,14 @@ public:
|
||||
|
||||
case WID_EM_MESSAGE:
|
||||
if (this->detailed_msg.empty()) {
|
||||
DrawStringMultiLine(r, this->summary_msg.GetDecodedString(), TC_FROMSTRING, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(r, this->summary_msg.GetDecodedString(), TC_FROMSTRING, SA_CENTER);
|
||||
} else if (this->extra_msg.empty()) {
|
||||
/* Extra space when message is shorter than company face window */
|
||||
int extra = (r.Height() - this->height_summary - this->height_detailed - WidgetDimensions::scaled.vsep_wide) / 2;
|
||||
|
||||
/* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */
|
||||
DrawStringMultiLine(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLine(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(r.WithHeight(this->height_summary + extra, false), this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(r.WithHeight(this->height_detailed + extra, true), this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
} else {
|
||||
/* Extra space when message is shorter than company face window */
|
||||
int extra = (r.Height() - this->height_summary - this->height_detailed - this->height_extra - (WidgetDimensions::scaled.vsep_wide * 2)) / 3;
|
||||
@@ -210,9 +210,9 @@ public:
|
||||
Rect top_section = r.WithHeight(this->height_summary + extra, false);
|
||||
Rect bottom_section = r.WithHeight(this->height_extra + extra, true);
|
||||
Rect middle_section = { top_section.left, top_section.bottom, top_section.right, bottom_section.top };
|
||||
DrawStringMultiLine(top_section, this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLine(middle_section, this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLine(bottom_section, this->extra_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(top_section, this->summary_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(middle_section, this->detailed_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
DrawStringMultiLineWithClipping(bottom_section, this->extra_msg.GetDecodedString(), TC_WHITE, SA_CENTER);
|
||||
}
|
||||
|
||||
break;
|
||||
|
Reference in New Issue
Block a user