From: matthew Date: Sat, 3 Nov 2018 16:20:06 +0000 (+0000) Subject: added mouse input X-Git-Url: https://git.owens.tech/assets/static/dummy.html/assets/static/dummy.html/git?a=commitdiff_plain;h=414fe314b2df33d8ce954e7c53bd746e018c57c3;p=csrpg.git added mouse input --- diff --git a/gl/input.c b/gl/input.c index c3c97a2..604de3c 100644 --- a/gl/input.c +++ b/gl/input.c @@ -2,13 +2,25 @@ #include "err.h" #include -typedef struct InputDevice{ +typedef struct KeyboardDevice{ Uint8 *state; Uint8 *prevState; Uint8 *binds; -}InputDevice; +}KeyboardDevice; -static InputDevice kb = {NULL,NULL,NULL}; +typedef struct MouseState{ + Uint8 buttons; + int x, y; + int relX, relY; // the xy coords relative to the last frame +}MouseState; + +typedef struct MouseDevice{ + MouseState state; + MouseState prevState; +}MouseDevice; + +static KeyboardDevice kb = {NULL,NULL,NULL}; +static MouseDevice m; //Setting buttonCount to 5, as SDL supports 5 mouse buttons bool devicesNotInitilised() { @@ -34,6 +46,16 @@ void loadKeybinds() kb.binds[INPUT_CAMERA_PAN_OUT] = SDL_SCANCODE_W; } +vec2_t crpgInputMousePos() +{ + return vec2(m.state.x, m.state.y); +} + +vec2_t crpgInputMouseRelPos() +{ + return vec2(m.state.relX, m.state.relY); +} + bool crpgInputPressed(int action) { if(devicesNotInitilised()){ @@ -79,4 +101,9 @@ void crpgInputUpdate() //SDL_PumpEvents(); kb.prevState = kb.state; kb.state = SDL_GetKeyboardState(NULL); + + m.prevState = m.state; + //m.state.buttons = SDL_GetRelativeMouseState(&(m.state.x), &(m.state.y)); + m.state.buttons = SDL_GetMouseState(&(m.state.x), &(m.state.y)); + SDL_GetRelativeMouseState(&(m.state.relX), &(m.state.relY)); } diff --git a/gl/input.h b/gl/input.h index 3d6ae21..5b7cbaa 100644 --- a/gl/input.h +++ b/gl/input.h @@ -1,6 +1,7 @@ #ifndef INPUT_H #define INPUT_H #include +#include "math_3d.h" typedef enum crpgInputActions{ INPUT_CAMERA_PAN_DOWN = 0, @@ -19,4 +20,6 @@ void crpgInputCleanup(); bool crpgInputPressed(int action); bool crpgInputHeld(int action); bool crpgInputReleased(int action); +vec2_t crpgInputMousePos(); +vec2_t crpgInputMouseRelPos(); #endif//INPUT_H