ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
TextInputGate.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
3#include "../Input/KeyCode.h"
4
5#include <unordered_set>
6
7union SDL_Event;
8struct SDL_Rect;
9
10namespace Shit {
11 class UITextInput;
12
24 class SHIT_API TextInputGate final {
25 public:
26 TextInputGate(const TextInputGate&) = delete;
28
30
33 static bool HandleEvent(const SDL_Event& event) { return GetInstance().handleEvent(event); }
34
36 static bool HasFocus();
37
39 void requestFocus(UITextInput* control);
40
42 void releaseFocus(UITextInput* control);
43
45 void clearFocus();
46
48 void updateCursorRect(const SDL_Rect& rect, int cursor);
49
50 private:
51 friend class EngineContext;
52 TextInputGate() = default;
53 ~TextInputGate() = default;
54
55 bool handleEvent(const SDL_Event& event);
56
57 UITextInput* m_focused = nullptr;
58
61 std::unordered_set<KeyCode> m_focusConsumedKeys;
62 };
63}
#define SHIT_API
定义 Core.h:14
void updateCursorRect(const SDL_Rect &rect, int cursor)
通知 IME 光标位置变化(用窗口坐标的 SDL_Rect)
void requestFocus(UITextInput *control)
请求聚焦某控件:失焦当前控件,启动新控件的文本输入模式
TextInputGate(const TextInputGate &)=delete
static bool HandleEvent(const SDL_Event &event)
获取原生事件转发入口(由 Game 在 PollEvent 后调用)
定义 TextInputGate.h:33
void clearFocus()
强制清空焦点(例如场景销毁时)
TextInputGate & operator=(const TextInputGate &)=delete
static TextInputGate & GetInstance()
friend class EngineContext
定义 TextInputGate.h:51
void releaseFocus(UITextInput *control)
失焦指定控件(仅当它当前正在聚焦时才生效)
static bool HasFocus()
当前是否有聚焦控件
文本输入控件抽象基类
定义 UITextInput.h:25
定义 AudioPlayer.h:10