Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::UI::CUISlider Class Reference

A horizontal slider control with background, fill bar and draggable handle. More...

#include <UserInterface/CUISlider.h>

Inheritance diagram for Skylicht::UI::CUISlider:
Skylicht::UI::CUIBase

Public Member Functions

 CUISlider (CUIContainer *container, CGUIElement *element)
 Construct a slider that wraps an existing CGUIElement.
 CUISlider (CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIElement *fillbar, CGUIElement *handle)
 Construct a slider with explicit sub-elements.
void setValue (float value, bool invokeEvent=true)
 Set the slider value and optionally invoke the OnChanged event.
float getValue ()
 Get the current normalized slider value in range [0,1].
Public Member Functions inherited from Skylicht::UI::CUIBase
 CUIBase (CUIContainer *container, CGUIElement *element)
 Constructor.
virtual ~CUIBase ()
 Virtual destructor.
void remove ()
 Remove this UI object from its container and perform cleanup.
virtual void update ()
virtual void setEnable (bool b)
 Enable or disable this UI object.
virtual void setVisible (bool b)
 Set visibility of this UI object.
bool isEnable ()
 Returns true if the object is enabled.
bool isVisible ()
 Returns true if the object is visible.
int getPointerId ()
 Get the pointer ID associated with this UI object.
void setPointerId (int id)
 Set the pointer ID for this UI object.
void resetTouch ()
 Reset pointer internal state (hover/down).
void setContinueGameEvent (bool b)
 Control whether input events continue to the game layer.
bool isContinueGameEvent ()
 Returns true when events are allowed to continue to the game layer.
bool isContinueKeyEvent ()
void setSkipPointerEventWhenDrag (bool b)
 When true pointer events will be skipped while dragging.
bool isPointerHover ()
 Returns true if pointer is hovering this object.
bool isPointerDown ()
 Returns true if pointer is down on this object.
CGUIElementgetElement ()
 Get the underlying CGUIElement pointer.
CCanvasgetCanvas ()
 Retrieve the canvas that the underlying element belongs to.
CUIContainergetContainer ()
 Get parent container.
core::vector3dfgetRectTransform ()
 Returns a pointer to the internal rect transform (4 corners).
void getRectTransform (CGUIElement *element, core::vector3df *t)
virtual void onPointerHover (int pointerId, float pointerX, float pointerY)
 Called when pointer enters or hovers over the element.
virtual void onPointerOut (int pointerId, float pointerX, float pointerY)
 Called when pointer leaves the element.
virtual void onPointerDown (int pointerId, float pointerX, float pointerY)
 Called when pointer is pressed down on the element.
virtual void onPointerUp (int pointerId, float pointerX, float pointerY)
 Called when pointer is released over the element.
virtual void onPointerMove (int pointerId, float pointerX, float pointerY)
 Called when pointer moves while over or dragging the element.
virtual void onPressed ()
 Called when the element is considered "pressed" (high-level event). Subclasses may trigger OnPressed callback from here.
virtual void onFocus ()
 Called when element receives focus.
virtual void onLostFocus ()
 Called when element loses focus.
virtual void onKeyEvent (const SEvent &event)
 Called when a keyboard event is delivered to this element.
void startMotion (EMotionEvent event)
 Start motions associated with a specific motion event.
void stopMotion (EMotionEvent event)
 Stop motions associated with a specific motion event.
bool isMotionPlaying (EMotionEvent event)
 Query whether any motion is currently playing for the given event.
virtual CMotionaddMotion (EMotionEvent event, CMotion *motion)
 Add a CMotion instance to the list for the given event. The motion will be initialized and managed by this object.
virtual CMotionaddMotion (EMotionEvent event, CGUIElement *element, CMotion *motion)
 Add a CMotion instance bound to a specific CGUIElement for the given event.
bool removeMotion (EMotionEvent event, CMotion *motion)
 Remove a motion instance from the given event list.
void removeMotions (EMotionEvent event)
 Remove all motions attached to the specified event.
std::vector< CMotion * > & getMotions (EMotionEvent event)
 Access the motion vector for a specific event.
void convertToUICoordinate (float &pointerX, float &pointerY)
 Convert screen pointer coordinates to this UI object's local UI coordinates.
void convertWorldToLocal (CGUIElement *element, float &x, float &y)
 Convert world coordinates to the local coordinate space of a CGUIElement.
void convertLocalToWorld (CGUIElement *element, float &x, float &y)
 Convert local coordinates of a CGUIElement to world coordinates.
virtual bool acceptDragFocus ()
 Whether this UI element should accept drag-focus when the pointer is already down and the user drags over it.
void setSoundId (int slot, int soundId)
 Set the sound id associated with this UI object.
int getSoundId (int slot)
 Get the sound id associated with this UI object.
void setUserData (void *data)
 Attach an application-defined pointer to this UI object.
void * getUserData ()
 Retrieve the pointer previously set via setUserData.

Public Attributes

std::function< void(CUISlider *, float)> OnChanged
 Event invoked when slider value changes.
