R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
RaylibSlider.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** r-type
4** File description:
5** RaylibSlider - Raylib implementation of ISlider
6*/
7
8#pragma once
9
10#include <functional>
11#include <string>
12
14#include "UI/IButton.hpp"
15#include "UI/ISlider.hpp"
16
17namespace UI {
27 class RaylibSlider : public ISlider {
28 public:
33 explicit RaylibSlider(Graphics::IGraphics &graphics);
34
38 ~RaylibSlider() override = default;
39
41 void Update() override;
42
44 void Render() override;
45
47 void SetOnValueChanged(std::function<void(float)> callback) override;
48
50 void SetPosition(float x, float y) override;
51
53 void GetPosition(float &x, float &y) const override;
54
56 void SetSize(float width, float height) override;
57
59 void GetSize(float &width, float &height) const override;
60
62 void SetTrackColor(unsigned int color) override;
63
65 void SetFilledColor(unsigned int color) override;
66
68 void SetHandleColor(unsigned int color) override;
69
71 void SetHandleHoverColor(unsigned int color) override;
72
74 void SetMinValue(float minValue) override;
75
77 void SetMaxValue(float maxValue) override;
78
80 void SetValue(float value) override;
81
83 [[nodiscard]] float GetValue() const override;
84
86 void SetAlign(Align align) override;
87
89 [[nodiscard]] Align GetAlign() const override;
90
92 void ApplyAlignment() override;
93
95 void SetEnabled(bool enabled) override;
96
98 [[nodiscard]] bool IsEnabled() const override;
99
100 private:
104 [[nodiscard]] bool IsMouseOverHandle() const;
105
109 [[nodiscard]] bool IsMouseOverTrack() const;
110
115
119 void ClampValue();
120
122 std::function<void(float)> _onValueChanged{};
123
124 float _x{0.0F};
125 float _y{0.0F};
126 float _width{200.0F};
127 float _height{10.0F};
128
129 unsigned int _trackColor{0xFF505050};
130 unsigned int _filledColor{0xFF4CAF50};
131 unsigned int _handleColor{0xFFFFFFFF};
132 unsigned int _handleHoverColor{0xFFE0E0E0};
133
134 float _minValue{0.0F};
135 float _maxValue{100.0F};
136 float _value{50.0F};
137
138 bool _enabled{true};
139 bool _isDragging{false};
140 bool _isHovered{false};
141
143
144 static constexpr float HANDLE_RADIUS = 12.0F; // Increased from 8.0F for better visibility
145 static constexpr float TRACK_HEIGHT_RATIO = 0.4F; // Track height relative to total height
146 };
147} // namespace UI
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract interface for UI sliders.
Definition ISlider.hpp:30
Raylib implementation of the ISlider interface.
void Render() override
Render the slider.
~RaylibSlider() override=default
Destroy the RaylibSlider.
void SetMinValue(float minValue) override
Set the minimum value.
void SetValue(float value) override
Set the current value.
void SetHandleHoverColor(unsigned int color) override
Set the handle hover color.
void SetOnValueChanged(std::function< void(float)> callback) override
Set callback invoked when value changes.
std::function< void(float)> _onValueChanged
Align GetAlign() const override
Get the current alignment mode.
void SetEnabled(bool enabled) override
Enable or disable the slider.
unsigned int _handleColor
bool IsMouseOverTrack() const
Check whether the mouse cursor is over the track.
unsigned int _handleHoverColor
void Update() override
Update the slider internal state (hover, drag).
unsigned int _filledColor
bool IsEnabled() const override
Check if the slider is enabled.
void SetSize(float width, float height) override
Set the slider size.
void SetFilledColor(unsigned int color) override
Set the filled track color (portion before handle).
void ApplyAlignment() override
Apply the current alignment mode to the position.
void ClampValue()
Clamp value to [min, max] range.
static constexpr float TRACK_HEIGHT_RATIO
bool IsMouseOverHandle() const
Check whether the mouse cursor is over the handle.
static constexpr float HANDLE_RADIUS
void SetTrackColor(unsigned int color) override
Set the track color (unfilled portion).
void SetAlign(Align align) override
Set alignment mode relative to the window.
void UpdateValueFromMouse()
Update value based on mouse position.
void SetHandleColor(unsigned int color) override
Set the handle color.
void GetSize(float &width, float &height) const override
Get the current size of the slider.
void GetPosition(float &x, float &y) const override
Get the current top-left position of the slider.
unsigned int _trackColor
void SetMaxValue(float maxValue) override
Set the maximum value.
Graphics::IGraphics & _graphics
float GetValue() const override
Get the current value.
void SetPosition(float x, float y) override
Set the top-left position of the slider.
Definition IButton.hpp:13
Align
Alignment modes relative to the current window.
Definition IButton.hpp:33
@ NONE
No alignment.