summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-10-05 08:34:46 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-10-05 08:34:46 +0200
commit7ebb0e91f63203753420b5a4b75d09d170f204f4 (patch)
tree7acc39bcbb3970e9112834c6082581e882517c87
parentf88411abc7150ed209efcb6180503f0c6f7c8ef6 (diff)
Added wriggle/input.
-rw-r--r--application.cpp4
-rw-r--r--application.h3
-rw-r--r--input.cpp10
-rw-r--r--input.h15
4 files changed, 31 insertions, 1 deletions
diff --git a/application.cpp b/application.cpp
index cafaeab..8ef9197 100644
--- a/application.cpp
+++ b/application.cpp
@@ -2,6 +2,8 @@
#include <stdexcept>
+extern const sf::Input* input_backend;
+
Application::Application() {
please_quit = false;
}
@@ -14,6 +16,8 @@ void Application::init_window(unsigned int w, unsigned int h, bool fs) {
window = new sf::Window(sf::VideoMode(w, h, 32), "Foo");
window->UseVerticalSync(true);
+
+ input_backend = &window->GetInput();
}
void Application::run() {
diff --git a/application.h b/application.h
index 4504e9e..a71ac93 100644
--- a/application.h
+++ b/application.h
@@ -2,6 +2,7 @@
#define APPLICATION_H
#include <SFML/Window.hpp>
+#include "input.h"
class Application {
private:
@@ -12,7 +13,7 @@ class Application {
void init_window(unsigned int w, unsigned int h, bool fs = false);
virtual void event(const sf::Event& e);
- virtual void event_keypress(sf::Key::Code key);
+ virtual void event_keypress(Key::Code key);
virtual void update() = 0;
diff --git a/input.cpp b/input.cpp
new file mode 100644
index 0000000..caeae82
--- /dev/null
+++ b/input.cpp
@@ -0,0 +1,10 @@
+#include "input.h"
+
+const sf::Input* input_backend = 0;
+
+bool Input::key_pressed(Key::Code key) {
+ if(!input_backend) {
+ return false;
+ }
+ return input_backend->IsKeyDown(key);
+}
diff --git a/input.h b/input.h
new file mode 100644
index 0000000..854b2c0
--- /dev/null
+++ b/input.h
@@ -0,0 +1,15 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include <SFML/Window/Input.hpp>
+
+namespace Key {
+ using namespace sf::Key;
+}
+
+class Input {
+ public:
+ static bool key_pressed(Key::Code key);
+};
+
+#endif