R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
UI::RaylibSlider Class Reference

Raylib implementation of the ISlider interface. More...

#include <RaylibSlider.hpp>

Inheritance diagram for UI::RaylibSlider:
Inheritance graph
Collaboration diagram for UI::RaylibSlider:
Collaboration graph

Public Member Functions

 RaylibSlider (Graphics::IGraphics &graphics)
 Construct a new RaylibSlider.
 
 ~RaylibSlider () override=default
 Destroy the RaylibSlider.
 
void Update () override
 Update the slider internal state (hover, drag).
 
void Render () override
 Render the slider.
 
void SetOnValueChanged (std::function< void(float)> callback) override
 Set callback invoked when value changes.
 
void SetPosition (float x, float y) override
 Set the top-left position of the slider.
 
void GetPosition (float &x, float &y) const override
 Get the current top-left position of the slider.
 
void SetSize (float width, float height) override
 Set the slider size.
 
void GetSize (float &width, float &height) const override
 Get the current size of the slider.
 
void SetTrackColor (unsigned int color) override
 Set the track color (unfilled portion).
 
void SetFilledColor (unsigned int color) override
 Set the filled track color (portion before handle).
 
void SetHandleColor (unsigned int color) override
 Set the handle color.
 
void SetHandleHoverColor (unsigned int color) override
 Set the handle hover color.
 
void SetMinValue (float minValue) override
 Set the minimum value.
 
void SetMaxValue (float maxValue) override
 Set the maximum value.
 
void SetValue (float value) override
 Set the current value.
 
float GetValue () const override
 Get the current value.
 
void SetAlign (Align align) override
 Set alignment mode relative to the window.
 
Align GetAlign () const override
 Get the current alignment mode.
 
void ApplyAlignment () override
 Apply the current alignment mode to the position.
 
void SetEnabled (bool enabled) override
 Enable or disable the slider.
 
bool IsEnabled () const override
 Check if the slider is enabled.
 
- Public Member Functions inherited from UI::ISlider
virtual ~ISlider ()=default
 Virtual destructor.
 

Private Member Functions

bool IsMouseOverHandle () const
 Check whether the mouse cursor is over the handle.
 
bool IsMouseOverTrack () const
 Check whether the mouse cursor is over the track.
 
void UpdateValueFromMouse ()
 Update value based on mouse position.
 
void ClampValue ()
 Clamp value to [min, max] range.
 

Private Attributes

Graphics::IGraphics_graphics
 
std::function< void(float)> _onValueChanged {}
 
float _x {0.0F}
 
float _y {0.0F}
 
float _width {200.0F}
 
float _height {10.0F}
 
unsigned int _trackColor {0xFF505050}
 
unsigned int _filledColor {0xFF4CAF50}
 
unsigned int _handleColor {0xFFFFFFFF}
 
unsigned int _handleHoverColor {0xFFE0E0E0}
 
float _minValue {0.0F}
 
float _maxValue {100.0F}
 
float _value {50.0F}
 
bool _enabled {true}
 
bool _isDragging {false}
 
bool _isHovered {false}
 
Align _align {Align::NONE}
 

Static Private Attributes

static constexpr float HANDLE_RADIUS = 12.0F
 
static constexpr float TRACK_HEIGHT_RATIO = 0.4F
 

Detailed Description

Raylib implementation of the ISlider interface.

Features:

  • Draggable handle
  • Click on track to jump to position
  • Visual feedback (hover, pressed)
  • Configurable range and colors

Definition at line 27 of file RaylibSlider.hpp.

Constructor & Destructor Documentation

◆ RaylibSlider()

UI::RaylibSlider::RaylibSlider ( Graphics::IGraphics graphics)
explicit

Construct a new RaylibSlider.

Parameters
graphicsGraphics wrapper used for input and drawing.

Definition at line 15 of file RaylibSlider.cpp.

◆ ~RaylibSlider()

UI::RaylibSlider::~RaylibSlider ( )
overridedefault

Destroy the RaylibSlider.

Member Function Documentation

