|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
UI 文字控件,使用 SDL_ttf 渲染文字到纹理 更多...
#include <UIText.h>
Public 类型 | |
| enum class | TextAnchor { Left , Center , Right } |
Public 成员函数 | |
| UIText ()=default | |
| UIText (const std::string &text, const std::string &fontPath, float fontSize) | |
| ~UIText () override | |
| void | onRender (const SDL_FRect &screenRect) override |
| 子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制) | |
| void | onDestroy () override |
| const std::string & | getText () const |
| void | setText (const std::string &text) |
| const std::string & | getFontPath () const |
| void | setFontPath (const std::string &fontPath) |
| float | getFontSize () const |
| void | setFontSize (float fontSize) |
| const Color & | getColor () const |
| void | setColor (const Color &color) |
| TextAnchor | getAnchor () const |
| void | setAnchor (TextAnchor anchor) |
| Public 成员函数 继承自 UIRendererComponent | |
| UIRendererComponent () | |
| ~UIRendererComponent () override=default | |
| void | onAttach () override |
| void | onDetach () 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 成员函数 继承自 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 文字控件,使用 SDL_ttf 渲染文字到纹理
纹理缓存策略:setText / setFontSize / setColor 置 dirty, 下次 onRender 用 TTF_RenderText_Blended 重新生成 SDL_Texture。 onDestroy 释放缓存的纹理。字体按 path+size 加载并缓存于进程级映射。 对齐方式(左 / 中 / 右)相对 UITransform 的屏幕矩形。
|
strong |
|
default |
| UIText | ( | const std::string & | text, |
| const std::string & | fontPath, | ||
| float | fontSize ) |
|
override |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
overridevirtual |
重载 UIRendererComponent .
|
overridevirtual |
子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)
实现了 UIRendererComponent.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |