summaryrefslogtreecommitdiffstats
path: root/src/render/Font.h
blob: d6f586922d45181a17726b2fe3307244a4e10476 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#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;

enum {
	FONTSTYLE_0,
	FONTSTYLE_1,
	FONTSTYLE_2,
};

class CFont
{
	static CFontDetails &Details;
	static int16 Size[3][193];
	static int16 

	static CSprite2d *Sprite;	//[3]
public:
	static void Initialise(void);
	static void Shutdown(void);
	static void InitPerFrame(void);
	static void PrintChar(float x, float y, uint16 c);
	static void PrintString(float x, float y, uint16 *s);
	static int GetNumberLines(float xstart, float ystart, uint16 *s);
	static void GetTextRect(CRect *rect, float xstart, float ystart, uint16 *s);
	static void PrintString(float x, float y, uint16 *start, uint16 *end, float spwidth);
	static float GetCharacterWidth(uint16 c);
	static float GetCharacterSize(uint16 c);
	static float GetStringWidth(uint16 *s, bool spaces = false);
	static uint16 *GetNextSpace(uint16 *s);
	static uint16 *ParseToken(uint16 *s, uint16*);
	static void DrawFonts(void);
	static uint16 character_code(uint8 c);

	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 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;
	}
};