-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
50 lines (43 loc) · 1.39 KB
/
Copy pathButton.cpp
File metadata and controls
50 lines (43 loc) · 1.39 KB
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
#include "Button.h"
//#include "rect.h"
#include "graphics.h"
using namespace std;
Button::Button(color fill, point2D center, unsigned int width, unsigned int height, std::string label) : Rect(fill, center, dimensions(width, height)) {
this->label = label;
originalFill = fill;
hoverFill = {fill.red + 0.5, fill.green + 0.5, fill.blue + 0.5};
pressFill = {fill.red - 0.5, fill.green - 0.5, fill.blue - 0.5};
}
void Button::draw() const {
Rect::draw();
glColor3f(0, 0, 0);
glRasterPos2i(center.x - (4 * label.length()), center.y + 7);
for (const char &letter : label) {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, letter);
}
}
void Button::hide() const {
Rect::drawBlack();
}
/* Returns true if the coordinate is inside the box */
bool Button::isOverlapping(int x, int y) const {
// TODO: Implement
if (((x >= this->getLeftX()) && (x <= this->getRightX())) && ((y >= this->getTopY()) && (y <= this->getBottomY()))) {
return true;
}
else {
return false; // Placeholder for compilation
}
}
/* Change color of the box when the user is hovering over it */
void Button::hover() {
setColor(hoverFill);
}
/* Change color of the box when the user is clicking on it */
void Button::pressDown() {
setColor(pressFill);
}
/* Change the color back when the user is not clicking/hovering */
void Button::release() {
setColor(originalFill);
}