ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
UIText.h
浏览该文件的文档.
1
#pragma once
2
#include "
../Core/Core.h
"
3
#include "
UIRendererComponent.h
"
4
#include <string>
5
#include <SDL3_ttf/SDL_ttf.h>
6
7
namespace
Shit
{
16
class
SHIT_API
SHIT_REFLECT
(BlackList)
UIText
:
public
UIRendererComponent
{
17
SHIT_REFLECT_BODY
(
UIText
)
18
public
:
19
enum class
TextAnchor
{
Left
, Center,
Right
};
20
21
UIText
() =
default
;
22
UIText
(
const
std::string& text,
const
std::string& fontPath,
float
fontSize);
23
~UIText
()
override
;
24
25
void
onRender
(
const
SDL_FRect& screenRect)
override
;
26
void
onDestroy
()
override
;
27
28
// --- getter & setter(变更后置 dirty) ---
29
const
std::string&
getText
()
const
{
return
m_text; }
30
void
setText
(
const
std::string& text) { m_text = text; m_isDirty =
true
; }
31
32
const
std::string&
getFontPath
()
const
{
return
m_fontPath; }
33
void
setFontPath
(
const
std::string& fontPath) { m_fontPath = fontPath; m_isDirty =
true
; }
34
35
float
getFontSize
()
const
{
return
m_fontSize; }
36
void
setFontSize
(
float
fontSize) { m_fontSize = fontSize; m_isDirty =
true
; }
37
38
const
Color
&
getColor
()
const
{
return
m_color; }
39
void
setColor
(
const
Color
& color) { m_color = color; m_isDirty =
true
; }
40
41
TextAnchor
getAnchor
()
const
{
return
m_anchor; }
42
void
setAnchor
(
TextAnchor
anchor) { m_anchor = anchor; }
43
44
private
:
45
void
rebuildTexture();
46
TTF_Font* getLoadedFont();
47
48
SHIT_META
(({.displayName =
"Text"
, .tooltip =
"文字内容"
}))
49
std::string m_text;
50
SHIT_META
(({.displayName =
"Font Path"
, .tooltip =
"字体文件路径"
}))
51
std::string m_fontPath;
52
SHIT_META
(({.displayName =
"Font Size"
, .tooltip =
"字号"
, .range = {1, 300}}))
53
float
m_fontSize = 24.0f;
54
SHIT_META
(({.displayName =
"Color"
, .tooltip =
"文字颜色"
}))
55
Color m_color;
56
SHIT_META
(({.displayName =
"Anchor"
, .tooltip =
"对齐方式(左/中/右)"
}))
57
TextAnchor m_anchor = TextAnchor::Center;
58
SHIT_META
(Disable)
59
SDL_Texture* m_cachedTexture =
nullptr
;
60
SHIT_META
(Disable)
61
bool
m_isDirty =
true
;
62
};
63
}
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:62
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:59
SHIT_META
#define SHIT_META(...)
定义
Macros.h:68
UIRendererComponent.h
Shit::UIRendererComponent::UIRendererComponent
UIRendererComponent()
Shit::UIText::getFontSize
float getFontSize() const
定义
UIText.h:35
Shit::UIText::getColor
const Color & getColor() const
定义
UIText.h:38
Shit::UIText::UIText
UIText(const std::string &text, const std::string &fontPath, float fontSize)
Shit::UIText::~UIText
~UIText() override
Shit::UIText::UIText
UIText()=default
Shit::UIText::getText
const std::string & getText() const
定义
UIText.h:29
Shit::UIText::setAnchor
void setAnchor(TextAnchor anchor)
定义
UIText.h:42
Shit::UIText::setColor
void setColor(const Color &color)
定义
UIText.h:39
Shit::UIText::TextAnchor
TextAnchor
定义
UIText.h:19
Shit::UIText::getFontPath
const std::string & getFontPath() const
定义
UIText.h:32
Shit::UIText::onRender
void onRender(const SDL_FRect &screenRect) override
子类实现:在给定屏幕矩形内绘制自身(通过 Renderer 静态 API 绘制)
Shit::UIText::setFontPath
void setFontPath(const std::string &fontPath)
定义
UIText.h:33
Shit::UIText::getAnchor
TextAnchor getAnchor() const
定义
UIText.h:41
Shit::UIText::setFontSize
void setFontSize(float fontSize)
定义
UIText.h:36
Shit::UIText::setText
void setText(const std::string &text)
定义
UIText.h:30
Shit::UIText::onDestroy
void onDestroy() override
Shit
定义
AudioPlayer.h:10
Shit::KeyCode::Right
@ Right
定义
KeyCode.h:97
Shit::KeyCode::Left
@ Left
定义
KeyCode.h:98
Shit::Color
RGBA 颜色(每通道 8 位)
定义
Core.h:26
include
ShitEngine
UI
UIText.h
制作者
1.17.0