-
Notifications
You must be signed in to change notification settings - Fork 75
/
hgefont.h
148 lines (121 loc) · 3.99 KB
/
hgefont.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeFont helper class header
*/
#pragma once
#ifndef HGEFONT_H
#define HGEFONT_H
#include <hge.h>
#include <hgesprite.h>
#define HGETEXT_LEFT 0
#define HGETEXT_RIGHT 1
#define HGETEXT_CENTER 2
#define HGETEXT_HORZMASK 0x03
#define HGETEXT_TOP 0
#define HGETEXT_BOTTOM 4
#define HGETEXT_MIDDLE 8
#define HGETEXT_VERTMASK 0x0C
/*
** HGE Font interface (to use with BMFont font)
** Supports Unicode
*/
#if HGE_UNICODE
class hgeFont
{
public:
hgeFont(hgeConstString filename, bool bMipmap=false);
void Render(float x, float y, int align, hgeConstString string) {}
void printf(float x, float y, int align, hgeConstString format, ...) {}
void printfb(float x, float y, float w, float h, int align, hgeConstString format, ...) {}
void SetColor(uint32_t col) { m_color = col; }
void SetZ(float z) { m_depth = z; }
void SetBlendMode(int blend) { m_blending = blend; }
void SetScale(float scale) { m_scale = scale; }
void SetProportion(float prop) { }
void SetRotation(float rot) { }
void SetTracking(float tracking) { }
void SetSpacing(float spacing) { }
uint32_t GetColor() const { return m_color; }
float GetZ() const { return m_depth; }
int GetBlendMode() const { return m_blending; }
float GetScale() const { return m_scale; }
float GetProportion() const { return 0.0f; }
float GetRotation() const { return 0.0f; }
float GetTracking() const { return 0.0f; }
float GetSpacing() const { return 0.0f; }
hgeSprite * GetSprite(hgeChar chr) const { return NULL; }
float GetPreWidth(hgeChar chr) const { return 0.0f; }
float GetPostWidth(hgeChar chr) const { return 0.0f; }
float GetHeight() const { return 0.0f; }
float GetStringWidth(hgeConstString string, bool bMultiline=true) const { return 0.0f; }
protected:
static HGE * m_hge;
uint32_t m_color;
float m_depth;
int m_blending;
float m_scale;
private:
hgeFont();
hgeFont(const hgeFont &fnt);
hgeFont & operator = (const hgeFont &fnt);
};
#else // not HGE_UNICODE
/*
** Legacy HGE Font class
*/
class hgeFont
{
public:
hgeFont(hgeConstString filename, bool bMipmap=false);
~hgeFont();
void Render(float x, float y, int align, hgeConstString string);
void printf(float x, float y, int align, hgeConstString format, ...);
void printfb(float x, float y, float w, float h, int align, hgeConstString format, ...);
void SetColor(uint32_t col);
void SetZ(float z);
void SetBlendMode(int blend);
void SetScale(float scale) {m_scale=scale;}
void SetProportion(float prop) { m_proportion=prop; }
void SetRotation(float rot) {m_rotation=rot;}
void SetTracking(float tracking) {m_tracking=tracking;}
void SetSpacing(float spacing) {m_spacing=spacing;}
uint32_t GetColor() const {return m_color;}
float GetZ() const {return m_depth;}
int GetBlendMode() const {return m_blending;}
float GetScale() const {return m_scale;}
float GetProportion() const { return m_proportion; }
float GetRotation() const {return m_rotation;}
float GetTracking() const {return m_tracking;}
float GetSpacing() const {return m_spacing;}
hgeSprite* GetSprite(hgeChar chr) const { return m_letters[(hgeChar)chr]; }
float GetPreWidth(hgeChar chr) const { return m_pre[(hgeChar)chr]; }
float GetPostWidth(hgeChar chr) const { return m_post[(hgeChar)chr]; }
float GetHeight() const { return m_height; }
float GetStringWidth(hgeConstString string, bool bMultiline=true) const;
private:
hgeFont();
hgeFont(const hgeFont &fnt);
hgeFont & operator = (const hgeFont &fnt);
hgeString _get_line( hgeString file, hgeString line );
const static size_t HGEFONT_BUFFER_SZ = 1024;
static hgeChar m_buffer[HGEFONT_BUFFER_SZ];
static HGE * m_hge;
uint32_t m_color;
float m_depth;
int m_blending;
float m_scale;
HTEXTURE m_texture;
hgeSprite* m_letters[256];
float m_pre[256];
float m_post[256];
float m_height;
float m_proportion;
float m_rotation;
float m_tracking;
float m_spacing;
};
#endif // HGE_UNICODE
#endif // HGEFONT_H