From 2cb54020692fd95129b60f9fb5c5e7eab22d11d2 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 26 Jun 2020 19:33:04 +0200 Subject: [PATCH] Introduce widget::textTop --- src/openrct2-ui/interface/Widget.cpp | 22 ++++++---------------- src/openrct2/interface/Window.h | 8 ++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/openrct2-ui/interface/Widget.cpp b/src/openrct2-ui/interface/Widget.cpp index c5ecb02c5c..87c863b9aa 100644 --- a/src/openrct2-ui/interface/Widget.cpp +++ b/src/openrct2-ui/interface/Widget.cpp @@ -345,12 +345,7 @@ static void widget_text_centred(rct_drawpixelinfo* dpi, rct_window* w, rct_widge int32_t r = w->windowPos.x + widget->right; if (widget->type == WWT_BUTTON || widget->type == WWT_TABLE_HEADER) - { - if (widget->height() >= 10) - topLeft.y += std::max(widget->top, widget->top + (widget->height() / 2) - 5); - else - topLeft.y += widget->top - 1; - } + topLeft.y += widget->textTop(); else topLeft.y += widget->top; @@ -390,10 +385,7 @@ static void widget_text(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex w if (widget->type == WWT_BUTTON || widget->type == WWT_DROPDOWN || widget->type == WWT_SPINNER || widget->type == WWT_TABLE_HEADER) { - if (widget->height() >= 10) - t = w->windowPos.y + std::max(widget->top, widget->top + (widget->height() / 2) - 5); - else - t = w->windowPos.y + widget->top - 1; + t = w->windowPos.y + widget->textTop(); } else t = w->windowPos.y + widget->top; @@ -1054,10 +1046,7 @@ static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg gCurrentFontFlags = 0; // Figure out where the text should be positioned vertically. - if (widget->height() >= 10) - t = w->windowPos.y + std::max(widget->top, widget->top + (widget->height() / 2) - 5); - else - t = w->windowPos.y + widget->top - 1; + t = w->windowPos.y + widget->textTop(); if (!active || gTextInput == nullptr) { @@ -1076,7 +1065,7 @@ static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg // +13 for cursor when max length. gfx_wrap_string(wrapped_string, r - l - 5 - 6, &no_lines, &font_height); - gfx_draw_string(dpi, wrapped_string, w->colours[1], { l + 2, t + 1 }); + gfx_draw_string(dpi, wrapped_string, w->colours[1], { l + 2, t }); size_t string_length = get_string_size(wrapped_string) - 1; @@ -1098,6 +1087,7 @@ static void widget_text_box_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg if (gTextBoxFrameNo <= 15) { colour = ColourMapA[w->colours[1]].mid_light; - gfx_fill_rect(dpi, cur_x, t + (widget->height() - 1), cur_x + width, t + (widget->height() - 1), colour + 5); + auto y = t + (widget->height() - 1); + gfx_fill_rect(dpi, cur_x, y, cur_x + width, y, colour + 5); } } diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index c813949328..91559d93d5 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -118,6 +118,14 @@ struct rct_widget { return (top + bottom) / 2; } + + int16_t textTop() const + { + if (height() >= 10) + return std::max(top, top + (height() / 2) - 5); + else + return top - 1; + } }; /**