re3/src/render/Font.h

157 lines
4.3 KiB
C
Raw Normal View History

2019-05-22 18:28:53 +00:00
#pragma once
struct CFontDetails
{
CRGBA color;
float scaleX;
float scaleY;
float slant;
float slantRefX;
float slantRefY;
bool justify;
bool centre;
bool rightJustify;
bool background;
bool backgroundOnlyText;
bool proportional;
float alphaFade;
CRGBA backgroundColor;
float wrapX;
float centreSize;
float rightJustifyWrap;
int16 style;
int32 bank;
int16 dropShadowPosition;
CRGBA dropColor;
};
class CSprite2d;
2019-05-30 22:32:50 +00:00
enum {
2019-05-30 22:37:14 +00:00
FONT_BANK,
FONT_PAGER,
FONT_HEADING,
2020-04-17 05:54:14 +00:00
MAX_FONTS
2019-05-30 22:32:50 +00:00
};
enum {
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT,
};
2020-03-29 06:35:13 +00:00
#ifdef MORE_LANGUAGES
enum
{
FONT_LANGSET_EFIGS,
FONT_LANGSET_RUSSIAN
};
#endif
2019-05-22 18:28:53 +00:00
class CFont
{
2020-03-29 06:35:13 +00:00
#ifdef MORE_LANGUAGES
2020-04-17 05:54:14 +00:00
static int16 Size[2][MAX_FONTS][193];
2020-03-29 06:35:13 +00:00
static uint8 LanguageSet;
static int32 Slot;
#else
2020-04-17 05:54:14 +00:00
static int16 Size[MAX_FONTS][193];
2020-03-29 06:35:13 +00:00
#endif
2020-04-17 05:54:14 +00:00
static int16 NewLine;
static CSprite2d Sprite[MAX_FONTS];
2019-05-22 18:28:53 +00:00
public:
2020-04-17 05:54:14 +00:00
static CFontDetails Details;
2019-05-22 18:28:53 +00:00
static void Initialise(void);
static void Shutdown(void);
static void InitPerFrame(void);
2020-04-02 06:51:35 +00:00
static void PrintChar(float x, float y, wchar c);
static void PrintString(float x, float y, wchar *s);
static int GetNumberLines(float xstart, float ystart, wchar *s);
static void GetTextRect(CRect *rect, float xstart, float ystart, wchar *s);
static void PrintString(float x, float y, wchar *start, wchar *end, float spwidth);
static float GetCharacterWidth(wchar c);
static float GetCharacterSize(wchar c);
static float GetStringWidth(wchar *s, bool spaces = false);
static wchar *GetNextSpace(wchar *s);
static wchar *ParseToken(wchar *s, wchar*);
2019-05-22 18:28:53 +00:00
static void DrawFonts(void);
2020-04-02 06:51:35 +00:00
static wchar character_code(uint8 c);
2019-05-22 18:28:53 +00:00
static CFontDetails GetDetails() { return Details; }
2019-05-22 18:28:53 +00:00
static void SetScale(float x, float y) { Details.scaleX = x; Details.scaleY = y; }
static void SetSlantRefPoint(float x, float y) { Details.slantRefX = x; Details.slantRefY = y; }
static void SetSlant(float s) { Details.slant = s; }
static void SetJustifyOn(void) {
Details.justify = true;
Details.centre = false;
Details.rightJustify = false;
}
static void SetJustifyOff(void) {
Details.justify = false;
Details.rightJustify = false;
}
static void SetRightJustifyOn(void) {
Details.rightJustify = true;
Details.justify = false;
Details.centre = false;
}
static void SetRightJustifyOff(void) {
Details.rightJustify = false;
Details.justify = false;
Details.centre = false;
}
static void SetCentreOn(void) {
Details.centre = true;
Details.justify = false;
Details.rightJustify = false;
}
static void SetCentreOff(void) {
Details.centre = false;
}
static void SetAlignment(uint8 alignment) {
if (alignment == ALIGN_LEFT) {
CFont::Details.justify = true;
CFont::Details.centre = false;
CFont::Details.rightJustify = false;
}
else if (alignment == ALIGN_CENTER) {
CFont::Details.justify = false;
CFont::Details.centre = true;
CFont::Details.rightJustify = false;
}
else if (alignment == ALIGN_RIGHT) {
CFont::Details.justify = false;
CFont::Details.centre = false;
CFont::Details.rightJustify = true;
}
}
2019-05-22 18:28:53 +00:00
static void SetWrapx(float x) { Details.wrapX = x; }
static void SetCentreSize(float s) { Details.centreSize = s; }
static void SetBackgroundOn(void) { Details.background = true; }
static void SetBackgroundOff(void) { Details.background = false; }
static void SetBackGroundOnlyTextOn(void) { Details.backgroundOnlyText = true; }
static void SetBackGroundOnlyTextOff(void) { Details.backgroundOnlyText = false; }
static void SetPropOn(void) { Details.proportional = true; }
static void SetPropOff(void) { Details.proportional = false; }
static void SetFontStyle(int16 style) { Details.style = style; }
static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; }
static void SetAlphaFade(float fade) { Details.alphaFade = fade; }
static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; }
// TODO: really just CRGBA but that isn't passed correctly
static void SetBackgroundColor(const CRGBA &col) { Details.backgroundColor = col; }
static void SetColor(const CRGBA &col) {
Details.color = col;
if(Details.alphaFade < 255.0f)
Details.color.a *= Details.alphaFade/255.0f;
}
static void SetDropColor(const CRGBA &col) {
Details.dropColor = col;
if(Details.alphaFade < 255.0f)
Details.dropColor.a *= Details.alphaFade/255.0f;
}
2020-03-29 06:35:13 +00:00
static void ReloadFonts(uint8 set);
2019-05-22 18:28:53 +00:00
};