SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Slider Class Reference

A draggable UI slider component. More...

#include <Slider.h>

Inheritance diagram for Slider:
Inheritance graph

Public Member Functions

 Slider ()=default
 Default constructor.
 
 Slider (const Slider &)=delete
 
Slideroperator= (const Slider &)=delete
 
 Slider (std::string sliderKnobKey, std::string sliderBarKey)
 Constructs a Slider with specified knob and bar texture keys.
 
void SetOrigin (float x, float y)
 Sets the origin of the slider (for transformations).
 
void SetPosition (float x, float y)
 Sets the position of the slider.
 
void SetAngleRadians (float rad)
 Sets the angle of the slider in radians.
 
void SetAngleDegrees (float deg)
 Sets the angle of the slider in degrees.
 
void SetScaleFactor (float x, float y)
 Sets the scale factor of the slider.
 
void SetScalePixel (float x, float y)
 Sets the scale of the slider in pixels.
 
float GetWidth () const
 Gets the width of the slider (bar) in pixels.
 
float GetHeight () const
 Gets the height of the slider (bar) in pixels.
 
float GetAngle () const
 Gets the angle of the slider in radians.
 
float GetScaleX () const
 Gets the x-scale factor of the slider.
 
float GetScaleY () const
 Gets the y-scale factor of the slider.
 
void SetLayer (int layer) override
 Sets the rendering layer of the slider.
 
void SetOnPressCommand (UICommand *cmd)
 Sets the command to be executed when the slider is pressed.
 
void SetValue (float value)
 Sets the value of the slider (0.0 to 1.0).
 
float GetValue () const
 Gets the current value of the slider (0.0 to 1.0).
 
- Public Member Functions inherited from UIComponent
virtual ~UIComponent ()=default
 Virtual destructor.
 
int GetLayer () const
 Gets the rendering layer of the component.
 
UIComponentType GetType () const
 Gets the type of the UI component.
 
bool IsEnabled () const
 Returns whether the component is enabled or not.
 
void SetEnabled (bool enabled)
 Sets the enabled state of the component.
 
void SetOwningCanvas (Canvas *canvas)
 Gets the owning canvas of the component.
 

Private Member Functions

void Render () override
 Renders the slider (bar and knob).
 
void OnPress () override
 Handles press events (mouse interaction) for the slider.
 
bool IsMouseOver (float xPos, float yPos) override
 Checks if the mouse is over the slider.
 
void UpdateWorld ()
 Updates the world matrix of the slider.
 

Private Attributes

SUNENGINESpritepKnobSprite
 Sprite for the slider knob.
 
SUNENGINESpritepBarSprite
 Sprite for the slider bar.
 
Matrix trans
 Transformation matrix.
 
Matrix rot
 Rotation matrix.
 
Matrix scale
 Scale matrix.
 
float posX
 X position of the slider center.
 
float posY
 Y position of the slider center.
 
float angle
 Angle of the slider in radians.
 
float scaleX
 X scale factor.
 
float scaleY
 Y scale factor.
 
float value
 Current value of the slider (0.0 to 1.0).
 
UICommandpOnPressCommand
 Command to execute when the slider is pressed.
 

Additional Inherited Members

- Protected Attributes inherited from UIComponent
bool Enabled = true
 Indicates if the component is enabled or not.
 
int Layer = 0
 Rendering layer in.
 
UIComponentType Type = UIComponentType::None
 Type of the UI component.
 
CanvaspOwningCanvas = nullptr
 Pointer to the owning canvas, if any.
 

Detailed Description

A draggable UI slider component.

The Slider class represents a UI slider that allows users to select a value by dragging a knob along a bar. It supports custom sprites for the knob and bar, and can be positioned, rotated, and scaled. The slider can execute a command when pressed, and its value can be set or queried programmatically.

Example usage:

