-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopsign.cpp
68 lines (58 loc) · 1.21 KB
/
stopsign.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stopsign.h"
StopSign::StopSign(QWidget* parent) : QOpenGLWidget(parent)
{
stopped = true;
change = 1; // transparency changes when stop sign is inactive
}
void StopSign::initializeGL()
{
openGLFunctions = QOpenGLContext::currentContext()->functions();
}
void StopSign::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
setAttribute(Qt::WA_AlwaysStackOnTop);
glClearColor(0.0,0.0,0.0,0.0);
glLoadIdentity();
// define vertices of an octagon
glBegin(GL_POLYGON);
glColor4f(0.8,0,0,change);
glVertex2f(-1,0.5);
glVertex2f(-0.5,1);
glVertex2f(0.5,1);
glVertex2f(1,0.5);
glVertex2f(1,-0.5);
glVertex2f(0.5,-1);
glVertex2f(-0.5,-1);
glVertex2f(-1,-0.5);
glEnd();
}
void StopSign::mousePressEvent(QMouseEvent *parent)
{
Q_UNUSED(parent);
toggle();
}
bool StopSign::isClicked()
{
return stopped;
}
void StopSign::set(bool active)
{
stopped = active;
if(stopped) {
change = 1;
} else {
change = 0.5;
}
update();
}
void StopSign::toggle()
{
stopped = !stopped;
if(stopped) {
change = 1;
} else {
change = 0.5;
}
update();
}