Spinning Topp Logo BlackTopp Studios
inc
gamewindow.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 _graphicsgamewindow_h
41 #define _graphicsgamewindow_h
42 
43 #include "Graphics/windowsettings.h"
44 
45 namespace Ogre
46 {
47  class RenderWindow;
48 }
49 
50 struct SDL_Window;
51 
52 namespace Mezzanine
53 {
54  namespace Graphics
55  {
56  class GraphicsManager;
57  class Viewport;
58  class CameraProxy;
59  ///////////////////////////////////////////////////////////////////////////////
60  /// @brief This class is for creating and managing game windows.
61  /// @details
62  ///////////////////////////////////////
64  {
65  public:
66  /// @brief Basic container type for Viewport storage by this class.
67  typedef std::list<Viewport*> ViewportContainer;
68  /// @brief Iterator type for Viewport instances stored by this class.
69  typedef ViewportContainer::iterator ViewportIterator;
70  /// @brief Const Iterator type for Viewport instances stored by this class.
71  typedef ViewportContainer::const_iterator ConstViewportIterator;
72  /// @brief Reverse Iterator type for Viewport instances stored by this class.
73  typedef ViewportContainer::reverse_iterator ReverseViewportIterator;
74  /// @brief Const Reverse Iterator type for Viewport instances stored by this class.
75  typedef ViewportContainer::const_reverse_iterator ConstReverseViewportIterator;
76 
77  /// @brief A listing of potential options for configuring a game window during construction.
79  {
80  WF_Fullscreen = 1, ///< This enables fullscreen on the window.
81  WF_Hidden = 2, ///< This hides the window so that it isn't visible.
82  WF_VsyncEnabled = 4, ///< This enables vsync for the window.
83  WF_FSAA_2 = 8, ///< Enables Fullscreen Anti-Aliasing level 2 for the window.
84  WF_FSAA_4 = 16, ///< Enables Fullscreen Anti-Aliasing level 4 for the window.
85  WF_FSAA_8 = 32, ///< Enables Fullscreen Anti-Aliasing level 8 for the window.
86  WF_FSAA_16 = 64, ///< Enables Fullscreen Anti-Aliasing level 16 for the window.
87  WF_Resizeable = 128, ///< Creates a window with resizable borders, otherwise it is fixed size.
88  WF_Maximized = 256, ///< Maximizes the window immediately after construction.
89  WF_Borderless = 512 ///< Removes all window decorations from the window(titlebar, borders, etc.).
90  };
91  protected:
92  /// @internal
93  /// @brief A struct storing all the window dimensions and update settings.
95  /// @internal
96  /// @brief A container storing all the viewports belonging to this window.
97  ViewportContainer Viewports;
98  /// @internal
99  /// @brief A pointer to the manager that created this window.
101  /// @internal
102  /// @brief A pointer to the internal window used for rendering.
103  Ogre::RenderWindow* OgreWindow;
104  /// @internal
105  /// @brief A pointer to the internal window used for collecting input.
106  SDL_Window* SDLWindow;
107  /// @internal
108  /// @brief The last set FSAA level for this gamewindow (used for serialization).
110  /// @internal
111  /// @brief A bit field containing all the flags used in the construction of this GameWindow.
113 
114  /// @internal
115  /// @brief Convenience method for constructing a window.
116  /// @param WindowCaption The caption to be set in the window titlebar.
117  /// @param Width The desired width in pixels.
118  /// @param Height The desired height in pixels.
119  /// @param Flags Additional misc parameters, see WindowFlags enum for more info.
120  void CreateGameWindow(const String& WindowCaption, const Whole Width, const Whole Height, const Whole Flags);
121  /// @internal
122  /// @brief Inserts a Viewport into this window based on it's ZOrder.
123  /// @param NewVP A pointer to the Viewport being added to this window.
124  void AddViewport(Viewport* NewVP);
125  /// @internal
126  /// @brief Updates all the viewports of this window and the cameras attached to them after a change in window geometry.
127  void UpdateViewportsAndCameras();
128  public:
129  /// @brief Class constructor.
130  /// @param WindowCaption The caption to be set in the window titlebar.
131  /// @param Width The desired width in pixels.
132  /// @param Height The desired height in pixels.
133  /// @param Flags Additional misc parameters, see WindowFlags enum for more info.
134  GameWindow(const String& WindowCaption, const Whole Width, const Whole Height, const Whole Flags);
135  /// @brief XML constructor.
136  /// @param XMLNode The node of the xml document to construct from.
137  GameWindow(const XML::Node& XMLNode);
138  /// @brief Class destructor.
139  ~GameWindow();
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Viewport Management
143 
144  /// @brief Creates an additional Viewport within a created render window.
145  /// @param VeiwportCamera The camera that is to be attached to this Viewport.
146  /// @param ZOrder The render order of this viewport relative to other viewports in this window.
147  /// @return Returns a pointer to the created Viewport.
148  Viewport* CreateViewport(CameraProxy* ViewportCamera, const Integer ZOrder);
149  /// @brief Gets a viewport by index.
150  /// @param Index The index of the Viewport to retrieve.
151  /// @return Returns a pointer to the viewport requested.
152  Viewport* GetViewport(const Whole Index) const;
153  /// @brief Gets a viewport by ZOrder.
154  /// @param ZOrder The ZOrder of the Viewport to retrieve.
155  /// @return Returns a pointer at the specified ZOrder, or NULL if no Viewports use that ZOrder.
156  Viewport* GetViewportByZOrder(const Integer ZOrder) const;
157  /// @brief Gets the number of viewports within this window.
158  /// @return Returns a Whole representing the number of viewports within this window.
159  Whole GetNumViewports() const;
160  /// @brief Destroys a viewport within this window.
161  /// @param ToBeDestroyed The viewport that will be destroyed.
162  void DestroyViewport(Viewport* ToBeDestroyed);
163  /// @brief Destroys every viewport within this window.
164  void DestroyAllViewports();
165 
166  /// @brief Gets an iterator to the first viewport in this window.
167  ViewportIterator BeginViewport();
168  /// @brief Gets an iterator to one passed the last viewport in this window.
169  ViewportIterator EndViewport();
170  /// @brief Gets a const iterator to the first viewport in this window.
171  ConstViewportIterator BeginViewport() const;
172  /// @brief Gets a const iterator to one passed the last viewport in this window.
173  ConstViewportIterator EndViewport() const;
174 
175  /// @brief Gets an iterator to the last viewport in this window.
176  ReverseViewportIterator ReverseBeginViewport();
177  /// @brief Gets an iterator to one before the first viewport in this window.
178  ReverseViewportIterator ReverseEndViewport();
179  /// @brief Gets a const iterator to the last viewport in this window.
180  ConstReverseViewportIterator ReverseBeginViewport() const;
181  /// @brief Gets a const iterator to one before the first viewport in this window.
182  ConstReverseViewportIterator ReverseEndViewport() const;
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Window Metrics Management
186 
187  /// @brief Sets the width of the game window.
188  /// @param Width The pixel size of the game window on the X axis.
189  void SetWidth(const Whole& Width);
190  /// @brief Gets the Width of the game window.
191  /// @return Returns a Whole containing the size of the game window on the X axis.
192  Whole GetWidth() const;
193  /// @brief Sets the height of the game window.
194  /// @param Height The pixel size of the game window on the Y axis.
195  void SetHeight(const Whole& Height);
196  /// @brief Gets the height of the game window.
197  /// @return Returns a Whole containing the size of the game window on the Y axis.
198  Whole GetHeight() const;
199 
200  /// @brief Sets the width and height of the game window.
201  /// @param WinRes A Resolution containing the width and height to be applied.
202  void SetResolution(const Resolution& WinRes);
203  /// @brief Sets the width and height of the game window.
204  /// @param Width The pixel size of the game window on the X axis.
205  /// @param Height The pixel size of the game window on the Y axis.
206  void SetResolution(const Whole& Width, const Whole& Height);
207  /// @brief Gets the width and height of the game window.
208  /// @return Returns a const Resolution reference containing the pixel size of the window on the X and Y axes.
209  const Resolution& GetResolution() const;
210 
211  /// @brief Set the Fullscreen Setting.
212  /// @param Fullscreen This accepts a Boole. True for fullscreen, false for windowed.
213  void SetFullscreen(const Boole Fullscreen);
214  /// @brief Gets the Fullscreen Setting.
215  /// @return This returns a Boole, true if fullscreen is set, false otherwise
216  Boole GetFullscreen() const;
217 
218  /// @brief Changes the X Resolution, Y Resolution, and fullscreen at the same time.
219  /// @param NewSettings A WindowSettings struct containing all of the window settings to be applied.
220  void SetRenderOptions(const WindowSettings& NewSettings);
221  /// @brief Gets the current window settings.
222  /// @return Returns a WindowSettings struct with the current window settings.
223  const WindowSettings& GetSettings();
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Window Settings Methods
227 
228  /// @brief Gets the the text in the titlebar.
229  /// @return Returns a const string ref of the text in the titlebar.
230  const String& GetWindowCaption() const;
231 
232  /// @brief Sets the level of Full Scale Anti-Aliasing to be used when rendering to this window.
233  /// @note Generally when this gets set it will not be applied. Anti-Aliasing is a construction time property of a window.
234  /// However this will be saved when the game window and it's settings are serialized, which will be used when it is reloaded.
235  /// @param FSAA The Anti-Aliasing level to be used, generally one of these values: 0, 2, 4, 8, or 16.
236  void SetFSAALevel(const Whole FSAA);
237  /// @brief Gets the last set Anti-Aliasing level on this Window.
238  /// @note This may or may not be the same as the current FSAA level setting.
239  /// @return Returns a Whole indicating which level of AA is set on this window.
240  Whole GetFSAALevel() const;
241  /// @brief Gets the actual Anti-Aliasing level currently being used by this game window.
242  /// @return Returns the FSAA level currently being used to render this window, or 0 if FSAA is disabled.
243  Whole GetActualFSAALevel() const;
244 
245  /// @brief Enables (or disables) vsync on this window.
246  /// @param Enable Whether or not to enable vsync.
247  void EnableVsync(Boole Enable);
248  /// @brief Gets whether or not vsync is currently enabled on this window.
249  /// @return Returns true if vsync is currently enabled, false otherwise.
250  Boole VsyncEnabled() const;
251  /// @brief Hides (shows) the window.
252  /// @param Hidden Whether or not to hide the window.
253  void SetHidden(Boole Hidden);
254  /// @brief Gets whether this window is hidden.
255  /// @return Returns true if this window is being hidden, false otherwise.
256  Boole IsHidden() const;
257  /// @brief Gets whether or not this window has a resizeable border.
258  /// @return Returns true if this window has a border when not fullscreen and it can be resized, false otherwise.
259  Boole BorderIsResizeable() const;
260  /// @brief Gets whether this window is borderless.
261  /// @return Returns true if this window has no border, false otherwise.
262  Boole IsBorderless() const;
263 
264  ///////////////////////////////////////////////////////////////////////////////
265  // Window Stats Methods
266 
267  /// @brief Gets the FPS based on the last frame rendered.
268  /// @details This essentially determines how many frames could be rendered if all
269  /// frames within a second rendered at the same speed.
270  /// @return Returns a Real representing the framerate.
271  Real GetLastFPS() const;
272  /// @brief Gets the Average FPS.
273  /// @return Returns a Real representing the average framerate.
274  Real GetAverageFPS() const;
275  /// @brief Gets the Best FPS.
276  /// @return Returns a Real representing the best framerate.
277  Real GetBestFPS() const;
278  /// @brief Gets the Worst FPS.
279  /// @return Returns a Real representing the worst framerate.
280  Real GetWorstFPS() const;
281  /// @brief Gets the shortest amount of time it's taken to render a frame.
282  /// @return Returns a Real representing the best time for rendering a frame.
283  Real GetBestFrameTime() const;
284  /// @brief Gets the longest amount of time it's taken to render a frame.
285  /// @return Returns a Real representing the worst time for rendering a frame.
286  Real GetWorstFrameTime() const;
287 
288  ///////////////////////////////////////////////////////////////////////////////
289  // Serialization
290 
291  /// @brief Convert this class to an XML::Node ready for serialization.
292  /// @param ParentNode The point in the XML hierarchy that all this GameWindow should be appended to.
293  void ProtoSerialize(XML::Node& ParentNode) const;
294  /// @brief Convert the properties of this class to an XML::Node ready for serialization.
295  /// @param SelfRoot The root node containing all the serialized data for this instance.
296  void ProtoSerializeProperties(XML::Node& SelfRoot) const;
297  /// @brief Convert the viewports of this class to an XML::Node ready for serialization.
298  /// @param SelfRoot The root node containing all the serialized data for this instance.
299  void ProtoSerializeViewports(XML::Node& SelfRoot) const;
300 
301  /// @brief Take the data stored in an XML Node and overwrite this object with it.
302  /// @param SelfRoot An XML::Node containing the data to populate this class with.
303  void ProtoDeSerialize(const XML::Node& SelfRoot);
304  /// @brief Take the data stored in an XML Node and overwrite the properties of this object with it.
305  /// @param SelfRoot An XML::Node containing the data to populate this class with.
306  void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
307  /// @brief Take the data stored in an XML Node and overwrite the viewports of this object with it.
308  /// @param SelfRoot An XML::Node containing the data to populate this class with.
309  void ProtoDeSerializeViewports(const XML::Node& SelfRoot);
310 
311  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
312  /// @return A string containing the name of this class.
313  static String GetSerializableName();
314 
315  ///////////////////////////////////////////////////////////////////////////////
316  // Internal Methods
317 
318  /// @internal
319  /// @brief This will get a pointer to the Ogre RenderWindow.
320  /// @return Returns a pointer to the Ogre RenderWindow class in use.
321  Ogre::RenderWindow* _GetOgreWindowPointer();
322  /// @internal
323  /// @brief This will get a pointer to the SDL Window.
324  /// @return Returns a pointer to the SDL Window class in use.
325  SDL_Window* _GetSDLWindowPointer();
326  };//GameWindow
327  }//Graphics
328 }//Mezzanine
329 
330 #endif
std::list< Viewport * > ViewportContainer
Basic container type for Viewport storage by this class.
Definition: gamewindow.h:67
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
SDL_Window * SDLWindow
A pointer to the internal window used for collecting input.
Definition: gamewindow.h:106
Ogre::RenderWindow * OgreWindow
A pointer to the internal window used for rendering.
Definition: gamewindow.h:103
ViewportContainer::iterator ViewportIterator
Iterator type for Viewport instances stored by this class.
Definition: gamewindow.h:69
This stores all the basic configuration options a game window supports.
Definition: resolution.h:57
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
WindowFlags
A listing of potential options for configuring a game window during construction. ...
Definition: gamewindow.h:78
This stores all the basic configuration options a game window supports.
ViewportContainer::reverse_iterator ReverseViewportIterator
Reverse Iterator type for Viewport instances stored by this class.
Definition: gamewindow.h:73
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This class is for creating and managing viewports within a game window.
Definition: viewport.h:65
WindowSettings Settings
A struct storing all the window dimensions and update settings.
Definition: gamewindow.h:94
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
ViewportContainer::const_reverse_iterator ConstReverseViewportIterator
Const Reverse Iterator type for Viewport instances stored by this class.
Definition: gamewindow.h:75
ViewportContainer Viewports
A container storing all the viewports belonging to this window.
Definition: gamewindow.h:97
ViewportContainer::const_iterator ConstViewportIterator
Const Iterator type for Viewport instances stored by this class.
Definition: gamewindow.h:71
This is the proxy class for placing and manipulating a camera in the scene.
Definition: cameraproxy.h:65
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
This is intended to store basic graphics setting for the user.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Whole RequestedFSAA
The last set FSAA level for this gamewindow (used for serialization).
Definition: gamewindow.h:109
GraphicsManager * Manager
A pointer to the manager that created this window.
Definition: gamewindow.h:100
Whole CreationFlags
A bit field containing all the flags used in the construction of this GameWindow. ...
Definition: gamewindow.h:112
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
This class is for creating and managing game windows.
Definition: gamewindow.h:63