mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 15:24:30 +01:00
Refactor TTF drawing (#21621)
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
#include "X8DrawingEngine.h"
|
||||
|
||||
#include "../Context.h"
|
||||
#include "../Game.h"
|
||||
#include "../Intro.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../core/Numerics.hpp"
|
||||
@@ -19,7 +18,6 @@
|
||||
#include "../interface/Window.h"
|
||||
#include "../ui/UiContext.h"
|
||||
#include "../util/Util.h"
|
||||
#include "../world/Climate.h"
|
||||
#include "Drawing.h"
|
||||
#include "IDrawingContext.h"
|
||||
#include "IDrawingEngine.h"
|
||||
@@ -743,3 +741,100 @@ void X8DrawingContext::DrawGlyph(DrawPixelInfo& dpi, const ImageId image, int32_
|
||||
{
|
||||
GfxDrawSpritePaletteSetSoftware(dpi, image, { x, y }, paletteMap);
|
||||
}
|
||||
|
||||
#ifndef NO_TTF
|
||||
template<bool TUseHinting>
|
||||
static void DrawTTFBitmapInternal(
|
||||
DrawPixelInfo& dpi, uint8_t colour, TTFSurface* surface, int32_t x, int32_t y, uint8_t hintingThreshold)
|
||||
{
|
||||
const int32_t surfaceWidth = surface->w;
|
||||
int32_t width = surfaceWidth;
|
||||
int32_t height = surface->h;
|
||||
|
||||
const int32_t overflowX = (dpi.x + dpi.width) - (x + width);
|
||||
const int32_t overflowY = (dpi.y + dpi.height) - (y + height);
|
||||
if (overflowX < 0)
|
||||
width += overflowX;
|
||||
if (overflowY < 0)
|
||||
height += overflowY;
|
||||
int32_t skipX = x - dpi.x;
|
||||
int32_t skipY = y - dpi.y;
|
||||
|
||||
auto src = static_cast<const uint8_t*>(surface->pixels);
|
||||
uint8_t* dst = dpi.bits;
|
||||
|
||||
if (skipX < 0)
|
||||
{
|
||||
width += skipX;
|
||||
src += -skipX;
|
||||
skipX = 0;
|
||||
}
|
||||
if (skipY < 0)
|
||||
{
|
||||
height += skipY;
|
||||
src += (-skipY * surfaceWidth);
|
||||
skipY = 0;
|
||||
}
|
||||
|
||||
dst += skipX;
|
||||
dst += skipY * (dpi.width + dpi.pitch);
|
||||
|
||||
const int32_t srcScanSkip = surfaceWidth - width;
|
||||
const int32_t dstScanSkip = dpi.width + dpi.pitch - width;
|
||||
for (int32_t yy = 0; yy < height; yy++)
|
||||
{
|
||||
for (int32_t xx = 0; xx < width; xx++)
|
||||
{
|
||||
if (*src != 0)
|
||||
{
|
||||
if constexpr (TUseHinting)
|
||||
{
|
||||
if (*src > 180)
|
||||
{
|
||||
// Centre of the glyph: use full colour.
|
||||
*dst = colour;
|
||||
}
|
||||
else if (*src > hintingThreshold)
|
||||
{
|
||||
*dst = BlendColours(colour, *dst);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst = colour;
|
||||
}
|
||||
}
|
||||
src++;
|
||||
dst++;
|
||||
}
|
||||
src += srcScanSkip;
|
||||
dst += dstScanSkip;
|
||||
}
|
||||
}
|
||||
#endif // NO_TTF
|
||||
|
||||
void X8DrawingContext::DrawTTFBitmap(
|
||||
DrawPixelInfo& dpi, TextDrawInfo* info, TTFSurface* surface, int32_t x, int32_t y, uint8_t hintingThreshold)
|
||||
{
|
||||
#ifndef NO_TTF
|
||||
const uint8_t fgColor = info->palette[1];
|
||||
const uint8_t bgColor = info->palette[3];
|
||||
|
||||
if (info->flags & TEXT_DRAW_FLAG_OUTLINE)
|
||||
{
|
||||
DrawTTFBitmapInternal<false>(dpi, bgColor, surface, x + 1, y, 0);
|
||||
DrawTTFBitmapInternal<false>(dpi, bgColor, surface, x - 1, y, 0);
|
||||
DrawTTFBitmapInternal<false>(dpi, bgColor, surface, x, y + 1, 0);
|
||||
DrawTTFBitmapInternal<false>(dpi, bgColor, surface, x, y - 1, 0);
|
||||
}
|
||||
if (info->flags & TEXT_DRAW_FLAG_INSET)
|
||||
{
|
||||
DrawTTFBitmapInternal<false>(dpi, bgColor, surface, x + 1, y + 1, 0);
|
||||
}
|
||||
|
||||
if (hintingThreshold > 0)
|
||||
DrawTTFBitmapInternal<true>(dpi, fgColor, surface, x, y, hintingThreshold);
|
||||
else
|
||||
DrawTTFBitmapInternal<false>(dpi, fgColor, surface, x, y, 0);
|
||||
#endif // NO_TTF
|
||||
}
|
||||
Reference in New Issue
Block a user