#include "jinput.h" #include #include "jdraw.h" namespace input { static const uint8_t *keys = nullptr; static uint8_t keypressed = 0; static uint8_t keydown = 0; static uint8_t btnClicked = 0; static int wheel = 0; static int screen_zoom = 1; void init(const int zoom) { keys = SDL_GetKeyboardState(NULL); screen_zoom = zoom; } // Determina si la tecla especificada està sent polsada ara mateix bool keyDown(const uint8_t key) { return keys[key]; } // Determina si la tecla especificada ha sigut polsada, pero no tornarà a ser true fins bool keyPressed(const uint8_t key) { return key == keypressed; } // Determina si hi ha alguna tecla polsada ara mateix bool anyKey() { return keydown != 0; } bool anyKeyPressed() { return keypressed != 0; } // Torna el codi de la tecla que està sent polsada ara mateix const uint8_t whichKey() { return keydown; } // Torna el codi de la tecla que està sent polsada ara mateix const uint8_t getKeyPressed() { return keypressed; } // (US INTERN) Actualitza la tecla actualment polsada (keydown) desde jgame void updateKey(const uint8_t key) { keydown = key; } // (US INTERN) Actualitza la tecla actualment polsada (keypress) desde jgame void updateKeypressed(const uint8_t key) { keypressed = key; } // (US INTERN) Actualitza el botó del ratolí actualment polsat desde jgame void updateClk(const uint8_t btn) { btnClicked = btn; } // (US INTERN) Actualitza el valor de la roda del ratolí actual desde jgame void updateWheel(const int dy) { wheel = dy; } // Torna la posició X actual del ratolí const int mouseX() { int x; SDL_GetMouseState(&x, NULL); return x/screen_zoom; } // Torna la posició Y actual del ratolí const int mouseY() { int y; SDL_GetMouseState(NULL, &y); return y/screen_zoom; } // Determina si el botó del ratolí especificat està sent polsada ara mateix const bool mouseBtn(const int btn) { return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(btn)); } // Determina si el botó especificat ha sigut polsat, pero no tornarà a ser true fins // que no se solte el botó i se torne a polsar (Equivalent a keypress en tecles). const bool mouseClk(const int btn) { return btnClicked == btn; } // Obté el valor actual de la rodeta del ratolí const int mouseWheel() { return wheel; } }