mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 04:21:50 +00:00
refactor input.h and related
This commit is contained in:
parent
9c31c6c8b7
commit
8bb1045e34
12 changed files with 236 additions and 254 deletions
|
|
@ -3,123 +3,143 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
struct keycode {
|
||||
static int ENTER;
|
||||
static int TAB;
|
||||
static int SPACE;
|
||||
static int BACKSPACE;
|
||||
static int LEFT_CONTROL;
|
||||
static int LEFT_SHIFT;
|
||||
static int LEFT_ALT;
|
||||
static int RIGHT_CONTROL;
|
||||
static int RIGHT_SHIFT;
|
||||
static int RIGHT_ALT;
|
||||
static int ESCAPE;
|
||||
static int CAPS_LOCK;
|
||||
static int LEFT;
|
||||
static int RIGHT;
|
||||
static int DOWN;
|
||||
static int UP;
|
||||
static int F1;
|
||||
static int F2;
|
||||
static int F3;
|
||||
static int F4;
|
||||
static int F5;
|
||||
static int F6;
|
||||
static int F7;
|
||||
static int F8;
|
||||
static int F9;
|
||||
static int F10;
|
||||
static int F11;
|
||||
static int F12;
|
||||
static int A;
|
||||
static int B;
|
||||
static int C;
|
||||
static int D;
|
||||
static int E;
|
||||
static int F;
|
||||
static int G;
|
||||
static int H;
|
||||
static int I;
|
||||
static int J;
|
||||
static int K;
|
||||
static int L;
|
||||
static int M;
|
||||
static int N;
|
||||
static int O;
|
||||
static int P;
|
||||
static int Q;
|
||||
static int R;
|
||||
static int S;
|
||||
static int T;
|
||||
static int U;
|
||||
static int V;
|
||||
static int W;
|
||||
static int X;
|
||||
static int Y;
|
||||
static int Z;
|
||||
static int NUM_0;
|
||||
static int NUM_1;
|
||||
static int NUM_2;
|
||||
static int NUM_3;
|
||||
static int NUM_4;
|
||||
static int NUM_5;
|
||||
static int NUM_6;
|
||||
static int NUM_7;
|
||||
static int NUM_8;
|
||||
static int NUM_9;
|
||||
static int MENU;
|
||||
static int PAUSE;
|
||||
static int INSERT;
|
||||
static int LEFT_SUPER;
|
||||
static int RIGHT_SUPER;
|
||||
static int DELETE;
|
||||
static int PAGE_UP;
|
||||
static int PAGE_DOWN;
|
||||
static int HOME;
|
||||
static int END;
|
||||
static int PRINT_SCREEN;
|
||||
static int NUM_LOCK;
|
||||
static int LEFT_BRACKET;
|
||||
static int RIGHT_BRACKET;
|
||||
|
||||
static const std::string name(int code);
|
||||
/**
|
||||
* @brief Represents glfw3 keycode values.
|
||||
*/
|
||||
enum class keycode : int {
|
||||
ENTER = 257,
|
||||
TAB = 258,
|
||||
SPACE = 32,
|
||||
BACKSPACE = 259,
|
||||
LEFT_SHIFT = 340,
|
||||
LEFT_CONTROL = 341,
|
||||
LEFT_ALT = 342,
|
||||
RIGHT_SHIFT = 344,
|
||||
RIGHT_CONTROL = 345,
|
||||
RIGHT_ALT = 346,
|
||||
ESCAPE = 256,
|
||||
CAPS_LOCK = 280,
|
||||
LEFT = 263,
|
||||
RIGHT = 262,
|
||||
DOWN = 264,
|
||||
UP = 265,
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
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,
|
||||
NUM_0 = 48,
|
||||
NUM_1 = 49,
|
||||
NUM_2 = 50,
|
||||
NUM_3 = 51,
|
||||
NUM_4 = 52,
|
||||
NUM_5 = 53,
|
||||
NUM_6 = 54,
|
||||
NUM_7 = 55,
|
||||
NUM_8 = 56,
|
||||
NUM_9 = 57,
|
||||
MENU = 348,
|
||||
PAUSE = 284,
|
||||
INSERT = 260,
|
||||
LEFT_SUPER = 343,
|
||||
RIGHT_SUPER = 347,
|
||||
DELETE = 261,
|
||||
PAGE_UP = 266,
|
||||
PAGE_DOWN = 267,
|
||||
HOME = 268,
|
||||
END = 269,
|
||||
PRINT_SCREEN = 283,
|
||||
NUM_LOCK = 282,
|
||||
LEFT_BRACKET = 91,
|
||||
RIGHT_BRACKET = 93,
|
||||
};
|
||||
|
||||
struct mousecode {
|
||||
static int BUTTON_1;
|
||||
static int BUTTON_2;
|
||||
static int BUTTON_3;
|
||||
|
||||
static const std::string name(int code);
|
||||
/**
|
||||
* @brief Represents glfw3 mouse button IDs.
|
||||
* @details There is a subset of glfw3 mouse button IDs.
|
||||
*/
|
||||
enum class mousecode : int {
|
||||
BUTTON_1 = 0, // Left mouse button
|
||||
BUTTON_2 = 1, // Right mouse button
|
||||
BUTTON_3 = 2, // Middle mouse button
|
||||
};
|
||||
|
||||
|
||||
namespace input_util {
|
||||
// @return Key label by keycode
|
||||
std::string to_string(keycode code);
|
||||
// @return Mouse button label by keycode
|
||||
std::string to_string(mousecode code);
|
||||
}
|
||||
|
||||
enum class inputtype {
|
||||
keyboard,
|
||||
mouse,
|
||||
keyboard,
|
||||
mouse,
|
||||
};
|
||||
|
||||
struct Binding {
|
||||
inputtype type;
|
||||
int code;
|
||||
bool state = false;
|
||||
bool justChange = false;
|
||||
inputtype type;
|
||||
int code;
|
||||
bool state = false;
|
||||
bool justChange = false;
|
||||
|
||||
bool active() const {
|
||||
return state;
|
||||
}
|
||||
bool active() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
bool jactive() const {
|
||||
return state && justChange;
|
||||
}
|
||||
bool jactive() const {
|
||||
return state && justChange;
|
||||
}
|
||||
|
||||
void reset(inputtype, int);
|
||||
void reset(keycode);
|
||||
void reset(mousecode);
|
||||
|
||||
const std::string text() const {
|
||||
switch (type) {
|
||||
case inputtype::keyboard: return keycode::name(code);
|
||||
case inputtype::mouse: return mousecode::name(code);
|
||||
}
|
||||
return "<unknown input type>";
|
||||
}
|
||||
inline const std::string text() const {
|
||||
switch (type) {
|
||||
case inputtype::keyboard: {
|
||||
return input_util::to_string(static_cast<keycode>(code));
|
||||
}
|
||||
case inputtype::mouse: {
|
||||
return input_util::to_string(static_cast<mousecode>(code));
|
||||
}
|
||||
}
|
||||
return "<unknown input type>";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue