-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguibutton.cpp
54 lines (47 loc) · 1.73 KB
/
guibutton.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
#include "guibutton.h"
GUIButton::GUIButton(int positionX, int positionY, sf::RenderWindow* hutrieApplication, std::string pathName, int sizeX,
int sizeY, bool rect, int rectX, int rectY, int rectSizeX, int rectSizeY)
{
this->hutrieApplication = hutrieApplication;
button.setSize(sf::Vector2f(sizeX, sizeY));
button.setPosition(positionX, positionY);
texture.loadFromFile(pathName);
button.setTexture(&texture);
active = false;
if (rect) button.setTextureRect(sf::IntRect(rectX, rectY, rectSizeX, rectSizeY));
}
GUIButton::GUIButton(int positionX, int positionY, sf::RenderWindow* hutrieApplication, int sizeX, int sizeY,
bool visible)
{
this->hutrieApplication = hutrieApplication;
button.setSize(sf::Vector2f(sizeX, sizeY));
button.setPosition(positionX, positionY);
if (visible)
{
//button.setOutlineColor(sf::Color::Black);
//button.setOutlineThickness(6);
sf::Color color(245, 255, 179, 100);
button.setFillColor(color);
}
else
{
button.setFillColor(sf::Color::Transparent);
}
}
bool GUIButton::checkBounds()
{
sf::Vector2f buttonPosition = button.getPosition();
sf::Vector2f buttonSize = button.getSize();
sf::Vector2i mousePosition = sf::Mouse::getPosition(*hutrieApplication);
bool result = active
&& buttonPosition.x <= mousePosition.x
&& buttonPosition.x + buttonSize.x >= mousePosition.x
&& buttonPosition.y <= mousePosition.y
&& buttonPosition.y + buttonSize.y >= mousePosition.y;
return result;
}
void GUIButton::changeTexture(std::string path)
{
texture.loadFromFile(path);
button.setTexture(&texture);
}