-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStatusBar.cpp
More file actions
99 lines (75 loc) · 2.39 KB
/
StatusBar.cpp
File metadata and controls
99 lines (75 loc) · 2.39 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
#include "StatusBar.h"
#include "Framework.h"
#include <cstdio>
#define INSET 0.005
Shader *StatusBar::BarShader;
void StatusBar::loadShader() {
BarShader = new Shader("shaders/bar");
}
StatusBar::StatusBar(btVector4 rect){
this->rect = rect;
topColor = bottomColor = btVector4(0.6, 0.81, 0.92, 0.5);
value = 100;
}
StatusBar::~StatusBar() {}
void StatusBar::render(){
glEnable(GL_BLEND); //GL_CHECK
glDepthMask(GL_FALSE); //GL_CHECK
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_CHECK
glUseProgram(BarShader->programID());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLint pos = glGetAttribLocation(BarShader->programID(), "positionIn");
GLint col = glGetAttribLocation(BarShader->programID(), "colorIn");
glBegin(GL_LINE_LOOP);
glVertexAttrib4f(col, 0.6, 0.81, 0.92, 0.5);
glVertexAttrib2f(pos, rect.x(), rect.y());
glVertexAttrib4f(col, 0.6, 0.81, 0.92, 0.5);
glVertexAttrib2f(pos, rect.x() + rect.z(), rect.y());
glVertexAttrib4f(col, 0.6, 0.81, 0.92, 0.5);
glVertexAttrib2f(pos, rect.x() + rect.z(), rect.y() + rect.w());
glVertexAttrib4f(col, 0.6, 0.81, 0.92, 0.5);
glVertexAttrib2f(pos, rect.x(), rect.y() + rect.w());
glEnd();
float height = value / 100.0 * (rect.w() - INSET);
btVector3 color3 = bottomColor.lerp(topColor, value / 100.0);
btVector4 color(color3.x(), color3.y(), color3.z(), bottomColor.w());
glBegin(GL_QUADS);
glVertexAttrib4fv(col, bottomColor.m_floats);
glVertexAttrib2f(pos, rect.x() + INSET, rect.y() + INSET);
glVertexAttrib4fv(col, bottomColor.m_floats);
glVertexAttrib2f(pos, rect.x() + rect.z() - INSET, rect.y() + INSET);
glVertexAttrib4fv(col, color.m_floats);
glVertexAttrib2f(pos, rect.x() + rect.z() - INSET, rect.y() + height);
glVertexAttrib4fv(col, color.m_floats);
glVertexAttrib2f(pos, rect.x() + INSET, rect.y() + height);
glEnd();
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
void StatusBar::setTopColor(btVector4 color) {
topColor = color;
}
void StatusBar::setBottomColor(btVector4 color) {
bottomColor = color;
}
void StatusBar::print(){
printf("%f\n", value);
}
float StatusBar::getValue() {
return value;
}
void StatusBar::setValue(float val) {
value = val;
}
void StatusBar::add(float val) {
value += val;
if(value > 100) value = 100.0;
}
void StatusBar::subtract(float val) {
value -= val;
if(value < 0 ) value = 0.0;
}