|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
UI 专用变换组件(参考 Unity RectTransform,但不引入 Canvas Scaler) 更多...
#include <UITransform.h>
Public 成员函数 | |
| UITransform ()=default | |
| ~UITransform () override=default | |
| UITransform (float anchoredPositionX, float anchoredPositionY, float width, float height) | |
| 便捷构造:居中锚点 + 给定偏移与尺寸 | |
| const Vector2 & | getAnchorMin () const |
| void | setAnchorMin (const Vector2 &anchorMin) |
| const Vector2 & | getAnchorMax () const |
| void | setAnchorMax (const Vector2 &anchorMax) |
| const Vector2 & | getPivot () const |
| void | setPivot (const Vector2 &pivot) |
| const Vector2 & | getAnchoredPosition () const |
| void | setAnchoredPosition (const Vector2 &position) |
| float | getWidth () const |
| void | setWidth (float width) |
| float | getHeight () const |
| void | setHeight (float height) |
| int | getZIndex () const |
| void | setZIndex (int zIndex) |
| SDL_FRect | getScreenRect (const SDL_FRect *parentRect) const |
| 计算最终屏幕空间矩形(传入已知父级矩形;nullptr 表示用 Canvas 屏幕矩形) | |
| SDL_FRect | resolveParentRect () const |
| 自动查找父级矩形:沿 GameObject 父链找 UITransform,否则用 Canvas;二者都无返回全屏 | |
| Public 成员函数 继承自 Component | |
| Component () | |
| virtual | ~Component ()=default |
| virtual void | onCreate () |
| virtual void | onAttach () |
| virtual void | onDetach () |
| virtual void | onDestroy () |
| 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 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
UI 专用变换组件(参考 Unity RectTransform,但不引入 Canvas Scaler)
决定 UI 元素在屏幕上的位置和大小。采用锚点(anchor)+ 轴心(pivot)定位:
注意坐标系:SDL Y 轴向下,(0,0) 为父级左上角,(1,1) 为右下角。 父级矩形查找顺序:沿 GameObject 父链查最近的 UITransform;若无则用 Canvas 屏幕矩形。
|
default |
|
overridedefault |
| UITransform | ( | float | anchoredPositionX, |
| float | anchoredPositionY, | ||
| float | width, | ||
| float | height ) |
便捷构造:居中锚点 + 给定偏移与尺寸
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| SDL_FRect getScreenRect | ( | const SDL_FRect * | parentRect | ) | const |
计算最终屏幕空间矩形(传入已知父级矩形;nullptr 表示用 Canvas 屏幕矩形)
|
inline |
|
inline |
| SDL_FRect resolveParentRect | ( | ) | const |
自动查找父级矩形:沿 GameObject 父链找 UITransform,否则用 Canvas;二者都无返回全屏
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |