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

Base wrapper class that connects a UI container and a GUI element. More...

#include <UserInterface/CUIBase.h>

Inheritance diagram for Skylicht::UI::CUIBase:
Skylicht::UI::CUIButton Skylicht::UI::CUICheckbox Skylicht::UI::CUIDraggable Skylicht::UI::CUIListView Skylicht::UI::CUIProgressBar Skylicht::UI::CUISlider Skylicht::UI::CUISwitch Skylicht::UI::CUITextBox

Public Member Functions

 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(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 Attributes

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

Base wrapper class that connects a UI container and a GUI element.

CUIBase represents a UI object hosted inside a CUIContainer and backed by a CGUIElement. It manages basic UI state (enable/visible), pointer state, and motion sequences (EMotionEvent).

Typical responsibilities:

  • Forward pointer events (hover, down, up, move) to higher-level callbacks.
  • Manage CMotion instances per motion event and start/stop them.
  • Provide utility conversion between world/local UI coordinates.

Subclasses (buttons, sliders, checkboxes, etc.) override virtual event handlers to implement control-specific behavior.

Constructor & Destructor Documentation

◆ CUIBase()

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

Constructor.

Parameters
containerParent container that owns this UI object.
elementUnderlying GUI element associated with this object.

Member Function Documentation

◆ acceptDragFocus()

virtual bool Skylicht::UI::CUIBase::acceptDragFocus ( )
inlinevirtual

Whether this UI element should accept drag-focus when the pointer is already down and the user drags over it.

When the pointer press starts on one control and the user drags over another control, the container (CUIContainer) may call onPointerDown(...) on the hovered element if it "accepts drag focus". This lets controls like list or grid views start scrolling/ handling a drag while the pointer is still pressed.

Default behaviour returns false so only the originally pressed control receives the pointer down. Subclasses that should grab the drag interaction (e.g. CUIListView) should override this to return true.

Reimplemented in Skylicht::UI::CUIListView.

◆ addMotion() [1/2]

virtual CMotion * Skylicht::UI::CUIBase::addMotion ( EMotionEvent event,
CGUIElement * element,
CMotion * motion )
virtual

Add a CMotion instance bound to a specific CGUIElement for the given event.

Parameters
eventMotion event to attach the motion to.
elementElement that the motion will operate on.
motionMotion instance.
Returns
The same CMotion pointer.

◆ addMotion() [2/2]

virtual CMotion * Skylicht::UI::CUIBase::addMotion ( EMotionEvent event,
CMotion * motion )
virtual

Add a CMotion instance to the list for the given event. The motion will be initialized and managed by this object.

Parameters
eventMotion event to attach the motion to.
motionPointer to CMotion (ownership semantics: container manages lifetime).
Returns
The same CMotion pointer.

◆ convertLocalToWorld()

void Skylicht::UI::CUIBase::convertLocalToWorld ( CGUIElement * element,
float & x,
float & y )

Convert local coordinates of a CGUIElement to world coordinates.

Parameters
elementElement whose local space is the source.
xIn/out: local X -> world X.
yIn/out: local Y -> world Y.

◆ convertToUICoordinate()

void Skylicht::UI::CUIBase::convertToUICoordinate ( float & pointerX,
float & pointerY )

Convert screen pointer coordinates to this UI object's local UI coordinates.

Parameters
pointerXIn/out: pointer X coordinate. Converted to local coordinates.
pointerYIn/out: pointer Y coordinate. Converted to local coordinates.

◆ convertWorldToLocal()

void Skylicht::UI::CUIBase::convertWorldToLocal ( CGUIElement * element,
float & x,
float & y )

Convert world coordinates to the local coordinate space of a CGUIElement.

Parameters
elementElement whose local space is the target.
xIn/out: world X -> local X.
yIn/out: world Y -> local Y.

◆ getMotions()

std::vector< CMotion * > & Skylicht::UI::CUIBase::getMotions ( EMotionEvent event)
inline

Access the motion vector for a specific event.

Parameters
eventMotion event.
Returns
Reference to vector of CMotion* for the event.

◆ getSoundId()

int Skylicht::UI::CUIBase::getSoundId ( int slot)
inline

Get the sound id associated with this UI object.

Returns
The currently set sound id (implementation-defined meaning).

◆ getUserData()

void * Skylicht::UI::CUIBase::getUserData ( )
inline

Retrieve the pointer previously set via setUserData.

Returns
The stored user data pointer, or nullptr if none was set.

◆ isMotionPlaying()

bool Skylicht::UI::CUIBase::isMotionPlaying ( EMotionEvent event)

Query whether any motion is currently playing for the given event.

Parameters
eventMotion event to query.
Returns
true if at least one motion is playing.

◆ onFocus()

virtual void Skylicht::UI::CUIBase::onFocus ( )
virtual

Called when element receives focus.

Reimplemented in Skylicht::UI::CUITextBox.

◆ onKeyEvent()

virtual void Skylicht::UI::CUIBase::onKeyEvent ( const SEvent & event)
virtual

Called when a keyboard event is delivered to this element.

Parameters
eventOriginal SEvent from the engine input system.

Reimplemented in Skylicht::UI::CUITextBox.

◆ onLostFocus()

virtual void Skylicht::UI::CUIBase::onLostFocus ( )
virtual

Called when element loses focus.

Reimplemented in Skylicht::UI::CUITextBox.

◆ onPointerDown()

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

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 in Skylicht::UI::CUIDraggable, Skylicht::UI::CUIListView, and Skylicht::UI::CUITextBox.

◆ onPointerHover()

virtual void Skylicht::UI::CUIBase::onPointerHover ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer enters or hovers over the element.

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

Reimplemented in Skylicht::UI::CUIButton, and Skylicht::UI::CUITextBox.

◆ onPointerMove()

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

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 in Skylicht::UI::CUIDraggable, Skylicht::UI::CUIListView, and Skylicht::UI::CUITextBox.

◆ onPointerOut()

virtual void Skylicht::UI::CUIBase::onPointerOut ( int pointerId,
float pointerX,
float pointerY )
virtual

Called when pointer leaves the element.

Parameters
pointerIdID of the pointer device.
pointerXWorld X coordinate at time of out event.
pointerYWorld Y coordinate at time of out event.

Reimplemented in Skylicht::UI::CUIButton, and Skylicht::UI::CUITextBox.

◆ onPointerUp()

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

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 in Skylicht::UI::CUIDraggable, Skylicht::UI::CUIListView, and Skylicht::UI::CUITextBox.

◆ onPressed()

virtual void Skylicht::UI::CUIBase::onPressed ( )
virtual

Called when the element is considered "pressed" (high-level event). Subclasses may trigger OnPressed callback from here.

Reimplemented in Skylicht::UI::CUIButton, Skylicht::UI::CUICheckbox, and Skylicht::UI::CUISwitch.

◆ remove()

void Skylicht::UI::CUIBase::remove ( )

Remove this UI object from its container and perform cleanup.

After calling remove(), the object should no longer be used by the container.

◆ removeMotion()

bool Skylicht::UI::CUIBase::removeMotion ( EMotionEvent event,
CMotion * motion )

Remove a motion instance from the given event list.

Parameters
eventEvent list to remove from.
motionMotion to remove.
Returns
true if motion was found and removed.

◆ removeMotions()

void Skylicht::UI::CUIBase::removeMotions ( EMotionEvent event)

Remove all motions attached to the specified event.

Parameters
eventEvent whose motions will be cleared.

◆ setContinueGameEvent()

void Skylicht::UI::CUIBase::setContinueGameEvent ( bool b)
inline

Control whether input events continue to the game layer.

Parameters
btrue to let events continue; false to stop propagation.

◆ setEnable()

virtual void Skylicht::UI::CUIBase::setEnable ( bool b)
virtual

Enable or disable this UI object.

Parameters
btrue to enable, false to disable.

◆ setSkipPointerEventWhenDrag()

void Skylicht::UI::CUIBase::setSkipPointerEventWhenDrag ( bool b)
inline

When true pointer events will be skipped while dragging.

Parameters
btrue to skip pointer events during drag.

◆ setSoundId()

void Skylicht::UI::CUIBase::setSoundId ( int slot,
int soundId )
inline

Set the sound id associated with this UI object.

The sound id can be used by the UI system to play feedback (e.g. on press or hover). Interpretation/lookup of the id is the caller/container's responsibility.

Parameters
soundIdApplication-defined sound identifier.

◆ setUserData()

void Skylicht::UI::CUIBase::setUserData ( void * data)
inline

Attach an application-defined pointer to this UI object.

This is a convenience for storing arbitrary user data or context related to the control. Ownership and lifetime are managed by the caller — the UI system only stores/returns the raw pointer.

Parameters
dataPointer to user-defined data (may be nullptr).

◆ setVisible()

virtual void Skylicht::UI::CUIBase::setVisible ( bool b)
virtual

Set visibility of this UI object.

Parameters
btrue to make visible, false to hide.

◆ startMotion()

void Skylicht::UI::CUIBase::startMotion ( EMotionEvent event)

Start motions associated with a specific motion event.

Parameters
eventMotion event to start (EMotionEvent).

◆ stopMotion()

void Skylicht::UI::CUIBase::stopMotion ( EMotionEvent event)

Stop motions associated with a specific motion event.

Parameters
eventMotion event to stop (EMotionEvent).

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