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

Checkbox control built on top of CUIBase. More...

#include <UserInterface/CUICheckbox.h>

Inheritance diagram for Skylicht::UI::CUICheckbox:
Skylicht::UI::CUIBase

Public Member Functions

 CUICheckbox (CUIContainer *container, CGUIElement *element)
 Create a checkbox bound to a container and element.
 CUICheckbox (CUIContainer *container, CGUIElement *element, CGUIElement *bg, CGUIElement *checked)
 Create a checkbox with explicit background and checked elements.
virtual void onPressed ()
 Called when the control is pressed.
void setToggle (bool b, bool invokeEvent=true, bool doAnimation=false)
 Set the checked state programmatically.
bool isToggle ()
 Query current checked state.
CGUIElementgetBackground ()
 Get the background element.
CGUIElementgetChecked ()
 Get the checked element.
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 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(CUICheckbox *, bool)> OnChanged
 Callback invoked when the checkbox state 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 stopTween ()
 Stop and clear any active tween animation.
void playTween ()
 Start the tween animation for the checked/unchecked transition.

Protected Attributes

CGUIElementm_background
CGUIElementm_checked
bool m_toggleStatus
CTweenm_tween
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

Checkbox control built on top of CUIBase.

CUICheckbox represents a two-state checkbox control with an optional simple animation when the checked state changes. The control contains a background element and a checked mark element (m_checked). Use OnChanged to react to user-initiated or programmatic changes.

Behaviour:

  • onPressed() toggles the checked state (unless overridden).
  • setToggle() changes the state programmatically; invokeEvent controls whether the OnChanged callback is invoked; doAnimation controls whether the checkbox plays its internal tween animation.

Typical usage:

  • Construct with a parent CUIContainer and an element node.
  • Optionally provide explicit background and checked elements via the alternate constructor.
  • Register a listener on OnChanged to be notified when the state changes.

Constructor & Destructor Documentation

◆ CUICheckbox() [1/2]

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

Create a checkbox bound to a container and element.

Parameters
containerParent CUIContainer that owns this control.
elementRoot CGUIElement node representing this control.

The control will use internal children of element (if present) or explicit elements can be supplied with the alternate constructor.

◆ CUICheckbox() [2/2]

Skylicht::UI::CUICheckbox::CUICheckbox ( CUIContainer * container,
CGUIElement * element,
CGUIElement * bg,
CGUIElement * checked )

Create a checkbox with explicit background and checked elements.

Parameters
containerParent CUIContainer.
elementRoot element for the control.
bgBackground element used for visuals.
checkedElement shown when checkbox is in checked state.

Member Function Documentation

◆ getBackground()

CGUIElement * Skylicht::UI::CUICheckbox::getBackground ( )
inline

Get the background element.

Returns
Pointer to CGUIElement used as background, or nullptr.

◆ getChecked()

CGUIElement * Skylicht::UI::CUICheckbox::getChecked ( )
inline

Get the checked element.

Returns
Pointer to CGUIElement representing the checked mark, or nullptr.

◆ isToggle()

bool Skylicht::UI::CUICheckbox::isToggle ( )
inline

Query current checked state.

Returns
true if checkbox is checked.

◆ onPressed()

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

Called when the control is pressed.

Default implementation toggles the checkbox state and will invoke OnChanged. Subclasses may override to customize behaviour; if overriding and wanting the default toggle semantics, they should call the base implementation.

Reimplemented from Skylicht::UI::CUIBase.

◆ playTween()

void Skylicht::UI::CUICheckbox::playTween ( )
protected

Start the tween animation for the checked/unchecked transition.

If no m_tween exists, no animation is played. This method is internal.

◆ setToggle()

void Skylicht::UI::CUICheckbox::setToggle ( bool b,
bool invokeEvent = true,
bool doAnimation = false )

Set the checked state programmatically.

Parameters
bDesired checked state (true = checked).
invokeEventIf true, the OnChanged callback is invoked.
doAnimationIf true, play checkbox animation (if present) when changing.

◆ stopTween()

void Skylicht::UI::CUICheckbox::stopTween ( )
protected

Stop and clear any active tween animation.

Called internally to abort animations when the control is destroyed or when a new animation should replace the current one.

Member Data Documentation

◆ OnChanged

std::function<void(CUICheckbox*, bool)> Skylicht::UI::CUICheckbox::OnChanged

Callback invoked when the checkbox state changes.

Signature: void(CUICheckbox* sender, bool checked)

  • sender: pointer to this checkbox.
  • checked: new checked state (true = checked).

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