-
Notifications
You must be signed in to change notification settings - Fork 0
/
swLabel.cpp
41 lines (34 loc) · 981 Bytes
/
swLabel.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
#include <QGLWidget>
#include "swLabel.h"
swLabel::swLabel() : font(NULL) {
type = SW_LABEL;
}
swLabel::swLabel(swFont* fnt, QString str, double size, int justification) : font(fnt), string(str) {
type = SW_LABEL;
justify = (swFontJustification)justification;
scale = swVector(size, size);
}
swLabel::~swLabel() {}
void swLabel::read(swStream* stream) {
swDrawable::read(stream);
stream->readString(string);
justify = (swFontJustification)stream->readInt();
}
void swLabel::write(swStream* stream) {
swDrawable::write(stream);
stream->writeString(string);
stream->writeInt(justify);
}
void swLabel::draw() {
if(font) {
glPushMatrix();
transform();
if(justify == SW_JUSTIFY_CENTER)
glTranslated((-string.length() + 1) * 1.5 / 2.0, 0, 0);
for(int i = 0; i < string.count(); i++) {
font->drawLetter(string[i].toAscii());
glTranslated(1.5, 0, 0);
}
glPopMatrix();
}
}