From 7ebb0e91f63203753420b5a4b75d09d170f204f4 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 5 Oct 2010 08:34:46 +0200 Subject: Added wriggle/input. --- application.cpp | 4 ++++ application.h | 3 ++- input.cpp | 10 ++++++++++ input.h | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 input.cpp create mode 100644 input.h diff --git a/application.cpp b/application.cpp index cafaeab..8ef9197 100644 --- a/application.cpp +++ b/application.cpp @@ -2,6 +2,8 @@ #include +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 +#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 + +namespace Key { + using namespace sf::Key; +} + +class Input { + public: + static bool key_pressed(Key::Code key); +}; + +#endif -- cgit v1.2.3