Public Attributes inherited from Skylicht::UI::CUIBase
std::function< void(int, float, float)> OnPointerHover
std::function< void(int, float, float)> OnPointerOut
std::function< void(int, float, float)> OnPointerDown
std::function< void(int, float, float)> OnPointerUp
std::function< void(int, float, float, bool)> OnPointerMove
std::function< void(CUIBase *)> OnPressed
std::function< void(CUIBase *)> OnFocus
std::function< void(CUIBase *)> OnLostFocus
std::function< void(CUIBase *, const SEvent &)> OnKeyEvent
std::function< void(CUIBase *, EMotionEvent)> OnMotionFinish [(int) EMotionEvent::NumEvent]

Protected Member Functions

void init ()
 Initialize internal state and locate child elements.
virtual void onBeginDrag ()
 Called when a drag begins (pointer down on handle).
virtual void updateDrag ()
 Update the slider value according to current pointer position.
virtual void onEndDrag ()
 Called when a drag ends (pointer up).

Protected Attributes

CGUIElementm_background
CGUIElementm_fillBar
CGUIElementm_handle
CGUIMaskm_mask
CUIBasem_bgHander
CUIBasem_buttonHander
float m_value
float m_handleWidth
core::vector2df m_offset
Protected Attributes inherited from Skylicht::UI::CUIBase
CUIContainerm_container
CGUIElementm_element
core::vector3df m_rectTransform [4]
std::vector< CMotion * > m_motions [(int) EMotionEvent::NumEvent]
bool m_enable
bool m_visible
bool m_isPointerHover
bool m_isPointerDown
bool m_skipPointerEventWhenDrag
bool m_continueGameEvent
bool m_continueKeyEvent
int m_pointerId
float m_pointerDownX
float m_pointerDownY
int m_soundId [4]
void * m_userData

Detailed Description

A horizontal slider control with background, fill bar and draggable handle.

CUISlider is a UI wrapper around GUI elements that implements a simple one-dimensional slider. The class tracks a normalized value in range [0, 1] and updates the fill and handle positions accordingly. It receives pointer events from the containing CUIContainer via CUIBase overrides and handles dragging logic internally.

Typical usage:

  • Create slider with underlying CGUIElement (and optional child elements for background, fillbar and handle).
  • Subscribe to OnChanged to receive value updates.
  • Call setValue() to programmatically update slider value.

Responsibilities:

Threading: UI code runs on the main/game thread; callbacks are invoked synchronously from the slider when value changes.

Constructor & Destructor Documentation

◆ CUISlider() [1/2]

Skylicht::UI::CUISlider::CUISlider ( CUIContainer * container,
CGUIElement * element )

Construct a slider that wraps an existing CGUIElement.

Parameters
containerParent CUIContainer that owns this UI object.
elementUnderlying CGUIElement used as the root element for the slider.

The constructor will attempt to locate child GUI elements (fill, handle) inside element or rely on the explicit constructor overload which accepts those child elements directly.

◆ CUISlider() [2/2]

Skylicht::UI::CUISlider::CUISlider ( CUIContainer * container,
CGUIElement * element,
CGUIElement * bg,
CGUIElement * fillbar,
CGUIElement * handle )

Construct a slider with explicit sub-elements.

Parameters
containerParent CUIContainer.
elementRoot GUI element.
bgBackground/track element.
fillbarFill portion element.
handleDraggable handle element.

Use this overload when you have separate GUI elements for the background, fill and handle to ensure the slider uses them directly.

Member Function Documentation

◆ init()

void Skylicht::UI::CUISlider::init ( )
protected

Initialize internal state and locate child elements.

Called by constructors to perform common setup:

  • cache handle width,
  • configure mask if available,
  • wire pointer callbacks on m_handle/m_buttonHander if present.

◆ onBeginDrag()

virtual void Skylicht::UI::CUISlider::onBeginDrag ( )
protectedvirtual

Called when a drag begins (pointer down on handle).

This captures the initial pointer offset and prepares slider for updateDrag() calls while the pointer moves.

◆ onEndDrag()

virtual void Skylicht::UI::CUISlider::onEndDrag ( )
protectedvirtual

Called when a drag ends (pointer up).

Finalizes the value and releases any capture state.

◆ setValue()

void Skylicht::UI::CUISlider::setValue ( float value,
bool invokeEvent = true )

Set the slider value and optionally invoke the OnChanged event.

Parameters
valueNew value to set. Values are clamped to [0, 1].
invokeEventWhen true (default) the OnChanged callback will be executed if value changed.

This method updates the internal m_value, moves the fill and handle GUI elements to reflect the change and triggers the change callback.

◆ updateDrag()

virtual void Skylicht::UI::CUISlider::updateDrag ( )
protectedvirtual

Update the slider value according to current pointer position.

This method should compute the new normalized value based on pointer coordinates relative to the slider track, update visuals and optionally fire OnChanged.

Member Data Documentation

◆ OnChanged

std::function<void(CUISlider*, float)> Skylicht::UI::CUISlider::OnChanged

Event invoked when slider value changes.

Signature: void(CUISlider* sender, float newValue)

  • sender is the slider instance that produced the event.
  • newValue is the new normalized value in [0, 1].

The event is invoked by setValue() and during dragging (when the underlying value changes). Listeners should not assume reentrancy protection; if they mutate the slider, behaviour is the caller's responsibility.


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