MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
actionhandler.cpp
1 //© Copyright 2010 - 2012 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 _uiactionhandler_cpp
41 #define _uiactionhandler_cpp
42 
43 #include "UI/actionhandler.h"
44 #include "UI/action.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
51  {
52 
53  }
54 
56  {
57 
58  }
59 
60  ///////////////////////////////////////////////////////////////////////////////
61  // Action Management
62 
64  {
65  ActionIterator ActIt = Actions.find(Name);
66  if( ActIt == Actions.end() )
67  {
68  Action* NewAction = new Action(Name,this);
69  Actions.insert( std::pair<String,Action*>(Name,NewAction) );
70  return NewAction;
71  }else{
72  MEZZ_EXCEPTION(Exception::II_DUPLICATE_IDENTITY_EXCEPTION,"An Action with the name \"" + Name + "\" already exists.");
73  }
74  }
75 
77  {
78  ActionIterator ActIt = Actions.find(Name);
79  if( ActIt != Actions.end() ) return (*ActIt).second;
80  else return NULL;
81  }
82 
83  void ActionHandler::DestroyAction(Action* ToBeDestroyed)
84  {
85  Unbind(ToBeDestroyed);
86  ActionIterator ActIt = Actions.find( ToBeDestroyed->GetName() );
87  if( ActIt != Actions.end() )
88  {
89  delete ToBeDestroyed;
90  Actions.erase(ActIt);
91  }
92  }
93 
95  {
96  UnbindAll();
97  for( ActionIterator ActIt = Actions.begin() ; ActIt != Actions.end() ; ++ActIt )
98  {
99  delete (*ActIt).second;
100  }
101  Actions.clear();
102  }
103 
104  ActionHandler::ActionIterator ActionHandler::BeginAction()
105  {
106  return Actions.begin();
107  }
108 
109  ActionHandler::ActionIterator ActionHandler::EndAction()
110  {
111  return Actions.end();
112  }
113 
114  ActionHandler::ConstActionIterator ActionHandler::BeginAction() const
115  {
116  return Actions.begin();
117  }
118 
119  ActionHandler::ConstActionIterator ActionHandler::EndAction() const
120  {
121  return Actions.end();
122  }
123 
124  ///////////////////////////////////////////////////////////////////////////////
125  // Binding Methods
126 
127  ActionHandler::ConstBindingRange ActionHandler::GetActionsBoundToCode(const Input::MetaCode& Code)
128  {
129  return Bindings.equal_range( Input::MetaCodeKey(Code) );
130  }
131 
132  void ActionHandler::Bind(const Input::MetaCode& Code, Action* ToBind, bool ForceUnique)
133  {
134  Input::MetaCodeKey Temp(Code);
135  if( ForceUnique )
136  {
137  BindingRange Range = Bindings.equal_range(Temp);
138  if( Range.first != Range.second )
139  {
140  Bindings.erase(Range.first,Range.second);
141  }
142  }
143  Bindings.insert( BindingPair(Temp,ToBind) );
144  }
145 
147  {
148  BindingRange Range = Bindings.equal_range( Input::MetaCodeKey(Code) );
149  for( BindingIterator BindIt = Range.first ; BindIt != Range.second ; ++BindIt )
150  (*BindIt).second = NULL;
151  }
152 
154  {
155  for( BindingIterator BindIt = Bindings.begin() ; BindIt != Bindings.end() ; ++BindIt )
156  {
157  if( ToUnbind == (*BindIt).second )
158  (*BindIt).second = NULL;
159  }
160  }
161 
163  {
164  for( BindingIterator BindIt = Bindings.begin() ; BindIt != Bindings.end() ; ++BindIt )
165  {
166  (*BindIt).second = NULL;
167  }
168  }
169 
171  {
172  Bindings.clear();
173  }
174 
175  ActionHandler::BindingIterator ActionHandler::BeginBinding()
176  {
177  return Bindings.begin();
178  }
179 
180  ActionHandler::BindingIterator ActionHandler::EndBinding()
181  {
182  return Bindings.end();
183  }
184 
185  ActionHandler::ConstBindingIterator ActionHandler::BeginBinding() const
186  {
187  return Bindings.begin();
188  }
189 
190  ActionHandler::ConstBindingIterator ActionHandler::EndBinding() const
191  {
192  return Bindings.end();
193  }
194 
195  ///////////////////////////////////////////////////////////////////////////////
196  // Internal Methods
197 
199  {
200  for( ActivatedIterator ActIt = ActivatedActions.begin() ; ActIt != ActivatedActions.end() ; ++ActIt )
201  {
202  if( BeingActivated == (*ActIt) )
203  return;
204  }
205  ActivatedActions.push_back(BeingActivated);
206  }
207 
209  {
210  Input::MetaCodeKey Temp(Code);
211  BindingRange CodeRange = Bindings.equal_range( Temp );
212  if( CodeRange.first != CodeRange.second )
213  {
214 
215  }
216  return false;
217  }
218 
220  {
221 
222  }
223  }//UI
224 }//Mezzanine
225 
226 #endif