Robot Devastation
SDLInputManager.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_SDL_INPUT_MANAGER_HPP__
6 #define __RD_SDL_INPUT_MANAGER_HPP__
7 
8 #include <string>
9 
10 #include <SDL.h>
11 
12 #include "InputManager.hpp"
13 
14 namespace rd{
15 
36 {
37  public:
38  virtual bool start();
39  virtual bool stop();
40  virtual bool isStopped() const;
41 
42  virtual bool configure(const std::string & parameter, const std::string & value);
43 
49  static bool RegisterManager();
50 
53 
55  static const std::string id;
56 
62  virtual bool refreshEvents();
63 
64  private:
72 
74  SDLInputManager & operator=(const SDLInputManager &);
75 
76  // This static function is the real callback function. It's compatible
77  // with the C-style CallbackFunctionPtr. The extra void* is used to
78  // get back into the real object of this class type.
79  static int staticInputCallback(void *userdata, SDL_Event *event)
80  {
81  // Get back into the class by treating p as the "this" pointer.
82  if( ! ((SDLInputManager *)userdata) -> inputCallback(event) )
83  return 1;
84  return 0;
85  }
86 
87  bool inputCallback(SDL_Event* event);
88 
89 
92 
93  bool stopped;
94 };
95 }
96 
97 #endif // __RD_SDL_INPUT_MANAGER_HPP__
rd::SDLInputManager::uniqueInstance
static SDLInputManager * uniqueInstance
Reference to this manager (unique instance)
Definition: SDLInputManager.hpp:91
rd::SDLInputManager::~SDLInputManager
~SDLInputManager()
Destructor. Used to reset the local static reference after destroying this manager.
Definition: SDLInputManager.cpp:54
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::SDLInputManager::configure
virtual bool configure(const std::string &parameter, const std::string &value)
Configures a parameter with a value.
Definition: SDLInputManager.cpp:39
rd::SDLInputManager::SDLInputManager
SDLInputManager()
Constructor.
Definition: SDLInputManager.cpp:67
rd::SDLInputManager::stop
virtual bool stop()
Stop capturing input events.
Definition: SDLInputManager.cpp:24
rd::SDLInputManager::start
virtual bool start()
Start to capture input events.
Definition: SDLInputManager.cpp:14
rd::InputManager
User input manager (keyboard, mouse, joysticks, etc)
Definition: InputManager.hpp:35
rd::SDLInputManager::RegisterManager
static bool RegisterManager()
Register this manager in the InputManager registry so that can be used.
Definition: SDLInputManager.cpp:44
rd::SDLInputManager::isStopped
virtual bool isStopped() const
True if the manager is not active.
Definition: SDLInputManager.cpp:34
rd::SDLInputManager::id
static const std::string id
String that identifies this manager.
Definition: SDLInputManager.hpp:55
rd::SDLInputManager::refreshEvents
virtual bool refreshEvents()
Get SDL info about input events.
Definition: SDLInputManager.cpp:61
rd::SDLInputManager
User input manager (keyboard, mouse, joysticks, etc) using SDL.
Definition: SDLInputManager.hpp:35