Nox Engine
 
Loading...
Searching...
No Matches
Button.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "Collider.h"
9#include "MouseTracker.h"
10#include "Text.h"
11#include "TextureManager.h"
12#include <functional>
13
14extern Manager manager;
15
21struct Button : public Component {
22public:
36 Button(
37 std::string inStr, int x, int y, int w, int h, float scale, SDL_Colour defColour,
38 SDL_Colour hoverColour, SDL_Colour textColour, std::function<void()> func
39 );
50 Button(std::string inStr, int x, int y, int w, int h, float scale, std::function<void()> func);
60 Button(std::string inStr, int x, int y, int w, int h, std::function<void()> func);
61 ~Button();
62
66 void init() override;
70 void update() override;
74 void reload() override;
78 void draw() override;
79
80private:
81 float scale;
82 bool isPressed;
83 std::string content;
84 std::function<void()> pressFunc;
85
86 Transform* transform;
87 Collider* collider;
88 Text* text;
89
90 SDL_Rect buttonRect;
91 SDL_Texture* texture;
92
93 SDL_Colour defColour;
94 SDL_Colour hoverColour;
95 SDL_Colour textColour;
96
101 void setTex(SDL_Colour& colour);
102};
Defines a component for collision detection.
Defines a component that tracks the mouse position and state.
Defines a component for rendering text.
A static utility class for loading and drawing textures.
A UI component that can be clicked to trigger a callback function.
Definition Button.h:21
void init() override
Initializes the button's components (transform, collider, text).
Definition Button.cpp:63
void update() override
Checks for mouse hover and click events to update the button's state.
Definition Button.cpp:92
void reload() override
Reloads the button's texture, useful after state changes.
Definition Button.cpp:98
void draw() override
Draws the button's background and text.
Definition Button.cpp:103
Provides an entity with a physical bounding box for collision detection.
Definition Collider.h:22
The base class for all components in the ECS.
Definition ECS.h:53
Manages all entities and their groups within the game.
Definition ECS.h:234
A component that renders a string of text on the screen.
Definition Text.h:16
Stores an entity's position, velocity, scale, and rotation.
Definition Transform.h:17