aboutsummaryrefslogtreecommitdiff
path: root/commands/commands.cpp
diff options
context:
space:
mode:
authorjacopograndi <jak.sk8@hotmail.it>2021-08-19 18:46:51 +0200
committerjacopograndi <jak.sk8@hotmail.it>2021-08-19 18:46:51 +0200
commita8bcacc95045102e67f2feabbdddf79535837554 (patch)
tree5781dd4cb2fe66b67deab84ff4641b7e21b9c174 /commands/commands.cpp
forgot to make repo until now
Diffstat (limited to 'commands/commands.cpp')
-rw-r--r--commands/commands.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/commands/commands.cpp b/commands/commands.cpp
new file mode 100644
index 0000000..df7aed5
--- /dev/null
+++ b/commands/commands.cpp
@@ -0,0 +1,64 @@
+#include <algorithm>
+
+#include "commands.h"
+
+Commands_sdl::Commands_sdl () {
+ for (int i=0; i<3; i++) {
+ mclick[i] = 0;
+ mheld[i] = 0;
+ }
+}
+
+Commands_sdl::~Commands_sdl () {
+
+}
+
+bool Commands_sdl::check_keydown (SDL_Scancode key) {
+ return std::find(keysdown.begin(), keysdown.end(), key) != keysdown.end();
+}
+bool Commands_sdl::check_key (SDL_Scancode key) {
+ return std::find(keys.begin(), keys.end(), key) != keys.end();
+}
+
+bool Commands_sdl::process_events () {
+ SDL_GetMouseState(&mx, &my);
+
+ SDL_Event e;
+ while(SDL_PollEvent(&e) != 0) {
+ if(e.type == SDL_QUIT) {
+ return true;
+ }
+ if(e.type == SDL_KEYDOWN && e.key.repeat == 0) {
+ keys.push_back(e.key.keysym.scancode);
+ keysdown.push_back(e.key.keysym.scancode);
+ }
+ if(e.type == SDL_KEYUP) {
+ keysdown.erase(std::remove(keysdown.begin(), keysdown.end(),
+ e.key.keysym.scancode), keysdown.end());
+ }
+
+ if(e.type == SDL_MOUSEBUTTONDOWN) {
+ if (e.button.button == SDL_BUTTON_LEFT) { mclick[0] = 1; }
+ if (e.button.button == SDL_BUTTON_MIDDLE) { mclick[1] = 1; }
+ if (e.button.button == SDL_BUTTON_RIGHT) { mclick[2] = 1; }
+ }
+ if(e.type == SDL_MOUSEBUTTONUP) {
+ if (e.button.button == SDL_BUTTON_LEFT) { mclick[0] = 0; }
+ if (e.button.button == SDL_BUTTON_MIDDLE) { mclick[1] = 0; }
+ if (e.button.button == SDL_BUTTON_RIGHT) { mclick[2] = 0; }
+ }
+ }
+ return false;
+}
+
+void Commands_sdl::process_clicks () {
+ for (int i=0; i<3; i++) {
+ if (mclick[i] > 0) { mheld[i] += 1; }
+ else if (mheld[i] > 0) { mheld[i] = -1; }
+ else { mheld[i] = 0; }
+ }
+}
+
+void Commands_sdl::process_keys () {
+ keys.clear();
+} \ No newline at end of file