60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
		
		
			
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
|  | #pragma once
 | |||
|  | 
 | |||
|  | #include <string>
 | |||
|  | #include <SDL2/SDL.h>
 | |||
|  | #include <SDL2/SDL_ttf.h>
 | |||
|  | #include "EngineFrame/Component/Component.h"
 | |||
|  | class Game; | |||
|  | 
 | |||
|  | class Text : public Component | |||
|  | { | |||
|  | private: | |||
|  |     /* data */ | |||
|  |     SDL_Texture *m_texture = nullptr; | |||
|  | 
 | |||
|  | public: | |||
|  |     Text(/* args */); | |||
|  |     Text(std::string Str, TTF_Font *font, SDL_Color color); | |||
|  |     Text(std::string Str, TTF_Font *font, SDL_Color textColor, SDL_Color strokeColor, int strokeSize); | |||
|  |     ~Text(); | |||
|  | 
 | |||
|  |     // 显式引入基类的Init方法,避免隐藏
 | |||
|  |     using Component::Init; | |||
|  |     void Init(std::string Str, TTF_Font *font, SDL_Color color); | |||
|  |     void Init(std::string Str, TTF_Font *font, SDL_Color textColor, SDL_Color strokeColor, int strokeSize); | |||
|  |     void HandleEvents(SDL_Event *e) override; | |||
|  |     void Update(float deltaTime) override; | |||
|  |     void Render(float deltaTime) override; | |||
|  |     void Clear() override; | |||
|  | 
 | |||
|  |     SDL_Texture *GetTexture(); | |||
|  | 
 | |||
|  | public: | |||
|  |     // 组件标签
 | |||
|  |     Tag m_tag = Tag::RENDER | Tag::UPDATE; // 标记该组件需要渲染和更新
 | |||
|  | 
 | |||
|  |     std::string m_text; | |||
|  |     TTF_Font *m_font; | |||
|  |     SDL_Color m_text_color; | |||
|  |     SDL_Color m_stroke_color; | |||
|  |     int m_stroke_size = 0; | |||
|  | 
 | |||
|  |     SDL_Point Pos = {0, 0};                // 位置坐标
 | |||
|  |     SDL_Point TextureSize = {0, 0};        // 纹理大小
 | |||
|  |     SDL_Point Size = {0, 0};               // 大小
 | |||
|  |     SDL_Point Anchor = {0, 0};             // 中心点
 | |||
|  |     float Angle = 0.0f;                    // 旋转角度
 | |||
|  |     SDL_RendererFlip flip = SDL_FLIP_NONE; // 翻转
 | |||
|  | 
 | |||
|  | public: | |||
|  |     // 设置坐标
 | |||
|  |     void SetPos(SDL_Point pos); | |||
|  |     // 设置文本
 | |||
|  |     void SetText(std::string Str); | |||
|  | 
 | |||
|  |     // 获取坐标
 | |||
|  |     SDL_Point GetPos(); | |||
|  |     // 获取文本
 | |||
|  |     std::string GetText(); | |||
|  | }; |