forked from hwauck/statue-puzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.cc
executable file
·74 lines (59 loc) · 1.41 KB
/
button.cc
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
#include "button.h"
Button::Button() {
llcorner = Point(0,0);
width = 0;
height = 0;
text = "";
color = "black";
textPos = Point(0,0);
}
Button::Button(Point llcorner, double height, std::string text, std::string color) {
this->llcorner = llcorner;
this->width = CHAR_WIDTH * text.size();
this->height = height;
this->text = text;
this->color = color;
this->textPos = Point(llcorner.get_x(), llcorner.get_y() + height * 5.0 / 6);
}
//determines if Point p is inside the button
bool Button::inRange(Point p) {
double xMin = llcorner.get_x();
double yMin = llcorner.get_y();
double xMax = xMin + width;
double yMax = yMin + height;
if ((p.get_x() < xMax && p.get_x() > xMin) && (p.get_y() < yMax && p.get_y() > yMin)) {
return true;
}
return false;
}
std::string Button::getColor() const {
return color;
}
double Button::getWidth() const {
return width;
}
Point Button::getLLcorner() const {
return llcorner;
}
Point Button::getTextPos() const {
return textPos;
}
std::string Button::getText() const {
return text;
}
void Button::setWidth(double width) {
this->width = width;
}
void Button::setHeight(double height) {
this->height = height;
}
void Button::setText(std::string text) {
this->text = text;
}
void Button::setTextPos(Point textPos) {
this->textPos = textPos;
}
void Button::draw() {
drawSolidRectangle(width, height, llcorner, WIDTH_INCREMENT, color);
cwin << Message(textPos, text);
}