-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widget.cpp
67 lines (62 loc) · 1.2 KB
/
Widget.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
#include "Widget.h"
#include <string>
#include <SDL.h>
#include <SDL_image.h>
// Standard Constructor for Widget
Widget::Widget(int start_x, int start_y, SDL_Renderer* renderer, SDL_Window* window)
{
pos.x = start_x;
pos.y = start_y;
this->renderer = renderer;
this->window = window;
this->locked = true;
this->hidden = false;
}
// Set the X position of the Widget
void Widget::setX(int x)
{
if (!locked && !hidden){
pos.x = x;
}
}
// Set the Y position of the Widget
void Widget::setY(int y)
{
if (!locked && !hidden){
pos.y = y;
}
}
// Set the X position of the Widget
int Widget::getX()
{
return pos.x;
}
// Set the Y position of the Widget
int Widget::getY()
{
return pos.y;
}
// If x and y are within boundaries of widget, toggle widget lock
void Widget::toggleLock()
{
locked = !locked;
return;
}
// If x and y are within boundaries of widget, toggle widget hidden
void Widget::toggleHidden()
{
hidden = !hidden;
return;
}
// Returns true only if x and y are within the rectangle bound of the widget
bool Widget::insideBound(int x, int y)
{
if (x > pos.x && y > pos.y && x < pos.x + pos.w && y < pos.y + pos.h){
return true;
}
return false;
}
// Destructor for Widget
Widget::~Widget()
{
}