-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswFont.cpp
60 lines (51 loc) · 1.41 KB
/
swFont.cpp
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
#include <QFile>
#include <QGLWidget>
#include "swFont.h"
swFont::swFont() : charBase(0), charCount(0), chars(NULL) {
type = SW_FONT;
}
swFont::swFont(QString file) : charBase(0), charCount(0), chars(NULL) {
type = SW_FONT;
QFile stream(file);
stream.open(QFile::ReadOnly);
swObject::read(&stream);
stream.close();
}
swFont::swFont(swStream* stream) : charBase(0), charCount(0), chars(NULL) {
type = SW_FONT;
read(stream);
}
swFont::~swFont() {
if(chars)
delete chars;
}
void swFont::read(swStream *stream) {
if(chars)
delete chars;
mesh.read(stream);
stream->readChar(charCount);
stream->readChar(charBase);
chars = new int[charCount];
stream->read((char*)chars, charCount * sizeof(int));
}
void swFont::write(swStream *stream) {
mesh.write(stream);
stream->writeChar(charCount);
stream->writeChar(charBase);
stream->write((char*)chars, charCount * sizeof(int));
}
bool swFont::hasLetter(char letter) {
return letter >= charBase && letter < (charBase + charCount);
}
void swFont::drawLetter(char letter) {
if(!hasLetter(letter))
return;
glBegin(GL_LINES);
for(int i = 0; i < mesh.edgeCount; i++) {
if(1 << i & chars[letter - charBase]) {
glVertex2dv(&mesh.verts[mesh.edges[i * 2] * 3]);
glVertex2dv(&mesh.verts[mesh.edges[i * 2 + 1] * 3]);
}
}
glEnd();
}