Input/Action.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2015 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_ACTION_HPP
00030 #define THOR_ACTION_HPP
00031 
00032 #include <Thor/Input/Detail/ActionOperations.hpp>
00033 #include <Thor/Config.hpp>
00034 
00035 #include <functional>
00036 
00037 
00038 namespace thor
00039 {
00040 namespace detail
00041 {
00042 
00043     class EventBuffer;
00044 
00045 } // namespace detail
00046 
00047 // ---------------------------------------------------------------------------------------------------------------------------
00048 
00049 
00052 
00056 class THOR_API Action
00057 {
00058     // ---------------------------------------------------------------------------------------------------------------------------
00059     // Public types
00060     public:
00061 
00064         enum ActionType
00065         {
00066             Hold,           
00067             PressOnce,      
00068             ReleaseOnce,    
00069         };
00070 
00071 
00072     // ---------------------------------------------------------------------------------------------------------------------------
00073     // Public member functions
00074     public:
00078         explicit                    Action(sf::Keyboard::Key key, ActionType action = Hold);
00079 
00083         explicit                    Action(sf::Mouse::Button mouseButton, ActionType action = Hold);
00084 
00089         explicit                    Action(JoystickButton joystickState, ActionType action = Hold);
00090 
00096         explicit                    Action(JoystickAxis joystickAxis);
00097 
00100         explicit                    Action(sf::Event::EventType eventType);
00101 
00102 
00103     // ---------------------------------------------------------------------------------------------------------------------------
00104     // Implementation details
00105     public:
00106         // Default constructor: Required for ActionMap::operator[] - constructs an uninitialized action
00107                                     Action();
00108 
00109         // Tests if the event/real time input constellation in the argument is true for this action
00110         bool                        isActive(const detail::EventBuffer& buffer) const;
00111 
00112         // Test if active and store relevant events
00113         bool                        isActive(const detail::EventBuffer& buffer, detail::ActionResult& out) const;
00114 
00115 
00116     // ---------------------------------------------------------------------------------------------------------------------------
00117     // Private member functions
00118     private:
00119         // Construct from movable pointer to the action's operation
00120         explicit                    Action(detail::ActionNode::CopiedPtr operation);
00121 
00122 
00123     // ---------------------------------------------------------------------------------------------------------------------------
00124     // Private variables
00125     private:
00126         detail::ActionNode::CopiedPtr   mOperation;
00127 
00128 
00129     // ---------------------------------------------------------------------------------------------------------------------------
00130     // Friends
00132     friend Action THOR_API operator|| (const Action& lhs, const Action& rhs);
00133     friend Action THOR_API operator&& (const Action& lhs, const Action& rhs);
00134     friend Action THOR_API operator! (const Action& action);
00135     friend Action THOR_API eventAction(std::function<bool(const sf::Event&)> filter);
00136     friend Action THOR_API realtimeAction(std::function<bool()> filter);
00138 };
00139 
00140 
00150 Action THOR_API             operator|| (const Action& lhs, const Action& rhs);
00151 
00162 Action THOR_API             operator&& (const Action& lhs, const Action& rhs);
00163 
00174 Action THOR_API             operator! (const Action& action);
00175 
00190 Action THOR_API             eventAction(std::function<bool(const sf::Event&)> filter);
00191 
00206 Action THOR_API             realtimeAction(std::function<bool()> filter);
00207 
00208 
00210 
00211 } // namespace thor
00212 
00213 #endif // THOR_ACTION_HPP