-
Notifications
You must be signed in to change notification settings - Fork 2
/
sfml_scroll_box.h
67 lines (44 loc) · 1.73 KB
/
sfml_scroll_box.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
#ifndef SFML_SCROLL_BOX_H
#define SFML_SCROLL_BOX_H
#include <SFML/Graphics.hpp>
#include <functional>
#include <sfml_button.h>
class sfml_scroll_box
{
public:
/// @param The x coordinate of the scroll_box
/// @param The y coordinate of the scroll_box
/// @param The width of the scroll_box
/// @param The heigth of the scroll_box
sfml_scroll_box(const double x = 1.0, const double y = 1.0,
const double height = 100.0, const double width = 100.0);
/// Is the scroll_box hovered above
bool hovering(const sf::Event& event, const sf::RenderWindow& window);
sf::RectangleShape &get_shape() noexcept { return m_shape; }
sf::View &get_view() noexcept { return m_view; }
sf::Vector2f get_pos() noexcept { return sf::Vector2f(m_x, m_y); }
sf::Vector2f get_size() noexcept { return sf::Vector2f(m_width, m_height); }
void set_pos(int x, int y, sf::RenderWindow &window);
void set_size(double width, double height);
void draw(sf::RenderWindow& window);
void draw(sf::RenderWindow& window, std::vector<sfml_button> v);
void add_rectangle(sf::RectangleShape &r);
void add_text(sf::Text &t);
void scroll(sf::Event &event);
bool is_clicked(sf::Vector2f pos) const;
int get_scroll() const noexcept { return m_scroll; }
void set_scroll(int scr) { m_scroll = scr; }
private:
sf::RectangleShape m_shape;
sf::View m_view;
double m_x;
double m_y;
double m_height;
double m_width;
//No, we are not going to use abstract base classes in this project
//std::vector<std::reference_wrapper<sf::Drawable>> m_drawables;
std::vector<std::reference_wrapper<sf::RectangleShape>> m_rectangles;
std::vector<std::reference_wrapper<sf::Text>> m_texts;
int m_scroll;
};
#endif // SFML_SCROLL_BOX_H