-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstick.cpp
60 lines (43 loc) · 976 Bytes
/
stick.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
#include "stick.h"
Stick::Stick() :
_x(0.0), _y(0.0),
_width(0.01), _height(0.1)
{
}
void Stick::draw()
{
glPushMatrix();
glTranslated(_x, _y, 0.5);
glRotated(_rotation, 0.0, 0.0, 1.0);
glPushMatrix();
glScaled(_width, _height, 1.0);
glTranslatef(-0.5, -0.5, 0.0);
glBegin(GL_QUADS);
glColor4f(_red, _green, _blue, _alpha);
glVertex2f(0.0, 0.0);
glVertex2f(1.0, 0.0);
glVertex2f(1.0, 1.0);
glVertex2f(0.0, 1.0);
glEnd();
glPopMatrix();
glPopMatrix();
glFlush();
}
void Stick::setSize(qreal width, qreal height)
{
_width = width;
_height = height;
}
void Stick::setColor(const QString &colorCode)
{
_color = QColor(colorCode);
setColor(_color.red(), _color.green(), _color.blue(), _color.alpha());
}
void Stick::setColor(int red, int green, int blue, int alpha)
{
_color = QColor(red, green, blue, alpha);
_red = _color.redF();
_green = _color.greenF();
_blue = _color.blueF();
_alpha = _color.alphaF();
}