-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAmountView.cpp
More file actions
38 lines (30 loc) · 1.01 KB
/
AmountView.cpp
File metadata and controls
38 lines (30 loc) · 1.01 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
#include "AmountView.h"
using namespace std;
AmountView::AmountView(GLuint* f, glm::vec3 p, GLint s, int startChar, glm::vec4 color)
: UIElement(f, p, s), colorMod(color) {
amount = 0;
view.push_back(new Renderable(position, font[startChar], numElements));
view.push_back(new Renderable(position + glm::vec3(0.15f, 0.f, 0.f), font[0], numElements));
}
void AmountView::add(int addition) {
int oldLength = to_string(amount).length();
amount += addition;
int newLength = to_string(amount).length();
// old < new
for (int i = oldLength + 1; i < newLength + 1; ++i) {
view.push_back(new Renderable(position + glm::vec3(i * 0.15f, 0.f, 0.f), font[0], numElements));
}
// new < old
for (int i = newLength; i < oldLength; ++i) {
view.pop_back();
}
for (int i = 1; i < view.size(); ++i) {
view[i]->setTex(font[(amount / (int)pow(10, view.size() - 1 - i) % 10)]);
}
}
void AmountView::render(Shader &shader) {
shader.setUniform4f("colorMod", colorMod);
for (Renderable* i : view) {
i->render(shader);
}
}