Use TitleCase on StaticLayout (#12155)

This commit is contained in:
Tulio Leao 2020-07-08 09:43:23 -03:00 committed by GitHub
parent f862935723
commit 2ee1a9d9db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 21 deletions

View File

@ -19,62 +19,62 @@ static void DrawText(rct_drawpixelinfo* dpi, int32_t x, int32_t y, TextPaint* pa
StaticLayout::StaticLayout(utf8string source, TextPaint paint, int32_t width) StaticLayout::StaticLayout(utf8string source, TextPaint paint, int32_t width)
{ {
_buffer = source; Buffer = source;
_paint = paint; Paint = paint;
int32_t fontSpriteBase; int32_t fontSpriteBase;
gCurrentFontSpriteBase = paint.SpriteBase; gCurrentFontSpriteBase = paint.SpriteBase;
_maxWidth = gfx_wrap_string(_buffer, width, &_lineCount, &fontSpriteBase); MaxWidth = gfx_wrap_string(Buffer, width, &LineCount, &fontSpriteBase);
_lineCount += 1; LineCount += 1;
_lineHeight = font_get_line_height(fontSpriteBase); LineHeight = font_get_line_height(fontSpriteBase);
} }
void StaticLayout::Draw(rct_drawpixelinfo* dpi, int32_t x, int32_t y) void StaticLayout::Draw(rct_drawpixelinfo* dpi, int32_t x, int32_t y)
{ {
gCurrentFontFlags = 0; gCurrentFontFlags = 0;
gCurrentFontSpriteBase = _paint.SpriteBase; gCurrentFontSpriteBase = Paint.SpriteBase;
TextPaint tempPaint = _paint; TextPaint tempPaint = Paint;
gCurrentFontFlags = 0; gCurrentFontFlags = 0;
int32_t lineY = y; int32_t lineY = y;
int32_t lineX = x; int32_t lineX = x;
switch (_paint.Alignment) switch (Paint.Alignment)
{ {
case TextAlignment::LEFT: case TextAlignment::LEFT:
lineX = x; lineX = x;
break; break;
case TextAlignment::CENTRE: case TextAlignment::CENTRE:
lineX = x + _maxWidth / 2; lineX = x + MaxWidth / 2;
break; break;
case TextAlignment::RIGHT: case TextAlignment::RIGHT:
lineX = x + _maxWidth; lineX = x + MaxWidth;
break; break;
} }
utf8* buffer = _buffer; utf8* buffer = Buffer;
for (int32_t line = 0; line < _lineCount; ++line) for (int32_t line = 0; line < LineCount; ++line)
{ {
DrawText(dpi, lineX, lineY, &tempPaint, buffer); DrawText(dpi, lineX, lineY, &tempPaint, buffer);
tempPaint.Colour = TEXT_COLOUR_254; tempPaint.Colour = TEXT_COLOUR_254;
buffer = get_string_end(buffer) + 1; buffer = get_string_end(buffer) + 1;
lineY += _lineHeight; lineY += LineHeight;
} }
} }
int32_t StaticLayout::GetHeight() int32_t StaticLayout::GetHeight()
{ {
return _lineHeight * _lineCount; return LineHeight * LineCount;
} }
int32_t StaticLayout::GetWidth() int32_t StaticLayout::GetWidth()
{ {
return _maxWidth; return MaxWidth;
} }
int32_t StaticLayout::GetLineCount() int32_t StaticLayout::GetLineCount()
{ {
return _lineCount; return LineCount;
} }
static void DrawText(rct_drawpixelinfo* dpi, int32_t x, int32_t y, TextPaint* paint, const_utf8string text) static void DrawText(rct_drawpixelinfo* dpi, int32_t x, int32_t y, TextPaint* paint, const_utf8string text)

View File

@ -31,11 +31,11 @@ struct TextPaint
class StaticLayout class StaticLayout
{ {
private: private:
utf8string _buffer; utf8string Buffer;
TextPaint _paint; TextPaint Paint;
int32_t _lineCount = 0; int32_t LineCount = 0;
int32_t _lineHeight; int32_t LineHeight;
int32_t _maxWidth; int32_t MaxWidth;
StaticLayout(); StaticLayout();
StaticLayout(const StaticLayout&); StaticLayout(const StaticLayout&);