Add mouse tracking in Input

This commit is contained in:
Edgaru089 2024-04-23 14:48:01 +08:00
parent 9c2c8ef1c0
commit b2978f4989
2 changed files with 30 additions and 11 deletions

34
input.c
View File

@ -17,19 +17,23 @@ const char *input_KeyNames[input_Key_Count] = {
"Spell", "Spell",
"Use", "Use",
"Dash", "Dash",
"Escape"}; "Escape",
"Left Mouse Button",
"Right Mouse Button"};
void input_SetDefaultKeymap(System_Input *sys) { void input_SetDefaultKeymap(System_Input *sys) {
sys->systemKeymap[input_Key_Up] = 'W'; sys->systemKeymap[input_Key_Up] = 'W';
sys->systemKeymap[input_Key_Left] = 'A'; sys->systemKeymap[input_Key_Left] = 'A';
sys->systemKeymap[input_Key_Down] = 'S'; sys->systemKeymap[input_Key_Down] = 'S';
sys->systemKeymap[input_Key_Right] = 'D'; sys->systemKeymap[input_Key_Right] = 'D';
sys->systemKeymap[input_Key_Jump] = VK_SPACE; sys->systemKeymap[input_Key_Jump] = VK_SPACE;
sys->systemKeymap[input_Key_Attack] = 'J'; sys->systemKeymap[input_Key_Attack] = 'J';
sys->systemKeymap[input_Key_Spell] = 'K'; sys->systemKeymap[input_Key_Spell] = 'K';
sys->systemKeymap[input_Key_Use] = 'L'; sys->systemKeymap[input_Key_Use] = 'L';
sys->systemKeymap[input_Key_Dash] = VK_OEM_1; // The ;: key on the US keyboard sys->systemKeymap[input_Key_Dash] = VK_OEM_1; // The ;: key on the US keyboard
sys->systemKeymap[input_Key_Escape] = VK_ESCAPE; sys->systemKeymap[input_Key_Escape] = VK_ESCAPE;
sys->systemKeymap[input_Key_LeftMouse] = VK_LBUTTON;
sys->systemKeymap[input_Key_RightMouse] = VK_RBUTTON;
} }
System_Input *input_NewSystem(App *super) { System_Input *input_NewSystem(App *super) {
@ -78,3 +82,11 @@ void input_Advance(System_Input *sys) {
sys->super->paused = !sys->super->paused; sys->super->paused = !sys->super->paused;
} }
} }
Vec2 input_MousePosition(System_Input *sys) {
POINT point;
GetCursorPos(&point);
ScreenToClient((HWND)sys->super->window, &point);
return vec2(point.x, point.y);
}

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
@ -21,6 +22,8 @@ typedef enum {
input_Key_Use, input_Key_Use,
input_Key_Dash, input_Key_Dash,
input_Key_Escape, input_Key_Escape,
input_Key_LeftMouse,
input_Key_RightMouse,
input_Key_Count input_Key_Count
} input_Key; } input_Key;
@ -63,6 +66,10 @@ void input_SetDefaultKeymap(System_Input *sys);
void input_Advance(System_Input *sys); void input_Advance(System_Input *sys);
// Get where the mouse is right now
Vec2 input_MousePosition(System_Input *sys);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif