From e88f96a15c95204d08a79892a67a4826945ac4b7 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sun, 26 Sep 2021 19:55:16 +0200 Subject: [PATCH] Move StaticLayout out of header file --- src/openrct2/drawing/Text.cpp | 93 ++++++++++++++++++++--------------- src/openrct2/drawing/Text.h | 20 -------- 2 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 8782f5c85b..3246d772cb 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -18,56 +18,67 @@ static void DrawText( static void DrawText( rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, const TextPaint& paint, rct_string_id format, const void* args); -StaticLayout::StaticLayout(utf8string source, const TextPaint& paint, int32_t width) +class StaticLayout { - Buffer = source; - Paint = paint; +private: + utf8string Buffer; + TextPaint Paint; + int32_t LineCount = 0; + int32_t LineHeight; + int32_t MaxWidth; - MaxWidth = gfx_wrap_string(Buffer, width, paint.SpriteBase, &LineCount); - LineCount += 1; - LineHeight = font_get_line_height(paint.SpriteBase); -} - -void StaticLayout::Draw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords) -{ - TextPaint tempPaint = Paint; - - auto lineCoords = coords; - switch (Paint.Alignment) +public: + StaticLayout(utf8string source, const TextPaint& paint, int32_t width) { - case TextAlignment::LEFT: - break; - case TextAlignment::CENTRE: - lineCoords.x += MaxWidth / 2; - break; - case TextAlignment::RIGHT: - lineCoords.x += MaxWidth; - break; + Buffer = source; + Paint = paint; + + MaxWidth = gfx_wrap_string(Buffer, width, paint.SpriteBase, &LineCount); + LineCount += 1; + LineHeight = font_get_line_height(paint.SpriteBase); } - utf8* buffer = Buffer; - for (int32_t line = 0; line < LineCount; ++line) + + void Draw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords) { - DrawText(dpi, lineCoords, tempPaint, buffer); - tempPaint.Colour = TEXT_COLOUR_254; - buffer = get_string_end(buffer) + 1; - lineCoords.y += LineHeight; + TextPaint tempPaint = Paint; + + auto lineCoords = coords; + switch (Paint.Alignment) + { + case TextAlignment::LEFT: + break; + case TextAlignment::CENTRE: + lineCoords.x += MaxWidth / 2; + break; + case TextAlignment::RIGHT: + lineCoords.x += MaxWidth; + break; + } + utf8* buffer = Buffer; + for (int32_t line = 0; line < LineCount; ++line) + { + DrawText(dpi, lineCoords, tempPaint, buffer); + tempPaint.Colour = TEXT_COLOUR_254; + buffer = get_string_end(buffer) + 1; + lineCoords.y += LineHeight; + } } -} -int32_t StaticLayout::GetHeight() -{ - return LineHeight * LineCount; -} + int32_t GetHeight() const + { + return LineHeight * LineCount; + } -int32_t StaticLayout::GetWidth() -{ - return MaxWidth; -} + int32_t GetWidth() const + { + return MaxWidth; + } -int32_t StaticLayout::GetLineCount() -{ - return LineCount; -} + int32_t GetLineCount() const + { + return LineCount; + } +}; static void DrawText( rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, const TextPaint& paint, const_utf8string text, bool noFormatting) diff --git a/src/openrct2/drawing/Text.h b/src/openrct2/drawing/Text.h index 87f3c63cfd..40261dabb8 100644 --- a/src/openrct2/drawing/Text.h +++ b/src/openrct2/drawing/Text.h @@ -124,26 +124,6 @@ struct TextPaint } }; -class StaticLayout -{ -private: - utf8string Buffer; - TextPaint Paint; - int32_t LineCount = 0; - int32_t LineHeight; - int32_t MaxWidth; - - StaticLayout(); - StaticLayout(const StaticLayout&); - -public: - StaticLayout(utf8string source, const TextPaint& paint, int32_t width); - void Draw(rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords); - int32_t GetHeight(); - int32_t GetWidth(); - int32_t GetLineCount(); -}; - void DrawTextBasic( rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, rct_string_id format, const Formatter& ft = {}, TextPaint textPaint = {});