aboutsummaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorjacopograndi <jacopo.grandi@outlook.it>2022-01-04 13:35:02 +0100
committerjacopograndi <jacopo.grandi@outlook.it>2022-01-04 13:35:02 +0100
commitbb16c32bde58cba70e4877aa2d3ebd04332eb575 (patch)
treede3d82cca043c26cbaa64837a3b2c18efc6ddb64 /commands
parent411d2f6d6a6e5370d33f0f54b2f2de7147a9d977 (diff)
linux compile and imgs
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.cpp138
-rw-r--r--commands/commands.h58
2 files changed, 98 insertions, 98 deletions
diff --git a/commands/commands.cpp b/commands/commands.cpp
index 7053316..cdaf30b 100644
--- a/commands/commands.cpp
+++ b/commands/commands.cpp
@@ -1,70 +1,70 @@
-#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);
-
- resx = -1; resy = -1;
-
- 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; }
- }
- if(e.type == SDL_WINDOWEVENT
- && e.window.event == SDL_WINDOWEVENT_RESIZED ) {
- resx = e.window.data1; resy = e.window.data2;
- }
- }
- 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();
+#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);
+
+ resx = -1; resy = -1;
+
+ 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; }
+ }
+ if(e.type == SDL_WINDOWEVENT
+ && e.window.event == SDL_WINDOWEVENT_RESIZED ) {
+ resx = e.window.data1; resy = e.window.data2;
+ }
+ }
+ 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
diff --git a/commands/commands.h b/commands/commands.h
index 5513790..020f186 100644
--- a/commands/commands.h
+++ b/commands/commands.h
@@ -1,30 +1,30 @@
-#ifndef COMMANDS_H
-#define COMMANDS_H
-
-#include <iostream>
-#include <vector>
-
-#define SDL_MAIN_HANDLED
-#include <SDL2/SDL.h>
-
-class Commands_sdl {
- public:
- Commands_sdl ();
- ~Commands_sdl ();
- bool process_events ();
- void process_clicks ();
- void process_keys ();
- bool check_keydown(SDL_Scancode key);
- bool check_key(SDL_Scancode key);
- int mx, my;
- int mclick[3];
- int mheld[3];
-
- int resx, resy;
-
- private:
- std::vector<SDL_Scancode> keys;
- std::vector<SDL_Scancode> keysdown;
-};
-
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+#include <iostream>
+#include <vector>
+
+#define SDL_MAIN_HANDLED
+#include <SDL2/SDL.h>
+
+class Commands_sdl {
+ public:
+ Commands_sdl ();
+ ~Commands_sdl ();
+ bool process_events ();
+ void process_clicks ();
+ void process_keys ();
+ bool check_keydown(SDL_Scancode key);
+ bool check_key(SDL_Scancode key);
+ int mx, my;
+ int mclick[3];
+ int mheld[3];
+
+ int resx, resy;
+
+ private:
+ std::vector<SDL_Scancode> keys;
+ std::vector<SDL_Scancode> keysdown;
+};
+
#endif \ No newline at end of file