ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
UIRendererComponent.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
4#include "../Math.h"
5#include <SDL3/SDL_pixels.h>
6#include <SDL3/SDL_rect.h>
7
8namespace Shit {
9 class UIRenderSystem;
10
20 public:
22 ~UIRendererComponent() override = default;
23
24 void onAttach() override;
25 void onDetach() override;
26 void onDestroy() override;
27
29 virtual void onRender(const SDL_FRect& screenRect) = 0;
30
32 virtual bool containsPoint(const SDL_FRect& screenRect, const Vector2& point) const;
33
34 // --- getter & setter ---
35 int getZIndex() const { return m_zIndex; }
36 void setZIndex(int zIndex) { m_zIndex = zIndex; requestSort(); }
37
38 bool isVisible() const { return m_isVisible; }
39 void setVisible(bool visible) { m_isVisible = visible; }
40
41 protected:
44
46 static SDL_Color toSDLColor(const Color& color) {
47 return SDL_Color{ color.red, color.green, color.blue, color.alpha };
48 }
49
50 SHIT_META(({.displayName = "Z-Index", .tooltip = "渲染层级(值越大越靠上)"}))
51 int m_zIndex = 0;
52 SHIT_META(({.displayName = "Visible", .tooltip = "是否参与渲染与命中"}))
53 bool m_isVisible = true;
54 };
55}
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:62
#define SHIT_REFLECT(Mode)
定义 Macros.h:59
#define SHIT_META(...)
定义 Macros.h:68
UI 渲染系统
定义 UIRenderSystem.h:21
~UIRendererComponent() override=default
void setVisible(bool visible)
定义 UIRendererComponent.h:39
int m_zIndex
渲染层级(值越大越靠上)
定义 UIRendererComponent.h:51
virtual bool containsPoint(const SDL_FRect &screenRect, const Vector2 &point) const
点击命中检测:默认矩形内即命中,子类可覆写为更精确的形状
virtual void onRender(const SDL_FRect &screenRect)=0
子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)
bool isVisible() const
定义 UIRendererComponent.h:38
void setZIndex(int zIndex)
定义 UIRendererComponent.h:36
void requestSort()
components变更后通知系统重排(实例:zIndex 变化)
void onAttach() override
static SDL_Color toSDLColor(const Color &color)
Color → SDL_Color 边界转换(供 UIText / UITextInput 系列传给 SDL_ttf 用)
定义 UIRendererComponent.h:46
bool m_isVisible
是否参与渲染与命中
定义 UIRendererComponent.h:53
void onDetach() override
int getZIndex() const
定义 UIRendererComponent.h:35
void onDestroy() override
定义 AudioPlayer.h:10
glm::vec2 Vector2
定义 Math.h:5
RGBA 颜色(每通道 8 位)
定义 Core.h:26
std::uint8_t green
定义 Core.h:28
std::uint8_t red
定义 Core.h:27
std::uint8_t blue
定义 Core.h:29
std::uint8_t alpha
定义 Core.h:30