◆ ApplyAlignment()

void UI::RaylibSlider::ApplyAlignment ( )
overridevirtual

Apply the current alignment mode to the position.

Note
This modifies the position based on the align setting.

Implements UI::ISlider.

Definition at line 170 of file RaylibSlider.cpp.

References _align, _graphics, _height, _width, _x, _y, UI::CENTER_BOTH, UI::CENTER_HORIZONTAL, UI::CENTER_VERTICAL, Graphics::IGraphics::GetScreenHeight(), Graphics::IGraphics::GetScreenWidth(), and UI::NONE.

Here is the call graph for this function:

◆ ClampValue()

void UI::RaylibSlider::ClampValue ( )
private

Clamp value to [min, max] range.

Definition at line 256 of file RaylibSlider.cpp.

References _maxValue, _minValue, and _value.

Referenced by SetMaxValue(), SetMinValue(), and SetValue().

◆ GetAlign()

Align UI::RaylibSlider::GetAlign ( ) const
overridevirtual

Get the current alignment mode.

Returns
Alignment mode.

Implements UI::ISlider.

Definition at line 166 of file RaylibSlider.cpp.

References _align.

◆ GetPosition()

void UI::RaylibSlider::GetPosition ( float &  x,
float &  y 
) const
overridevirtual

Get the current top-left position of the slider.

Parameters
xOutput X position in pixels.
yOutput Y position in pixels.

Implements UI::ISlider.

Definition at line 106 of file RaylibSlider.cpp.

References _x, and _y.

◆ GetSize()

void UI::RaylibSlider::GetSize ( float &  width,
float &  height 
) const
overridevirtual

Get the current size of the slider.

Parameters
widthOutput width in pixels.
heightOutput height in pixels.

Implements UI::ISlider.

Definition at line 116 of file RaylibSlider.cpp.

References _height, and _width.

◆ GetValue()

float UI::RaylibSlider::GetValue ( ) const
overridevirtual

Get the current value.

Returns
Current value.

Implements UI::ISlider.

Definition at line 158 of file RaylibSlider.cpp.

References _value.

◆ IsEnabled()

bool UI::RaylibSlider::IsEnabled ( ) const
overridevirtual

Check if the slider is enabled.

Returns
true if enabled.

Implements UI::ISlider.

Definition at line 199 of file RaylibSlider.cpp.

References _enabled.

◆ IsMouseOverHandle()

bool UI::RaylibSlider::IsMouseOverHandle ( ) const
private

Check whether the mouse cursor is over the handle.

Definition at line 203 of file RaylibSlider.cpp.

References _graphics, _height, _maxValue, _minValue, _value, _width, _x, _y, Graphics::IGraphics::GetMouseX(), Graphics::IGraphics::GetMouseY(), and HANDLE_RADIUS.

Referenced by Update().

Here is the call graph for this function:

◆ IsMouseOverTrack()

bool UI::RaylibSlider::IsMouseOverTrack ( ) const
private

Check whether the mouse cursor is over the track.

Definition at line 224 of file RaylibSlider.cpp.

References _graphics, _height, _width, _x, _y, Graphics::IGraphics::GetMouseX(), and Graphics::IGraphics::GetMouseY().

Referenced by Update().

Here is the call graph for this function:

◆ Render()

void UI::RaylibSlider::Render ( )
overridevirtual

Render the slider.

Note
Must be called between the backend BeginDrawing/EndDrawing calls.

Implements UI::ISlider.

Definition at line 53 of file RaylibSlider.cpp.

References _filledColor, _graphics, _handleColor, _handleHoverColor, _height, _isDragging, _isHovered, _maxValue, _minValue, _trackColor, _value, _width, _x, _y, Graphics::IGraphics::DrawCircle(), Graphics::IGraphics::DrawCircleFilled(), Graphics::IGraphics::DrawRectangle(), HANDLE_RADIUS, and TRACK_HEIGHT_RATIO.

Here is the call graph for this function:

◆ SetAlign()

void UI::RaylibSlider::SetAlign ( Align  align)
overridevirtual

Set alignment mode relative to the window.

Parameters
alignAlignment mode.

Implements UI::ISlider.

Definition at line 162 of file RaylibSlider.cpp.

References _align.

◆ SetEnabled()

void UI::RaylibSlider::SetEnabled ( bool  enabled)
overridevirtual

Enable or disable the slider.

Parameters
enabledtrue to enable, false to disable.

Implements UI::ISlider.

Definition at line 191 of file RaylibSlider.cpp.

References _enabled, _isDragging, and _isHovered.

◆ SetFilledColor()

void UI::RaylibSlider::SetFilledColor ( unsigned int  color)
overridevirtual

Set the filled track color (portion before handle).

Parameters
colorColor in ARGB format (0xAARRGGBB).

Implements UI::ISlider.

Definition at line 125 of file RaylibSlider.cpp.

References _filledColor.

◆ SetHandleColor()

void UI::RaylibSlider::SetHandleColor ( unsigned int  color)
overridevirtual

Set the handle color.

Parameters
colorColor in ARGB format (0xAARRGGBB).

Implements UI::ISlider.

Definition at line 129 of file RaylibSlider.cpp.

References _handleColor.

◆ SetHandleHoverColor()

void UI::RaylibSlider::SetHandleHoverColor ( unsigned int  color)
overridevirtual

Set the handle hover color.

Parameters
colorColor in ARGB format (0xAARRGGBB).

Implements UI::ISlider.

Definition at line 133 of file RaylibSlider.cpp.

References _handleHoverColor.

◆ SetMaxValue()

void UI::RaylibSlider::SetMaxValue ( float  maxValue)
overridevirtual

Set the maximum value.

Parameters
maxValueMaximum value.

Implements UI::ISlider.

Definition at line 142 of file RaylibSlider.cpp.

References _maxValue, and ClampValue().

Here is the call graph for this function:

◆ SetMinValue()

void UI::RaylibSlider::SetMinValue ( float  minValue)
overridevirtual

Set the minimum value.

Parameters
minValueMinimum value.

Implements UI::ISlider.

Definition at line 137 of file RaylibSlider.cpp.

References _minValue, and ClampValue().

Here is the call graph for this function:

◆ SetOnValueChanged()

void UI::RaylibSlider::SetOnValueChanged ( std::function< void(float)>  callback)
overridevirtual

Set callback invoked when value changes.

Parameters
callbackFunction called when the slider value changes.

Implements UI::ISlider.

Definition at line 97 of file RaylibSlider.cpp.

References _onValueChanged.

◆ SetPosition()

void UI::RaylibSlider::SetPosition ( float  x,
float  y 
)
overridevirtual

Set the top-left position of the slider.

Parameters
xX position in pixels.
yY position in pixels.

Implements UI::ISlider.

Definition at line 101 of file RaylibSlider.cpp.

References _x, and _y.

◆ SetSize()

void UI::RaylibSlider::SetSize ( float  width,
float  height 
)
overridevirtual

Set the slider size.

Parameters
widthWidth in pixels (track length).
heightHeight in pixels (track thickness).

Implements UI::ISlider.

Definition at line 111 of file RaylibSlider.cpp.

References _height, and _width.

◆ SetTrackColor()

void UI::RaylibSlider::SetTrackColor ( unsigned int  color)
overridevirtual

Set the track color (unfilled portion).

Parameters
colorColor in ARGB format (0xAARRGGBB).

Implements UI::ISlider.

Definition at line 121 of file RaylibSlider.cpp.

References _trackColor.

◆ SetValue()

void UI::RaylibSlider::SetValue ( float  value)
overridevirtual

Set the current value.

Parameters
valueCurrent value (will be clamped to [min, max]).

Implements UI::ISlider.

Definition at line 147 of file RaylibSlider.cpp.

References _onValueChanged, _value, and ClampValue().

Here is the call graph for this function:

◆ Update()

void UI::RaylibSlider::Update ( )
overridevirtual

Update the slider internal state (hover, drag).

Note
Should be called once per frame.

Implements UI::ISlider.

Definition at line 17 of file RaylibSlider.cpp.

References _enabled, _graphics, _isDragging, _isHovered, Graphics::IGraphics::IsMouseButtonDown(), Graphics::IGraphics::IsMouseButtonPressed(), IsMouseOverHandle(), IsMouseOverTrack(), and UpdateValueFromMouse().

Here is the call graph for this function:

◆ UpdateValueFromMouse()

void UI::RaylibSlider::UpdateValueFromMouse ( )
private

Update value based on mouse position.

Definition at line 232 of file RaylibSlider.cpp.

References _graphics, _maxValue, _minValue, _onValueChanged, _value, _width, _x, and Graphics::IGraphics::GetMouseX().

Referenced by Update().

Here is the call graph for this function:

Member Data Documentation

◆ _align

Align UI::RaylibSlider::_align {Align::NONE}
private

Definition at line 142 of file RaylibSlider.hpp.

Referenced by ApplyAlignment(), GetAlign(), and SetAlign().

◆ _enabled

bool UI::RaylibSlider::_enabled {true}
private

Definition at line 138 of file RaylibSlider.hpp.

Referenced by IsEnabled(), SetEnabled(), and Update().

◆ _filledColor

unsigned int UI::RaylibSlider::_filledColor {0xFF4CAF50}
private

Definition at line 130 of file RaylibSlider.hpp.

Referenced by Render(), and SetFilledColor().

◆ _graphics

Graphics::IGraphics& UI::RaylibSlider::_graphics
private

◆ _handleColor

unsigned int UI::RaylibSlider::_handleColor {0xFFFFFFFF}
private

Definition at line 131 of file RaylibSlider.hpp.

Referenced by Render(), and SetHandleColor().

◆ _handleHoverColor

unsigned int UI::RaylibSlider::_handleHoverColor {0xFFE0E0E0}
private

Definition at line 132 of file RaylibSlider.hpp.

Referenced by Render(), and SetHandleHoverColor().

◆ _height

float UI::RaylibSlider::_height {10.0F}
private

◆ _isDragging

bool UI::RaylibSlider::_isDragging {false}
private

Definition at line 139 of file RaylibSlider.hpp.

Referenced by Render(), SetEnabled(), and Update().

◆ _isHovered

bool UI::RaylibSlider::_isHovered {false}
private

Definition at line 140 of file RaylibSlider.hpp.

Referenced by Render(), SetEnabled(), and Update().

◆ _maxValue

float UI::RaylibSlider::_maxValue {100.0F}
private

◆ _minValue

float UI::RaylibSlider::_minValue {0.0F}
private

◆ _onValueChanged

std::function<void(float)> UI::RaylibSlider::_onValueChanged {}
private

Definition at line 122 of file RaylibSlider.hpp.

Referenced by SetOnValueChanged(), SetValue(), and UpdateValueFromMouse().

◆ _trackColor

unsigned int UI::RaylibSlider::_trackColor {0xFF505050}
private

Definition at line 129 of file RaylibSlider.hpp.

Referenced by Render(), and SetTrackColor().

◆ _value

float UI::RaylibSlider::_value {50.0F}
private

◆ _width

float UI::RaylibSlider::_width {200.0F}
private

◆ _x

float UI::RaylibSlider::_x {0.0F}
private

◆ _y

float UI::RaylibSlider::_y {0.0F}
private

◆ HANDLE_RADIUS

constexpr float UI::RaylibSlider::HANDLE_RADIUS = 12.0F
staticconstexprprivate

Definition at line 144 of file RaylibSlider.hpp.

Referenced by IsMouseOverHandle(), and Render().

◆ TRACK_HEIGHT_RATIO

constexpr float UI::RaylibSlider::TRACK_HEIGHT_RATIO = 0.4F
staticconstexprprivate

Definition at line 145 of file RaylibSlider.hpp.

Referenced by Render().


The documentation for this class was generated from the following files: