1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

implement utf8, part 20 (improve font sizes and offsets)

This commit is contained in:
IntelOrca
2015-07-30 08:20:27 +01:00
parent 52d5732826
commit 4d003ad00a

View File

@@ -22,6 +22,7 @@
#include "../addresses.h"
#include "../localisation/localisation.h"
#include "../sprites.h"
#include "../world/map.h"
#include "drawing.h"
static int ttf_get_string_width(const utf8 *text);
@@ -29,10 +30,9 @@ static void ttf_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, in
static bool _ttfInitialised = false;
static TTF_Font *_ttfFont[4] = { NULL };
int _ttfFontOffsetX = 0;
int _ttfFontOffsetY = 0;
static const int TTFFontSizes[] = { 9, 9, 11, 13 };
static const int TTFFontSizes[] = { 9, 11, 12, 13 };
static const rct_xy16 TTFFontOffsets[] = { { -1, -2 }, { -1, -2 }, { -1, -3 }, { -1, -3 } };
#define TTF_SURFACE_CACHE_SIZE 256
#define TTF_GETWIDTH_CACHE_SIZE 1024
@@ -927,8 +927,6 @@ bool ttf_initialise()
}
}
_ttfFontOffsetX = 1;
_ttfFontOffsetY = -2;
_ttfInitialised = true;
}
return true;
@@ -953,21 +951,26 @@ void ttf_dispose()
_ttfInitialised = false;
}
TTF_Font *ttf_get_font_from_sprite_base(uint16 spriteBase)
int ttf_get_font_size_from_sprite_base(uint16 spriteBase)
{
switch (spriteBase) {
case FONT_SPRITE_BASE_TINY:
return _ttfFont[0];
return 0;
case FONT_SPRITE_BASE_SMALL:
return _ttfFont[1];
return 1;
default:
case FONT_SPRITE_BASE_MEDIUM:
return _ttfFont[2];
return 2;
case FONT_SPRITE_BASE_BIG:
return _ttfFont[3];
return 3;
}
}
TTF_Font *ttf_get_font_from_sprite_base(uint16 spriteBase)
{
return _ttfFont[ttf_get_font_size_from_sprite_base(spriteBase)];
}
enum {
TEXT_DRAW_FLAG_INSET = 1 << 0,
TEXT_DRAW_FLAG_OUTLINE = 1 << 1,
@@ -1029,9 +1032,10 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
return;
}
}
int drawX = info->x + _ttfFontOffsetX;
int drawY = info->y + _ttfFontOffsetY;
int fontSize = ttf_get_font_size_from_sprite_base(info->font_sprite_base);
int drawX = info->x + TTFFontOffsets[fontSize].x;
int drawY = info->y + TTFFontOffsets[fontSize].y;
int width = surface->w;
int height = surface->h;