-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperClass.h
71 lines (61 loc) · 1.76 KB
/
HelperClass.h
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
//
// Created by Kelly Lwin on 4/25/2023.
//
#ifndef SFML_TEMPLATE_HELPERCLASS_H
#define SFML_TEMPLATE_HELPERCLASS_H
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Font.h"
#include "States.h"
#include "MouseEvents.h"
class PhonyButton: public sf::RectangleShape, public States {
private:
public:
PhonyButton() {
setSize({150, 50});
setFillColor(sf::Color::Transparent);
setPosition({100, 100});
}
};
class Button: public sf::Drawable {
private:
sf::RectangleShape box;
sf::Text buttonText;
std::string string="Button";
sf::Font font;
public:
Button() {
setSize({100, 50});
setColor({sf::Color::Blue});
Font::defaultFont(buttonText, font, string);
}
void setPosition(const sf::Vector2f& pos) {
box.setPosition(pos);
buttonText.setPosition({pos.x+10, pos.y});
}
void setSize(const sf::Vector2f& size) {box.setSize(size);}
void setColor(const sf::Color& color) {box.setFillColor(color);}
void setButtonText(const std::string& text) {
string = text;
buttonText.setString(string);
}
sf::FloatRect getGlobalBounds() const {
return box.getGlobalBounds();
}
void addEventHandler(sf::RenderWindow& window, sf::Event event) {
if(MouseEvents::isClicked(box, window)) {
setColor(sf::Color::Red);
}
if(MouseEvents::isNotClicked(box, window)) {
setColor(sf::Color::Green);
}
}
void update() {
}
protected:
void draw(sf::RenderTarget &target, sf::RenderStates states) const override {
target.draw(this->box);
target.draw(buttonText);
}
};
#endif //SFML_TEMPLATE_HELPERCLASS_H