-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTBar.cpp
46 lines (39 loc) · 999 Bytes
/
TBar.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
#include "TBar.h"
bool TBar::Hit(float x, float y) {
return (x >= posX && x <= posX + Width && y >= posY && y <= posY + Height);
}
void TBar::OnMouseDown(float x, float y) {
if (BarButton.Hit(x, y)) {
m_bButtonClick = true;
BarButton.SetPos(x);
}
else if (Hit(x, y)) {
BarButton.SetPos(x);
}
}
void TBar::OnMove(float x, float y) {
if (!m_bButtonClick)
return;
BarButton.SetPos(x);
}
float TBar::getValue() {
return BarButton.posX / Width;
}
void TBar::OnMouseUp(float x, float y) {
m_bButtonClick = false;
}
void TBar::Show() {
//Draw bar
glDisable(GL_DEPTH_TEST);
glm::mat4 model(1.f);
model = glm::translate(model, glm::vec3(posX, posY, 0.f));
shdr.Use();
shdr.SetMat4("model", model);
barMesh->Draw(shdr);
//Draw button
model = glm::mat4(1.f);
model = glm::translate(model, glm::vec3(posX + BarButton.posX, posY + BarButton.posY - (BarButton.Height - Height) / 2, 0.f));
shdr.SetMat4("model", model);
BarButton.btnMesh->Draw(shdr);
glEnable(GL_DEPTH_TEST);
}