]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Input.h
added Input class for handling user input
[l2e.git] / src / app / Input.h
diff --git a/src/app/Input.h b/src/app/Input.h
new file mode 100644 (file)
index 0000000..ad50869
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Input.h
+ *
+ *  Created on: Aug 6, 2012
+ *      Author: holy
+ */
+
+#ifndef APP_INPUT_H_
+#define APP_INPUT_H_
+
+#include <SDL.h>
+#include <map>
+
+namespace app {
+
+class Input {
+
+public:
+       enum Button {
+               PAD_UP = 1,
+               PAD_RIGHT = 2,
+               PAD_DOWN = 4,
+               PAD_LEFT = 8,
+               ACTION_A = 16,
+               ACTION_B = 32,
+               ACTION_X = 64,
+               ACTION_Y = 128,
+               START = 256,
+               SELECT = 512,
+               SHOULDER_RIGHT = 1024,
+               SHOULDER_LEFT = 2048
+       };
+
+public:
+       Input();
+
+public:
+       bool IsDown(Button b) const {
+               return down & b;
+       }
+       bool JustPressed(Button b) const {
+               return pressed & b;
+       }
+       bool JustReleased(Button b) const {
+               return released & b;
+       }
+
+public:
+       void ResetInteractiveState() {
+               pressed = 0;
+               released = 0;
+       }
+       void HandleKeyboardEvent(const SDL_KeyboardEvent &);
+
+public:
+       void MapKey(SDLKey k, Button b) {
+               mapping[k] = b;
+       }
+
+private:
+       std::map<SDLKey, Button> mapping;
+       Uint16 down;
+       Uint16 pressed;
+       Uint16 released;
+
+};
+
+}
+
+#endif /* APP_INPUT_H_ */