-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorPicker.h
63 lines (54 loc) · 1.57 KB
/
ColorPicker.h
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
#ifndef COLOR_PICKER_H
#define COLOR_PICKER_H
#include "Color.h"
#include "ColorSlider.h"
#include "RectangleShape.h"
class ColorPicker {
private:
RectangleShape area;
RectangleShape displayColor;
ColorSlider redSlider;
ColorSlider greenSlider;
ColorSlider blueSlider;
public:
ColorPicker() {
area = RectangleShape(0.1, -0.9, 1.8, 0.2, Color(0.66, 0.66, 0.66));
redSlider = ColorSlider(-0.52, -0.9, Color(1, 0, 0));
greenSlider = ColorSlider(0, -0.9, Color(0, 1, 0));
blueSlider = ColorSlider(0.52, -0.9, Color(0, 0, 1));
displayColor = RectangleShape(0.9, -0.9, 0.2, 0.2, getColor());
displayColor.outline();
}
void draw() {
area.draw();
displayColor.draw();
redSlider.draw();
greenSlider.draw();
blueSlider.draw();
// Borders for the area:
glColor3f(0, 0, 0);
glBegin(GL_LINES);
// Top:
glVertex2f(-0.8, -0.8);
glVertex2f(0.8, -0.8);
// Bottom:
glVertex2f(-0.8, -0.999);
glVertex2f(1, -0.999);
glEnd();
}
void handleClick(float x, float y) {
if (redSlider.contains(x, y))
redSlider.handleClick(x, y);
else if (greenSlider.contains(x, y))
greenSlider.handleClick(x, y);
else if (blueSlider.contains(x, y))
blueSlider.handleClick(x, y);
displayColor.setColor(getColor());
}
bool contains(float x, float y) { return area.contains(x, y); }
Color getColor() {
return Color(redSlider.getIntensity(), greenSlider.getIntensity(),
blueSlider.getIntensity());
}
};
#endif