-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpriteFont.h
More file actions
85 lines (66 loc) · 2.28 KB
/
Copy pathSpriteFont.h
File metadata and controls
85 lines (66 loc) · 2.28 KB
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
/*
This is a modified version of the SpriteFont class from the
Seed Of Andromeda source code.
Use it for any of your projects, commercial or otherwise,
free of charge, but do not remove this disclaimer.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.
November 28 2014
Original Author: Cristian Zaloj
Modified By: Benjamin Arnold
*/
#pragma once
#ifndef SpriteFont_h__
#define SpriteFont_h__
#include <SDL_ttf.h>
#include <glm/glm.hpp>
#include <map>
#include <vector>
#include "Vertex.h"
namespace KlaoudeEngine {
class GLTexture;
class SpriteBatch;
struct CharGlyph
{
char character;
glm::vec4 uvRect;
glm::vec2 size;
};
#define FIRST_PRINTABLE_CHAR ((char)32)
#define LAST_PRINTABLE_CHAR ((char)126)
/// For text justification
enum class Justification {
LEFT, MIDDLE, RIGHT
};
class SpriteFont {
public:
SpriteFont(const char* font, int size, char cs, char ce);
SpriteFont(const char* font, int size) :
SpriteFont(font, size, FIRST_PRINTABLE_CHAR, LAST_PRINTABLE_CHAR) {
}
/// Destroys the font resources
void dispose();
int getFontHeight() const {
return m_fontHeight;
}
/// Measures the dimensions of the text
glm::vec2 measure(const char* s);
/// Draws using a spritebatch
void draw(SpriteBatch& batch, const char* s, glm::vec2 position, glm::vec2 scaling,
float depth, ColorRGBA8 tint, Justification just = Justification::LEFT);
private:
static std::vector<int>* createRows(glm::ivec4* rects, int rectsLength, int r, int padding, int& w);
int m_regStart, m_regLength;
CharGlyph* m_glyphs;
int m_fontHeight;
unsigned int m_texID;
};
}
#endif // SpriteFont_h__