Bromeon
Events/Action.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 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/Detail/ActionOperations.hpp>
00033 #include <Thor/Config.hpp>
00034 
00035 
00036 namespace thor
00037 {
00038 namespace detail
00039 {
00040 
00041     class EventBuffer;
00042 
00043 } // namespace detail
00044 
00045 // ---------------------------------------------------------------------------------------------------------------------------
00046 
00047 
00050 
00054 class THOR_API Action
00055 {
00056     // ---------------------------------------------------------------------------------------------------------------------------
00057     // Public types
00058     public:
00059 
00062         enum ActionType
00063         {
00064             Realtime,       
00065             PressOnce,      
00066             ReleaseOnce,    
00067             Once,           
00068         };
00069 
00070 
00071     // ---------------------------------------------------------------------------------------------------------------------------
00072     // Public member functions
00073     public:
00077         explicit                    Action(sf::Keyboard::Key key, ActionType action = Realtime);
00078 
00082         explicit                    Action(sf::Mouse::Button mouseButton, ActionType action = Realtime);
00083 
00088         explicit                    Action(Joystick joystickState, ActionType action = Realtime);
00089 
00092         explicit                    Action(sf::Event::EventType eventType);
00093 
00094 
00095     // ---------------------------------------------------------------------------------------------------------------------------
00096     // Implementation details
00097     public:
00098         // Default constructor: Required for ActionMap::operator[] - constructs an uninitialized action
00099                                     Action();
00100 
00101         // Tests if the event/real time input constellation in the argument is true for this action
00102         bool                        IsActive(const detail::EventBuffer& buffer) const;
00103 
00104         // Test if active and store relevant events
00105         bool                        IsActive(const detail::EventBuffer& buffer, detail::ActionResult& out) const;
00106 
00107 
00108     // ---------------------------------------------------------------------------------------------------------------------------
00109     // Private member functions
00110     private:
00111         // Construct from movable pointer to the action's operation
00112         explicit                    Action(detail::ActionNode::MovedPtr operation);
00113 
00114 
00115     // ---------------------------------------------------------------------------------------------------------------------------
00116     // Private variables
00117     private:
00118         detail::ActionNode::CopiedPtr   mOperation;
00119 
00120 
00121     // ---------------------------------------------------------------------------------------------------------------------------
00122     // Friends
00124     friend Action THOR_API operator|| (const Action& lhs, const Action& rhs);
00125     friend Action THOR_API operator&& (const Action& lhs, const Action& rhs);
00127 };
00128 
00129 
00132 Action THOR_API             operator|| (const Action& lhs, const Action& rhs);
00133 
00136 Action THOR_API             operator&& (const Action& lhs, const Action& rhs);
00137 
00139 
00140 } // namespace thor
00141 
00142 #endif // THOR_ACTION_HPP