JacksEscape/input.h

76 lines
1.5 KiB
C
Raw Normal View History

2024-03-01 14:37:59 +08:00
#pragma once
2024-04-23 14:48:01 +08:00
#include "types.h"
2024-03-01 14:37:59 +08:00
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// Types of input the player might want
typedef enum {
input_Key_Left,
input_Key_Right,
input_Key_Up,
input_Key_Down,
input_Key_Jump,
input_Key_Attack,
input_Key_Spell,
input_Key_Use,
2024-03-05 15:20:32 +08:00
input_Key_Dash,
2024-03-04 15:05:21 +08:00
input_Key_Escape,
2024-04-23 14:48:01 +08:00
input_Key_LeftMouse,
input_Key_RightMouse,
2024-03-01 14:37:59 +08:00
input_Key_Count
} input_Key;
2024-03-01 16:15:21 +08:00
// Names for input_Key
2024-03-04 15:05:21 +08:00
extern const char *input_KeyNames[input_Key_Count];
2024-03-01 16:15:21 +08:00
2024-03-01 14:37:59 +08:00
// States a key might in
typedef enum {
Released,
JustReleased,
Pressed,
JustPressed
2024-03-01 14:37:59 +08:00
} input_KeyState;
2024-03-01 16:15:21 +08:00
static inline bool input_IsPressed(input_KeyState state) { return state == Pressed || state == JustPressed; }
static inline bool input_IsReleased(input_KeyState state) { return state == Released || state == JustReleased; }
2024-03-01 17:09:24 +08:00
typedef struct _App App;
2024-03-01 14:37:59 +08:00
typedef struct {
2024-03-01 17:09:24 +08:00
App *super;
2024-03-01 16:15:21 +08:00
input_KeyState keys[input_Key_Count]; // States of keys
unsigned int systemKeymap[input_Key_Count]; // Which system key (VK code) this function uses
// https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
2024-03-01 14:37:59 +08:00
} System_Input;
2024-03-01 16:15:21 +08:00
// Creates a new input system.
// Uses a default keymap
2024-03-01 17:09:24 +08:00
System_Input *input_NewSystem(App *super);
2024-03-01 16:15:21 +08:00
void input_DeleteSystem(System_Input *sys);
// Sets the keymaps to default.
void input_SetDefaultKeymap(System_Input *sys);
// Update key states
void input_Advance(System_Input *sys);
2024-04-23 14:48:01 +08:00
// Get where the mouse is right now
Vec2 input_MousePosition(System_Input *sys);
2024-03-01 14:37:59 +08:00
#ifdef __cplusplus
}
#endif