Unify input behind Engine::Input facade; fix Ctrl+P and Pause button
New Engine/Core/Input.h/.cpp: static input facade with a Key/MouseButton enum (values map to GLFW key codes internally) so scripts and game logic no longer touch GLFW directly - window backend becomes swappable and the facade is the surface to expose when embedding scripting later. Wired up in Application's constructor; Camera (editor camera WASD/RMB/MMB), the WASDMove script and SandboxApp key handling now query Input only. Ctrl+P hotkey fix: the !m_Playing guard made the hotkey dead exactly when it was needed - after pressing Play. Now toggles both ways. Toolbar Pause button now reads "Resume" while paused (tooltip follows).
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Input.h:统一输入门面(脚本/游戏逻辑唯一入口)。
|
||||
//
|
||||
// 目的:
|
||||
// 1. 上层代码(脚本、SandboxApp、编辑器相机)不再直接依赖 GLFW——
|
||||
// 只依赖本枚举与门面,Window 后端将来可换(SDL/平台原生)
|
||||
// 2. 嵌入脚本时暴露的也是这一套(Lua/Python 绑定包一层即可)
|
||||
//
|
||||
// 键码值 = GLFW 物理键码(glf3.h 标准值),强转 int 可直接传给
|
||||
// Window::IsKeyPressed;但调用方不得依赖这一点。
|
||||
//
|
||||
// 语义:轮询接口沿用 Window 的门控规则——UI 捕获键盘(编辑器文本框
|
||||
// 输入中)时 IsKeyDown 返回 false,游戏侧静默;鼠标捕获同理。
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Engine {
|
||||
|
||||
class Window;
|
||||
|
||||
namespace Input {
|
||||
|
||||
enum class Key : int {
|
||||
// ---- 可打印区(值 = ASCII)----
|
||||
Space = 32,
|
||||
Apostrophe = 39,
|
||||
Comma = 44,
|
||||
Minus = 45,
|
||||
Period = 46,
|
||||
Slash = 47,
|
||||
Num0 = 48, Num1 = 49, Num2 = 50, Num3 = 51, Num4 = 52,
|
||||
Num5 = 53, Num6 = 54, Num7 = 55, Num8 = 56, Num9 = 57,
|
||||
Semicolon = 59,
|
||||
Equal = 61,
|
||||
A = 65, B = 66, C = 67, D = 68, E = 69, F = 70, G = 71,
|
||||
H = 72, I = 73, J = 74, K = 75, L = 76, M = 77, N = 78,
|
||||
O = 79, P = 80, Q = 81, R = 82, S = 83, T = 84, U = 85,
|
||||
V = 86, W = 87, X = 88, Y = 89, Z = 90,
|
||||
BracketLeft = 91,
|
||||
Backslash = 92,
|
||||
BracketRight = 93,
|
||||
GraveAccent = 96,
|
||||
// ---- 控制键(值 = GLFW 键码)----
|
||||
Escape = 256,
|
||||
Enter = 257,
|
||||
Tab = 258,
|
||||
Backspace = 259,
|
||||
Insert = 260,
|
||||
Delete = 261,
|
||||
Right = 262,
|
||||
Left = 263,
|
||||
Down = 264,
|
||||
Up = 265,
|
||||
PageUp = 266,
|
||||
PageDown = 267,
|
||||
Home = 268,
|
||||
End = 269,
|
||||
F1 = 290, F2 = 291, F3 = 292, F4 = 293, F5 = 294, F6 = 295,
|
||||
F7 = 296, F8 = 297, F9 = 298, F10 = 299, F11 = 300,
|
||||
F12 = 301,
|
||||
// ---- 修饰键 ----
|
||||
LeftShift = 340,
|
||||
LeftControl = 341,
|
||||
LeftAlt = 342,
|
||||
LeftSuper = 343,
|
||||
RightShift = 344,
|
||||
RightControl = 345,
|
||||
RightAlt = 346,
|
||||
RightSuper = 347,
|
||||
};
|
||||
|
||||
enum class MouseButton : int {
|
||||
Left = 0, // GLFW_MOUSE_BUTTON_1
|
||||
Right = 1,
|
||||
Middle = 2,
|
||||
};
|
||||
|
||||
// 装配:Application 构造时自动调用(后端 Window 就绪后)
|
||||
void Init(const Window& window);
|
||||
|
||||
// 轮询查询(UI 捕获对应输入时返回 false——游戏侧静默)
|
||||
bool IsKeyDown(Key key);
|
||||
bool IsMouseButtonDown(MouseButton button);
|
||||
}
|
||||
|
||||
} // namespace Engine
|
||||
Reference in New Issue
Block a user