R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
RaylibButton.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** RaylibButton - Raylib implementation of IButton
6*/
7
8#pragma once
9
10#include <functional>
11#include <string>
12
14#include "UI/IButton.hpp"
15
16namespace UI {
28 class RaylibButton : public IButton {
29 public:
34 explicit RaylibButton(Graphics::IGraphics &graphics);
35
39 ~RaylibButton() override = default;
40
42 void Update() override;
43
45 void Render() override;
46
48 void SetCallback(std::function<void()> callback) override;
49
51 void SetPosition(float x, float y) override;
52
54 void GetPosition(float &x, float &y) const override;
55
57 void SetSize(float width, float height) override;
58
60 void GetSize(float &width, float &height) const override;
61
63 void SetBackgroundColor(unsigned int color) override;
64
66 void SetHoverColor(unsigned int color) override;
67
69 void SetText(const std::string &text) override;
70
72 void SetTextSize(int size) override;
73
75 void SetTextColor(unsigned int color) override;
76
78 void SetFont(int fontHandle) override;
79
81 void SetAlign(Align align) override;
82
84 [[nodiscard]] Align GetAlign() const override;
85
87 void ApplyAlignment() override;
88
90 [[nodiscard]] ButtonState GetState() const override;
91
93 [[nodiscard]] bool IsEnabled() const override;
94
96 void SetEnabled(bool enabled) override;
97
99 [[nodiscard]] const std::string &GetText() const override;
100
102 [[nodiscard]] int GetTextSize() const override;
103
105 [[nodiscard]] unsigned int GetTextColor() const override;
106
108 [[nodiscard]] int GetFont() const override;
109
111 void SetFocused(bool focused) override;
112
114 [[nodiscard]] bool IsFocused() const override;
115
117 void TriggerClick() override;
118
119 private:
123 [[nodiscard]] bool IsMouseOver() const;
124
126 std::function<void()> _callback{};
127
128 float _x{0.0F};
129 float _y{0.0F};
130 float _width{100.0F};
131 float _height{40.0F};
132
133 unsigned int _backgroundColor{0xFF808080};
134 unsigned int _hoverColor{0xFFA0A0A0};
135 unsigned int _focusColor{0xFF4080FF}; // Blue border for focused state
136
138 bool _enabled{true};
139 bool _wasMouseDown{false};
140 bool _focused{false}; // Keyboard focus state
141
142 // Text properties
143 std::string _text;
144 int _textSize{20};
145 unsigned int _textColor{0xFFFFFFFF};
146 int _fontHandle{-1};
147
149 };
150} // namespace UI
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract interface for UI buttons.
Definition IButton.hpp:50
Raylib implementation of the IButton interface.
void SetHoverColor(unsigned int color) override
Set button hover color.
unsigned int GetTextColor() const override
Get label color.
void TriggerClick() override
Programmatically trigger the button's click callback.
void SetPosition(float x, float y) override
Set the top-left position of the button.
Graphics::IGraphics & _graphics
unsigned int _hoverColor
ButtonState GetState() const override
Get current button state.
void SetAlign(Align align) override
Set alignment mode relative to the current window.
void SetFocused(bool focused) override
Set the keyboard focus state of the button.
std::function< void()> _callback
void ApplyAlignment() override
Apply alignment (recomputes position based on window size).
unsigned int _textColor
void SetFont(int fontHandle) override
Set font handle to use for button text.
unsigned int _focusColor
bool IsFocused() const override
Check if this button currently has keyboard focus.
int GetFont() const override
Get current font handle used by this button.
const std::string & GetText() const override
Get button label text.
bool IsEnabled() const override
Check if button is enabled.
void SetSize(float width, float height) override
Set the button size.
bool IsMouseOver() const
Check whether the mouse cursor is currently over the button rectangle.
void Update() override
Update the button internal state (hover/pressed) and trigger callbacks.
Align GetAlign() const override
Get current alignment mode.
void SetTextColor(unsigned int color) override
Set label color.
void SetText(const std::string &text) override
Set button label text.
void SetCallback(std::function< void()> callback) override
Set callback invoked on click.
unsigned int _backgroundColor
void SetEnabled(bool enabled) override
Enable/disable the button.
void SetBackgroundColor(unsigned int color) override
Set button background color.
int GetTextSize() const override
Get label font size.
void GetPosition(float &x, float &y) const override
Get the current top-left position of the button.
void Render() override
Render the button.
void GetSize(float &width, float &height) const override
Get the current size of the button.
void SetTextSize(int size) override
Set label font size in pixels.
~RaylibButton() override=default
Destroy the RaylibButton.
Definition IButton.hpp:13
ButtonState
Button state enumeration.
Definition IButton.hpp:17
@ NORMAL
Default state.
Align
Alignment modes relative to the current window.
Definition IButton.hpp:33
@ NONE
No alignment.