MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
eventgamewindow.cpp
1 // © Copyright 2010 - 2014 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 EVENTGAMEWINDOW_CPP
41 #define EVENTGAMEWINDOW_CPP
42 
43 #include "eventgamewindow.h"
44 #include "stringtool.h"
45 #include "exception.h"
46 
47 #ifdef MEZZDEBUG
48 #include "entresol.h"
49 #endif
50 
51 #include <cassert>
52 #include <memory>
53 
54 #include "SDL.h"
55 
56 namespace Mezzanine
57 {
58  /// @brief used to keep private in one place that is actually private.
60  {
61  public:
62  EventGameWindowData(EventGameWindow::GameWindowEventID GWEventID, int First_, int Second_):EventID(GWEventID),First(First_),Second(Second_)
63  {}
64 
65  /// @brief What kind of change happened to this game window
67 
68  /// @brief store a piece of information about the event.
69  int First;
70 
71  /// @brief store another piece of information about the event.
72  int Second;
73  };
74 
76  { Data=0; construct(Raw_); }
77 
79  { Data=0; construct(GWEventID, First, Second); }
80 
82  {
83  Data=0;
84  assert(Other.Data);
85  construct(Other.Data->EventID, Other.Data->First, Other.Data->Second);
86  }
87 
89  { return EventBase::GameWindow; }
90 
92  {
93  delete this->Data;
94  }
95 
97  {
98  assert(this->Data);
99  return this->Data->EventID;
100  }
101 
103  {
104  assert(this->Data);
105  return this->Data->First;
106  }
107 
109  {
110  assert(this->Data);
111  return this->Data->Second;
112  }
113 
115  {
116  switch (GWEventID)
117  {
118  case GAME_WINDOW_NONE:
119  return "GAME_WINDOW_NONE";
120  case GAME_WINDOW_SHOWN:
121  return "GAME_WINDOW_SHOWN";
122  case GAME_WINDOW_HIDDEN:
123  return "GAME_WINDOW_HIDDEN";
124  case GAME_WINDOW_EXPOSED:
125  return "GAME_WINDOW_EXPOSED";
126  case GAME_WINDOW_MOVED:
127  return "GAME_WINDOW_MOVED";
128  case GAME_WINDOW_RESIZED:
129  return "GAME_WINDOW_RESIZED";
131  return "GAME_WINDOW_SIZE_CHANGED";
133  return "GAME_WINDOW_MINIMIZED";
135  return "GAME_WINDOW_MAXIMIZED";
137  return "GAME_WINDOW_RESTORED";
138  case GAME_WINDOW_ENTER:
139  return "GAME_WINDOW_ENTER";
140  case GAME_WINDOW_LEAVE:
141  return "GAME_WINDOW_LEAVE";
143  return "GAME_WINDOW_FOCUS_GAINED";
145  return "GAME_WINDOW_FOCUS_LOST";
146  case GAME_WINDOW_CLOSE:
147  return "GAME_WINDOW_CLOSE";
148  default:
149  throw("Unhandled EventGameWindow::GameWindowEventID reached during eventid to String conversion.");
150  }
151  }
152 
154  { return ( GAME_WINDOW_FIRST <= this->GetEventID() && this->GetEventID() <= GAME_WINDOW_LAST ); }
155 
157  {
158  if(this->Data==Other.Data)
159  { return; }
160  this->Data->EventID=Other.Data->EventID;
161  this->Data->First=Other.Data->First;
162  this->Data->Second=Other.Data->Second;
163  }
164 
166  {
167  assert(this->Data);
168  return ( this->Data->EventID==Other.Data->EventID && this->Data->First==Other.Data->First && this->Data->Second==Other.Data->Second );
169  }
170 
172  { return GetEventID()==Other; }
173 
174  void EventGameWindow::construct(RawEvent Raw_)
175  {
176  assert((int)GAME_WINDOW_NONE==(int)SDL_WINDOWEVENT_NONE);
177  assert((int)GAME_WINDOW_CLOSE==(int)SDL_WINDOWEVENT_CLOSE);
179  switch (Raw_.window.event)
180  {
181  case SDL_WINDOWEVENT_NONE:
182  GWEventID = GAME_WINDOW_NONE; break;
183  case SDL_WINDOWEVENT_SHOWN:
184  GWEventID = GAME_WINDOW_SHOWN; break;
185  case SDL_WINDOWEVENT_HIDDEN:
186  GWEventID = GAME_WINDOW_HIDDEN; break;
187  case SDL_WINDOWEVENT_EXPOSED:
188  GWEventID = GAME_WINDOW_EXPOSED; break;
189  case SDL_WINDOWEVENT_MOVED:
190  GWEventID = GAME_WINDOW_MOVED; break;
191  case SDL_WINDOWEVENT_RESIZED:
192  GWEventID = GAME_WINDOW_RESIZED; break;
193  case SDL_WINDOWEVENT_SIZE_CHANGED:
194  GWEventID = GAME_WINDOW_SIZE_CHANGED; break;
195  case SDL_WINDOWEVENT_MINIMIZED:
196  GWEventID = GAME_WINDOW_MINIMIZED; break;
197  case SDL_WINDOWEVENT_MAXIMIZED:
198  GWEventID = GAME_WINDOW_MAXIMIZED; break;
199  case SDL_WINDOWEVENT_RESTORED:
200  GWEventID = GAME_WINDOW_RESTORED; break;
201  case SDL_WINDOWEVENT_ENTER:
202  GWEventID = GAME_WINDOW_ENTER; break;
203  case SDL_WINDOWEVENT_LEAVE:
204  GWEventID = GAME_WINDOW_LEAVE; break;
205  case SDL_WINDOWEVENT_FOCUS_GAINED:
206  GWEventID = GAME_WINDOW_FOCUS_GAINED; break;
207  case SDL_WINDOWEVENT_FOCUS_LOST:
208  GWEventID = GAME_WINDOW_FOCUS_LOST; break;
209  case SDL_WINDOWEVENT_CLOSE:
210  GWEventID = GAME_WINDOW_CLOSE; break;
211  default:
212  throw("Unhandled EventGameWindow::GameWindowEventID reached during event creation.");
213  }
214  construct(GWEventID, Raw_.window.data1, Raw_.window.data2);
215  }
216 
217  void EventGameWindow::construct(EventGameWindow::GameWindowEventID GWEventID, int First, int Second)
218  {
219  this->Data=new EventGameWindowData(GWEventID,First, Second);
220  }
221 }
222 
223 ///////////////////////////////////////////////////////////////////////////////
224 // Class External << Operators for streaming or assignment
225 std::ostream& operator << (std::ostream& stream, const Mezzanine::EventGameWindow& Ev)
226 {
227  stream << "<EventGameWindow Version=\"1\" EventID=\"" << Ev.GetEventID() << "\" First=\"" << Ev.GetFirstEventData() << "\" Second=\"" << Ev.GetSecondEventData() << "\" />";
228  return stream;
229 }
230 
231 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::EventGameWindow& Ev)
232 {
235 
236  Doc->GetFirstChild() >> Ev;
237 
238  return stream;
239 }
240 
241 const Mezzanine::XML::Node& operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::EventGameWindow& Ev)
242 {
243  if ( Mezzanine::String(OneNode.Name())==Mezzanine::String("EventGameWindow") )
244  {
245  if(OneNode.GetAttribute("Version").AsInt() == 1)
246  {
248  OneNode.GetAttribute("First").AsInt(),
249  OneNode.GetAttribute("Second").AsInt() );
250  }else{
251  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for EventGameWindow: Not Version 1");
252  }
253  }else{
254  MEZZ_EXCEPTION(Mezzanine::Exception::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a EventGameWindow, found a " + Mezzanine::String(OneNode.Name()));
255  }
256 
257  return OneNode;
258 }
259 
261 {
262  if ( Mezzanine::String(OneNode.Name())==Mezzanine::String("EventGameWindow") )
263  {
264  if(OneNode.GetAttribute("Version").AsInt() == 1)
265  {
267  OneNode.GetAttribute("First").AsInt(),
268  OneNode.GetAttribute("Second").AsInt() );
269  }else{
270  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for EventGameWindow: Not Version 1");
271  }
272  }else{
273  MEZZ_EXCEPTION(Mezzanine::Exception::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a EventGameWindow, found a " + Mezzanine::String(OneNode.Name()));
274  }
275 
276  return OneNode;
277 }
278 
279 #endif
280