Spinning Topp Logo BlackTopp Studios
inc
action.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uiaction_h
41 #define _uiaction_h
42 
43 #include "eventpublisher.h"
44 #include "Input/metacode.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
50  class ActionHandler;
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @brief This is the base class for action specific event arguments.
53  /// @details
54  ///////////////////////////////////////
56  {
57  public:
58  ///////////////////////////////////////////////////////////////////////////////
59  // Public Data Members
60 
61  /// @brief The identification of the source firing this event.
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // Construction and Destruction
66 
67  /// @brief Class constructor.
68  /// @param Name The name of the event being fired.
69  /// @param Source The identification of the action firing this event.
70  ActionEventArguments(const String& Name, const String& Source) :
71  EventArguments(Name), ActionName(Source) { }
72  /// @brief Class destructor.
73  virtual ~ActionEventArguments() { }
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  // CountedPtr Functionality
77 
78  /// @copydoc EventArguments::GetMostDerived()
80  { return this; }
81  };//ActionEventArguments
82  }//UI
83 
84  ///////////////////////////////////////////////////////////////////////////////
85  /// @brief This is a metaprogramming traits class used by ActionEventArguments.
86  /// @details This is need for an intrusive CountedPtr implementation. Should a working external reference count be made this
87  /// could be dropped in favor of a leaner implementation.
88  ///////////////////////////////////////
89  template <>
90  class ReferenceCountTraits<UI::ActionEventArguments>
91  {
92  public:
93  /// @brief Typedef communicating the reference count type to be used.
95 
96  /// @brief Method responsible for creating a reference count for a CountedPtr of the templated type.
97  /// @param Target A pointer to the target class that is to be reference counted.
98  /// @return Returns a pointer to a new reference counter for the templated type.
99  static RefCountType* ConstructionPointer(RefCountType* Target)
100  { return Target; }
101 
102  /// @brief Enum used to decide the type of casting to be used by a reference counter of the templated type.
103  enum { IsCastable = CastStatic };
104  };//ReferenceCountTraits<ActionEventArguments>
105 
106  namespace UI
107  {
108  ///////////////////////////////////////////////////////////////////////////////
109  /// @brief This class represents an action to be taken. Can have multiple inputs bound to it.
110  /// @details
111  ///////////////////////////////////////
113  {
114  public:
115  /// @brief Event name for when this Action is activated.
117  /// @brief Event name for when this Action is deactivated.
119  protected:
120  friend class ActionHandler;
121  /// @internal
122  /// @brief The name of this action.
124  /// @internal
125  /// @brief A pointer to the handler that owns this Action.
127  //public:
128  /// @brief Class constructor.
129  /// @param Name The name to be given to the action.
130  /// @param Handler A pointer to this actions creator.
131  Action(const String& Name, ActionHandler* Handler);
132  /// @brief Class destructor.
133  ~Action();
134  public:
135  ///////////////////////////////////////////////////////////////////////////////
136  // Utility
137 
138  /// @brief Gets the name of this Action.
139  /// @return Returns a const reference to a string containing the name of this Action.
140  const String& GetName() const;
141 
142  ///////////////////////////////////////////////////////////////////////////////
143  // Internal Methods
144 
145  /// @internal
146  /// @brief Runs all logic associated with this Action being activated.
147  void _OnActivateAction();
148  /// @internal
149  /// @brief Runs all logic associated with this Action being deactivated.
150  void _OnDeactivateAction();
151  /// @internal
152  /// @brief Handles input passed to this Action.
153  /// @param Code The MetaCode to be processed.
154  /// @return Returns true if this input was consumed/handled, false otherwise.
155  Boole _HandleInput(const Input::MetaCode& Code);
156  };//Action
157  }//UI
158 }//Mezzanine
159 
160 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
UI::ActionEventArguments RefCountType
Typedef communicating the reference count type to be used.
Definition: action.h:94
ActionHandler * Parent
A pointer to the handler that owns this Action.
Definition: action.h:126
const String ActionName
The name of this action.
Definition: action.h:123
virtual ~ActionEventArguments()
Class destructor.
Definition: action.h:73
This is the base class for any class that generates and publishes events to subscribers.
This class is the core class responsible for the management of actions.
Definition: actionhandler.h:54
ActionEventArguments(const String &Name, const String &Source)
Class constructor.
Definition: action.h:70
This is used to deduce at compile if a specific class has built-in reference counting or needs an ext...
Definition: countedptr.h:87
This class represents an action to be taken. Can have multiple inputs bound to it.
Definition: action.h:112
A static cast from the pointer as provided with no attempt to calls functions on the pointer target...
Definition: countedptr.h:63
This is a common class to represent all possible arguments for a given event that is fired...
This Determines the kind of user input.
Definition: metacode.h:93
static RefCountType * ConstructionPointer(RefCountType *Target)
Method responsible for creating a reference count for a CountedPtr of the templated type...
Definition: action.h:99
const String ActionName
The identification of the source firing this event.
Definition: action.h:62
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual ActionEventArguments * GetMostDerived()
Get a pointer to the most Derived type of this instance.
Definition: action.h:79
This is the base class for action specific event arguments.
Definition: action.h:55
static const String EventActionActivated
Event name for when this Action is activated.
Definition: action.h:116
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
static const String EventActionDeactivated
Event name for when this Action is deactivated.
Definition: action.h:118