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

A UI control that enables dragging of its underlying GUI element. More...

#include <UserInterface/CUIDraggable.h>

Inheritance diagram for Skylicht::UI::CUIDraggable:
Skylicht::UI::CUIBase

Public Member Functions

 CUIDraggable (CUIContainer *container, CGUIElement *element)
 Construct a draggable wrapper for a GUI element.
void lock (bool x, bool y)
 Lock/unlock movement on each axis.
void limitDragToRect (bool b)
 Enable or disable rectangular bounds for dragging.
void setBounds (const core::rectf &r)
 Set the rectangular bounds used when limitDragToRect(true) is active.
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 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(CUIDraggable *, float posX, float posY)> OnBeginDrag
 Callback invoked when a drag operation begins.
std::function< void(CUIDraggable *, float posX, float posY)> OnDrag
 Callback invoked while dragging (on pointer move).
std::function< void(CUIDraggable *, float posX, float posY)> OnEndDrag
 Callback invoked when the drag operation ends.
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

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 updateDrag ()
 Apply pointer movement to the underlying element.
virtual void onBeginDrag ()
 Internal hook invoked when a drag begins.
virtual void onEndDrag ()
 Internal hook invoked when a drag ends.

Protected Attributes

core::vector2df m_offset
core::vector3df m_oldPosition
bool m_lockX
bool m_lockY
bool m_limitDragToRect
core::rectf m_bounds
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 UI control that enables dragging of its underlying GUI element.

CUIDraggable extends CUIBase to provide simple pointer-driven dragging behavior for a CGUIElement. It converts pointer events into local movements of the element and exposes lifecycle callbacks for begin, ongoing, and end of drag operations.

Features:

Notes:

  • Coordinates passed to callbacks are world (canvas) coordinates.
  • Dragging behavior uses pointer events delivered by CUIBase (onPointerDown, onPointerMove, onPointerUp) and implements an internal offset to preserve the initial grab position.

Constructor & Destructor Documentation

◆ CUIDraggable()

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

Construct a draggable wrapper for a GUI element.

Parameters
containerParent CUIContainer that owns this UI object.
elementUnderlying CGUIElement to be moved by dragging.

The constructor registers this object with the container and prepares internal state. It does not automatically lock axes or bounds.

Member Function Documentation

◆ limitDragToRect()

void Skylicht::UI::CUIDraggable::limitDragToRect ( bool b)
inline

Enable or disable rectangular bounds for dragging.

Parameters
btrue to constrain dragging to m_bounds, false to allow free dragging.

◆ lock()

void Skylicht::UI::CUIDraggable::lock ( bool x,
bool y )
inline

Lock/unlock movement on each axis.

Parameters
xtrue to lock X axis, false to allow X movement.
ytrue to lock Y axis, false to allow Y movement.

◆ onBeginDrag()

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

Internal hook invoked when a drag begins.

Subclasses can override to provide additional state setup. Default implementation should invoke OnBeginDrag if set.

◆ onEndDrag()

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

Internal hook invoked when a drag ends.

Subclasses can override to provide teardown behavior. Default implementation should invoke OnEndDrag if set.

◆ onPointerDown()

virtual void Skylicht::UI::CUIDraggable::onPointerDown ( int pointerId,
float pointerX,
float pointerY )
protectedvirtual

Called when pointer is pressed down on the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate where press occurred.
pointerYWorld Y coordinate where press occurred.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerMove()

virtual void Skylicht::UI::CUIDraggable::onPointerMove ( int pointerId,
float pointerX,
float pointerY )
protectedvirtual

Called when pointer moves while over or dragging the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate of pointer.
pointerYWorld Y coordinate of pointer.

Reimplemented from Skylicht::UI::CUIBase.

◆ onPointerUp()

virtual void Skylicht::UI::CUIDraggable::onPointerUp ( int pointerId,
float pointerX,
float pointerY )
protectedvirtual

Called when pointer is released over the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate where release occurred.
pointerYWorld Y coordinate where release occurred.

Reimplemented from Skylicht::UI::CUIBase.

◆ setBounds()

void Skylicht::UI::CUIDraggable::setBounds ( const core::rectf & r)
inline

Set the rectangular bounds used when limitDragToRect(true) is active.

Parameters
rRectangle in the draggable's local coordinate space.

◆ updateDrag()

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

Apply pointer movement to the underlying element.

Computes the new target position using m_offset, optional axis locks (m_lockX, m_lockY) and optional bounds (m_limitDragToRect, m_bounds). After moving the element it updates m_oldPosition and invokes OnDrag.

Member Data Documentation

◆ OnBeginDrag

std::function<void(CUIDraggable*, float posX, float posY)> Skylicht::UI::CUIDraggable::OnBeginDrag

Callback invoked when a drag operation begins.

Parameters
thisPointer to the draggable instance.
posXWorld X coordinate where the drag began.
posYWorld Y coordinate where the drag began.

Typical use: start visual feedback or record initial state.

◆ OnDrag

std::function<void(CUIDraggable*, float posX, float posY)> Skylicht::UI::CUIDraggable::OnDrag

Callback invoked while dragging (on pointer move).

Parameters
thisPointer to the draggable instance.
posXCurrent world X coordinate.
posYCurrent world Y coordinate.

Typical use: update linked data, synchronize other UI, etc.

◆ OnEndDrag

std::function<void(CUIDraggable*, float posX, float posY)> Skylicht::UI::CUIDraggable::OnEndDrag

Callback invoked when the drag operation ends.

Parameters
thisPointer to the draggable instance.
posXFinal world X coordinate.
posYFinal world Y coordinate.

Typical use: finalize state, persist position, stop feedback.


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