Корабът Радецки - Eight ball pool v 1.0
The documnetation for our physics-themed project.
ui_elements.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <raygui.h>
4#include "drawable.hpp"
5
7{
8protected:
9 Rectangle bounds;
10 float rotation;
11
12public:
13 UIElement(Rectangle bounds, float rotation) : Drawable()
14 {
15 this->bounds = bounds;
16 this->rotation = rotation;
17 }
18
19 virtual ~UIElement() = default;
20
21 void SetPosition(Vector2 position);
22 Vector2 GetPosition();
23
24 void SetRotation(float rotation);
25 float GetRotation();
26
27 void SetSize(Vector2 size);
28 Vector2 GetSize();
29};
30
31class Button : public UIElement
32{
33protected:
35 const char* text;
36
39
40public:
41 Button(const char* text, Rectangle bounds, float rotation) : UIElement(bounds, rotation)
42 {
43 this->text = text;
44 this->is_clicked = false;
45
46 click_sound = LoadSound("resources/sfx/menu_hover.wav");
47 hover_sound = LoadSound("resources/sfx/menu_click.wav");
48 }
49
50 virtual ~Button()
51 {
52 UnloadSound(hover_sound);
53 UnloadSound(click_sound);
54 }
55
61 bool IsClicked();
62
66 void Draw() override;
67
71 void Update() override;
72};
73
74class Label : public UIElement
75{
76protected:
77 const char* text;
78
79public:
80 Label(const char* text, Rectangle bounds, float rotation) : UIElement(bounds, rotation)
81 {
82 this->text = text;
83 };
84
85 virtual ~Label() = default;
86
90 void Draw() override;
91};
92
93class CheckBox : public UIElement
94{
95private:
96 bool checked;
97
98protected:
99 const char* placeholder_text;
100
101public:
102 CheckBox(const char* text, Rectangle bounds, float rotation, bool checked = false) : UIElement(bounds, rotation)
103 {
104 placeholder_text = text;
105 this->checked = checked;
106 }
107
108 virtual ~CheckBox() = default;
109
113 void Draw() override;
114
120 bool IsChecked();
121
129 void SetChecked(bool value);
130};
Definition: ui_elements.hpp:32
void Update() override
Updates the spritess.
Definition: ui_elements.cpp:40
bool IsClicked()
Checks whether the button has been clicked or not.
Definition: ui_elements.cpp:46
Sound hover_sound
Definition: ui_elements.hpp:37
void Draw() override
Draws the sprites.
Definition: ui_elements.cpp:35
Button(const char *text, Rectangle bounds, float rotation)
Definition: ui_elements.hpp:41
const char * text
Definition: ui_elements.hpp:35
virtual ~Button()
Definition: ui_elements.hpp:50
bool is_clicked
Definition: ui_elements.hpp:34
Sound click_sound
Definition: ui_elements.hpp:38
Definition: ui_elements.hpp:94
void SetChecked(bool value)
Sets the "Checked" status of the boxes.
Definition: ui_elements.cpp:66
void Draw() override
Draws the sprites.
Definition: ui_elements.cpp:56
bool IsChecked()
Checks whether or not any of the checkboxes are checked.
Definition: ui_elements.cpp:61
virtual ~CheckBox()=default
CheckBox(const char *text, Rectangle bounds, float rotation, bool checked=false)
Definition: ui_elements.hpp:102
const char * placeholder_text
Definition: ui_elements.hpp:99
Definition: drawable.hpp:13
Drawable()
Sets the sprites' IDs.
Definition: drawable.cpp:8
Definition: ui_elements.hpp:75
const char * text
Definition: ui_elements.hpp:77
virtual ~Label()=default
void Draw() override
Draws the sprites.
Definition: ui_elements.cpp:51
Label(const char *text, Rectangle bounds, float rotation)
Definition: ui_elements.hpp:80
Definition: ui_elements.hpp:7
UIElement(Rectangle bounds, float rotation)
Definition: ui_elements.hpp:13
float GetRotation()
Definition: ui_elements.cpp:19
float rotation
Definition: ui_elements.hpp:10
Rectangle bounds
Definition: ui_elements.hpp:9
Vector2 GetPosition()
Definition: ui_elements.cpp:9
void SetPosition(Vector2 position)
Definition: ui_elements.cpp:3
void SetSize(Vector2 size)
Definition: ui_elements.cpp:24
void SetRotation(float rotation)
Definition: ui_elements.cpp:14
Vector2 GetSize()
Definition: ui_elements.cpp:30
virtual ~UIElement()=default