-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.cpp
More file actions
50 lines (42 loc) · 1.13 KB
/
GUI.cpp
File metadata and controls
50 lines (42 loc) · 1.13 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 "GUI.h"
#include <stdio.h>
GUI::GUI() {
//empty constructor
}
GUI::~GUI() {
//empty destructor
}
bool GUI::quit = false;
GUI::Box::Box(int x1, int y1, int x2, int y2, int value) {
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
this->boxValue = value;
}
bool GUI::Box::contains(int x, int y) {
return ((x > x1) && (x < x2) && (y > y1) && (y < y2));
}
int GUI::getInput() {
//Get mouse coordinate
int boxClicked = 0;
SDL_Event e;
while(SDL_PollEvent(&e) != 0) { //iterate through all events in queue
if(e.type == SDL_QUIT) { //if user quit, change quit flag and return immediately
GUI::quit = true;
return 0;
} else if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT) { // if user left-clicks
int mouseX = e.button.x;
int mouseY = e.button.y;
//Get clicked box's value
int numBox = boxes.size();
for(int i = 0; i < numBox; i++) {
if(boxes[i].contains(mouseX, mouseY)) {
boxClicked = boxes[i].boxValue;
break;
}
}
}
}
return boxClicked;
}