|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
UI 按钮控件,基于鼠标 Raycasting 触发交互 更多...
#include <UIButton.h>
类 | |
| struct | ColorBlock |
| ColorTint 过渡的四种状态颜色(乘到 UIImage 像素上) 更多... | |
Public 类型 | |
| enum class | State { Normal , Highlighted , Pressed , Disabled } |
Public 成员函数 | |
| UIButton ()=default | |
| ~UIButton () override=default | |
| void | onPointerEnter () |
| void | onPointerExit () |
| void | onPointerDown () |
| void | onPointerUp () |
| bool | isInteractable () const |
| void | setInteractable (bool interactable) |
| State | getState () const |
| bool | wasPointerDown () const |
| const ColorBlock & | getColors () const |
| void | setColors (const ColorBlock &colors) |
| void | setOnClick (std::function< void()> callback) |
| void | resetPressed () |
| 复位残留的按下状态(按钮在按下后离开 visible 未收到 onPointerUp 时使用),不触发 onClick | |
| Public 成员函数 继承自 UIRendererComponent | |
| UIRendererComponent () | |
| ~UIRendererComponent () override=default | |
| void | onAttach () override |
| void | onDetach () override |
| void | onDestroy () override |
| virtual bool | containsPoint (const SDL_FRect &screenRect, const Vector2 &point) const |
| 点击命中检测:默认矩形内即命中,子类可覆写为更精确的形状 | |
| int | getZIndex () const |
| void | setZIndex (int zIndex) |
| bool | isVisible () const |
| void | setVisible (bool visible) |
| Public 成员函数 继承自 Component | |
| Component () | |
| virtual | ~Component ()=default |
| virtual void | onCreate () |
| virtual void | onAfterDeserialize () |
| 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。 | |
| Component (const Component &)=delete | |
| Component & | operator= (const Component &)=delete |
| Component (Component &&)=delete | |
| Component & | operator= (Component &&)=delete |
| GameObject * | getOwner () const |
| bool | isRegistered () const |
Protected 成员函数 | |
| void | onRender (const SDL_FRect &) override |
| 子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制) | |
| Protected 成员函数 继承自 UIRendererComponent | |
| void | requestSort () |
| components变更后通知系统重排(实例:zIndex 变化) | |
| Protected 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
额外继承的成员函数 | |
| 静态 Protected 成员函数 继承自 UIRendererComponent | |
| static SDL_Color | toSDLColor (const Color &color) |
| Color → SDL_Color 边界转换(供 UIText / UITextInput 系列传给 SDL_ttf 用) | |
| Protected 属性 继承自 UIRendererComponent | |
| int | m_zIndex = 0 |
| 渲染层级(值越大越靠上) | |
| bool | m_isVisible = true |
| 是否参与渲染与命中 | |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
UI 按钮控件,基于鼠标 Raycasting 触发交互
由 UIRenderSystem 的命中检测驱动状态机:Normal → Highlighted (悬停) → Pressed (按下)。 释放且仍在按钮内时触发 onClick。不支持交互时进入 Disabled 状态。 采用 ColorTint 过渡:状态变化时改写同 GameObject 上 UIImage 的 color(若存在)。 UI 渲染交给同 GameObject 的 UIImage / 自定义控件,本控件不直接绘制。
|
strong |
|
default |
|
overridedefault |
|
inline |
|
inline |
|
inline |
| void onPointerDown | ( | ) |
| void onPointerEnter | ( | ) |
| void onPointerExit | ( | ) |
| void onPointerUp | ( | ) |
|
overrideprotectedvirtual |
子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)
实现了 UIRendererComponent.
| void resetPressed | ( | ) |
复位残留的按下状态(按钮在按下后离开 visible 未收到 onPointerUp 时使用),不触发 onClick
|
inline |
| void setInteractable | ( | bool | interactable | ) |
|
inline |
|
inline |