-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTextMap.cpp
More file actions
108 lines (93 loc) · 1.98 KB
/
TextMap.cpp
File metadata and controls
108 lines (93 loc) · 1.98 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "all.hpp"
#include "TextMap.hpp"
TextMap::TextMap(): xMax_(16), yMax_(16), size_(100)
{
this->setMap("font/panda.png");
this->content_ = "";
this->pop_ = false;
}
TextMap::TextMap(std::string const & file): xMax_(16), yMax_(16), size_(100)
{
this->setMap(file);
this->content_ = "";
this->pop_ = false;
}
TextMap::TextMap(std::string const & file, int nbCharX, int nbCharY): xMax_(nbCharX), yMax_(nbCharY), size_(100)
{
this->setMap(file);
this->content_ = "";
this->pop_ = false;
}
TextMap::~TextMap()
{
}
void TextMap::setContent(std::string const & content)
{
this->content_ = content;
this->pop_ = true;
}
void TextMap::setPopup(bool const & pop)
{
this->pop_ = pop;
}
void TextMap::setMap(std::string const & file)
{
this->texture_ = gdl::Image::load(file);
}
void TextMap::setSize(int size)
{
this->size_ = size;
}
void TextMap::putChar(char c)
{
float l = (this->size_ * 8) / 10;
float a = 1.0f / this->xMax_;
float b = 1.0f / this->yMax_;
float x1 = (c % this->xMax_) * a;
float y1 = (c / this->yMax_) * b;
float x2 = x1 + a;
float y2 = y1 + b;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
texture_.bind();
glBegin(GL_QUADS);
glTexCoord2d(x1, y1); glVertex3f(-l, l, l);
glTexCoord2d(x1, y2); glVertex3f(-l, -l, l);
glTexCoord2d(x2, y2); glVertex3f(l, -l, l);
glTexCoord2d(x2, y1); glVertex3f(l, l, l);
glEnd();
glDisable(GL_BLEND);
}
void TextMap::putStr(std::string const str)
{
int i = 0;
glPushMatrix();
while(str[i])
{
if (str[i] != '\n')
{
this->putChar(str[i++]);
glTranslatef(this->size_, 0, 0);
}
else
{
i++;
glPopMatrix();
glPushMatrix();
glTranslatef(0, -this->size_, 0);
this->putStr(str.substr(i));
break;
}
}
glPopMatrix();
}
void TextMap::popup(void)
{
if (this->pop_ == true)
{
glPushMatrix();
glTranslatef(-500, 0, 0);
this->putStr(this->content_);
glPopMatrix();
}
}