Slider* slider = new Slider("KnobTextureKey", "BarTextureKey");
slider->SetOrigin(0.5f, 0.5f);
slider->SetPosition(400.0f, 200.0f);
slider->SetScaleFactor(1.0f, 1.0f);
slider->SetOnPressCommand(new MySliderCommand());
canvas->AddComponent(slider);
void SetOrigin(float x, float y)
Sets the origin of the slider (for transformations).
Definition Slider.cpp:35
void SetPosition(float x, float y)
Sets the position of the slider.
Definition Slider.cpp:42
void SetOnPressCommand(UICommand *cmd)
Sets the command to be executed when the slider is pressed.
Definition Slider.cpp:146
void SetScaleFactor(float x, float y)
Sets the scale factor of the slider.
Definition Slider.cpp:58
Slider()=default
Default constructor.
See also
Canvas, UICommand, SUNENGINESprite

Constructor & Destructor Documentation

◆ Slider()

Slider::Slider ( std::string sliderKnobKey,
std::string sliderBarKey )

Constructs a Slider with specified knob and bar texture keys.

Parameters
sliderKnobKeyThe texture key for the slider knob.
sliderBarKeyThe texture key for the slider bar.

Member Function Documentation

◆ GetAngle()

float Slider::GetAngle ( ) const

Gets the angle of the slider in radians.

Returns
The angle in radians.

◆ GetHeight()

float Slider::GetHeight ( ) const

Gets the height of the slider (bar) in pixels.

Returns
The height of the slider.

◆ GetScaleX()

float Slider::GetScaleX ( ) const

Gets the x-scale factor of the slider.

Returns
The x-scale factor.

◆ GetScaleY()

float Slider::GetScaleY ( ) const

Gets the y-scale factor of the slider.

Returns
The y-scale factor.

◆ GetValue()

float Slider::GetValue ( ) const

Gets the current value of the slider (0.0 to 1.0).

Returns
The current slider value.

◆ GetWidth()

float Slider::GetWidth ( ) const

Gets the width of the slider (bar) in pixels.

Returns
The width of the slider.

◆ IsMouseOver()

bool Slider::IsMouseOver ( float xPos,
float yPos )
overrideprivatevirtual

Checks if the mouse is over the slider.

Parameters
xPosThe x-coordinate of the mouse position.
yPosThe y-coordinate of the mouse position.
Returns
True if the mouse is over the slider, false otherwise.

Implements UIComponent.

◆ OnPress()

void Slider::OnPress ( )
overrideprivatevirtual

Handles press events (mouse interaction) for the slider.

Implements UIComponent.

Here is the call graph for this function:

◆ Render()

void Slider::Render ( )
overrideprivatevirtual

Renders the slider (bar and knob).

Implements UIComponent.

Here is the call graph for this function:

◆ SetAngleDegrees()

void Slider::SetAngleDegrees ( float deg)

Sets the angle of the slider in degrees.

Parameters
degThe angle in degrees.

◆ SetAngleRadians()

void Slider::SetAngleRadians ( float rad)

Sets the angle of the slider in radians.

Parameters
radThe angle in radians.

◆ SetLayer()

void Slider::SetLayer ( int layer)
overridevirtual

Sets the rendering layer of the slider.

Parameters
layerThe layer index.

Reimplemented from UIComponent.

◆ SetOnPressCommand()

void Slider::SetOnPressCommand ( UICommand * cmd)

Sets the command to be executed when the slider is pressed.

Parameters
cmdThe command to execute.

◆ SetOrigin()

void Slider::SetOrigin ( float x,
float y )

Sets the origin of the slider (for transformations).

Parameters
xThe x-coordinate of the origin (0.0 to 1.0).
yThe y-coordinate of the origin (0.0 to 1.0).

◆ SetPosition()

void Slider::SetPosition ( float x,
float y )

Sets the position of the slider.

Parameters
xThe x-coordinate of the slider's center.
yThe y-coordinate of the slider's center.

◆ SetScaleFactor()

void Slider::SetScaleFactor ( float x,
float y )

Sets the scale factor of the slider.

Parameters
xThe x-scale factor.
yThe y-scale factor.

◆ SetScalePixel()

void Slider::SetScalePixel ( float x,
float y )

Sets the scale of the slider in pixels.

Parameters
xThe width in pixels.
yThe height in pixels.

◆ SetValue()

void Slider::SetValue ( float value)

Sets the value of the slider (0.0 to 1.0).

Parameters
valueThe new value for the slider.
Here is the caller graph for this function:

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