forked from funkey/gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSliderPainter.cpp
83 lines (60 loc) · 1.54 KB
/
SliderPainter.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <gui/OpenGl.h>
#include "SliderPainter.h"
namespace gui {
SliderPainter::SliderPainter(double min, double max, double value) :
_min(min),
_max(max),
_value(value),
_highlight(false) {
setSize(0, 0, 100, 10);
updateSliderPosition();
}
void
SliderPainter::setValue(double value) {
_value = value;
updateSliderPosition();
}
void
SliderPainter::setHighlight(bool highlight) {
_highlight = highlight;
}
void
SliderPainter::draw(
const util::rect<double>& roi,
const util::point<double>& resolution) {
if (_highlight)
glColor4f(1.0, 0.75, 0.75, 0.5);
else
glColor4f(0.75, 0.75, 0.75, 0.5);
const util::rect<double>& size = getSize();
glLineWidth(1);
glDisable(GL_LINE_SMOOTH);
glBegin(GL_LINES);
glVertex2d(size.minX + size.height()/2, size.minY + size.height()/2);
glVertex2d(size.maxX - size.height()/2, size.minY + size.height()/2);
glEnd();
glBegin(GL_QUADS);
glVertex2d(_graspSize.minX, _graspSize.minY);
glVertex2d(_graspSize.maxX, _graspSize.minY);
glVertex2d(_graspSize.maxX, _graspSize.maxY);
glVertex2d(_graspSize.minX, _graspSize.maxY);
glEnd();
}
const util::rect<double>&
SliderPainter::getGraspSize() {
return _graspSize;
}
void
SliderPainter::updateSliderPosition() {
const util::rect<double>& size = getSize();
double sliderWidth = 0.1*size.width();
double sliderPos =
sliderWidth/2 + (_value - _min)/
(_max - _min)*(size.width() - sliderWidth);
_graspSize = util::rect<double>(
sliderPos - sliderWidth/2,
size.minY,
sliderPos + sliderWidth/2,
size.maxY);
}
} // namespace gui