ActionMap.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2015 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_ACTIONMAP_HPP
30 #define THOR_ACTIONMAP_HPP
31 
32 #include <Thor/Input/Action.hpp>
34 #include <Thor/Input/Detail/ActionOperations.hpp>
35 
36 #include <Aurora/Tools/NonCopyable.hpp>
37 #include <Aurora/Tools/ForEach.hpp>
38 
39 #include <map>
40 
41 
42 namespace thor
43 {
44 
45 template <typename Event, typename EventId>
47 
48 
51 
59 template <typename ActionId>
60 class ActionMap : private aurora::NonCopyable
61 {
62  // ---------------------------------------------------------------------------------------------------------------------------
63  // Public types
64  public:
68 
69 
70  // ---------------------------------------------------------------------------------------------------------------------------
71  // Public member functions
72  public:
75  ActionMap();
76 
79  ActionMap(ActionMap&& source);
80 
83  ActionMap& operator= (ActionMap&& source);
84 
100  void update(sf::Window& window);
101 
105  void pushEvent(const sf::Event& event);
106 
110  void clearEvents();
111 
119  Action& operator[] (const ActionId& id);
120 
123  void removeAction(const ActionId& id);
124 
127  void clearActions();
128 
137  bool isActive(const ActionId& id) const;
138 
165  void invokeCallbacks(CallbackSystem& system, sf::Window* window) const;
166 
167 
168  // ---------------------------------------------------------------------------------------------------------------------------
169  // Private types
170  private:
171  typedef std::map<ActionId, Action> Map;
172 
173 
174  // ---------------------------------------------------------------------------------------------------------------------------
175  // Private variables
176  private:
177  Map mActionMap;
178  detail::EventBuffer mEventBuffer;
179 };
180 
182 
183 } // namespace thor
184 
185 #include <Thor/Input/Detail/ActionMap.inl>
186 #endif // THOR_ACTIONMAP_HPP
Class for dynamic actions that are connected with SFML events.
Definition: Action.hpp:56
Class for object-oriented handling of user-defined events.
Definition: ActionMap.hpp:46
Action & operator[](const ActionId &id)
Returns the action associated with a given action identifier.
Class template that associates identifiers with dynamic actions.
Definition: ActionMap.hpp:60
void clearEvents()
Removes the events that have been temporarily stored.
ActionMap()
Default constructor.
Definition: Animator.hpp:42
ActionMap & operator=(ActionMap &&source)
Move assignment operator.
bool isActive(const ActionId &id) const
Returns whether the action associated with the specified identifier is currently in effect...
Class template thor::ActionContext.
void clearActions()
Removes all actions associated with this map.
void update(sf::Window &window)
Clears old events and polls the window for new ones.
EventSystem< ActionContext< ActionId >, ActionId > CallbackSystem
EventSystem to connect ActionMap with event listeners.
Definition: ActionMap.hpp:67
void removeAction(const ActionId &id)
Remove the action associated with the specified id.
void invokeCallbacks(CallbackSystem &system, sf::Window *window) const
Forwards active actions to a callback system.
void pushEvent(const sf::Event &event)
Feeds the action map with a SFML event, that can be used during the current frame.
Class thor::Action.