MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gamewindow.h
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 _graphicsgamewindow_h
41 #define _graphicsgamewindow_h
42 
43 #include "Graphics/windowsettings.h"
44 namespace Ogre
45 {
46  class RenderWindow;
47 }
48 
49 struct SDL_Window;
50 
51 namespace Mezzanine
52 {
53  namespace Graphics
54  {
55  class GraphicsManager;
56  class Viewport;
57  class CameraProxy;
58  ///////////////////////////////////////////////////////////////////////////////
59  /// @brief This class is for creating and managing game windows.
60  /// @details
61  ///////////////////////////////////////
63  {
64  public:
65  /// @brief Basic container type for Viewport storage by this class.
66  typedef std::list<Viewport*> ViewportContainer;
67  /// @brief Iterator type for Viewport instances stored by this class.
68  typedef ViewportContainer::iterator ViewportIterator;
69  /// @brief Const Iterator type for Viewport instances stored by this class.
70  typedef ViewportContainer::const_iterator ConstViewportIterator;
71  /// @brief Reverse Iterator type for Viewport instances stored by this class.
72  typedef ViewportContainer::reverse_iterator ReverseViewportIterator;
73  /// @brief Const Reverse Iterator type for Viewport instances stored by this class.
74  typedef ViewportContainer::const_reverse_iterator ConstReverseViewportIterator;
75 
76  /// @enum WindowFlags
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.
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 A bit field containing all the flags used in the construction of this GameWindow.
110 
111  /// @internal
112  /// @brief Convenience method for constructing a window.
113  /// @param WindowCaption The caption to be set in the window titlebar.
114  /// @param Width The desired width in pixels.
115  /// @param Height The desired height in pixels.
116  /// @param Flags Additional misc parameters, see WindowFlags enum for more info.
117  void CreateGameWindow(const String& WindowCaption, const Whole Width, const Whole Height, const Whole Flags);
118  /// @internal
119  /// @brief Updates all the viewports of this window and the cameras attached to them after a change in window geometry.
120  void UpdateViewportsAndCameras();
121  /// @internal
122  /// @brief Checks to see if a resolution is larger than the currently set desktop resolution.
123  /// @remarks This method is used for a check that is only really needed on Windows XP. When a resolution is selected that is larger
124  /// than the desktop resolution then the app hardlocks somewhere inside of SDL.
125  /// @param Width The number of horizontal pixels to check against the desktop.
126  /// @param Height The number of vertical pixels to check against the desktop.
127  /// @return Returns "1" if the resolution provided is larger, "-1" if the resolution is smaller, and "0" if the resolution is the same.
128  int IsLargerThenDesktop(const Whole Width, const Whole Height);
129  public:
130  /// @brief Class constructor.
131  /// @param WindowCaption The caption to be set in the window titlebar.
132  /// @param Width The desired width in pixels.
133  /// @param Height The desired height in pixels.
134  /// @param Flags Additional misc parameters, see WindowFlags enum for more info.
135  GameWindow(const String& WindowCaption, const Whole Width, const Whole Height, const Whole Flags);
136  /// @brief Class destructor.
137  ~GameWindow();
138 
139  ///////////////////////////////////////////////////////////////////////////////
140  // Viewport Management
141 
142  /// @brief Creates an additional Viewport within a created render window.
143  /// @param VeiwportCamera The camera that is to be attached to this Viewport.
144  /// @param ZOrder The render order of this viewport relative to other viewports in this window.
145  /// @return Returns a pointer to the created Viewport.
146  Viewport* CreateViewport(CameraProxy* ViewportCamera, const Integer ZOrder);
147  /// @brief Gets a viewport by index.
148  /// @param Index The index of the Viewport to retrieve.
149  /// @return Returns a pointer to the viewport requested.
150  Viewport* GetViewport(const Whole Index) const;
151  /// @brief Gets a viewport by ZOrder.
152  /// @param ZOrder The ZOrder of the Viewport to retrieve.
153  /// @return Returns a pointer at the specified ZOrder, or NULL if no Viewports use that ZOrder.
154  Viewport* GetViewportByZOrder(const Integer ZOrder) const;
155  /// @brief Gets the number of viewports within this window.
156  /// @return Returns a Whole representing the number of viewports within this window.
157  Whole GetNumViewports() const;
158  /// @brief Destroys a viewport within this window.
159  /// @param ToBeDestroyed The viewport that will be destroyed.
160  void DestroyViewport(Viewport* ToBeDestroyed);
161 
162  /// @brief Gets an iterator to the first viewport in this window.
163  ViewportIterator BeginViewport();
164  /// @brief Gets an iterator to one passed the last viewport in this window.
165  ViewportIterator EndViewport();
166  /// @brief Gets a const iterator to the first viewport in this window.
167  ConstViewportIterator BeginViewport() const;
168  /// @brief Gets a const iterator to one passed the last viewport in this window.
169  ConstViewportIterator EndViewport() const;
170 
171  /// @brief Gets an iterator to the last viewport in this window.
172  ReverseViewportIterator ReverseBeginViewport();
173  /// @brief Gets an iterator to one before the first viewport in this window.
174  ReverseViewportIterator ReverseEndViewport();
175  /// @brief Gets a const iterator to the last viewport in this window.
176  ConstReverseViewportIterator ReverseBeginViewport() const;
177  /// @brief Gets a const iterator to one before the first viewport in this window.
178  ConstReverseViewportIterator ReverseEndViewport() const;
179 
180  ///////////////////////////////////////////////////////////////////////////////
181  // Window Metrics Management
182 
183  /// @brief Sets the Width.
184  /// @details Set the Render Width inside the window in windowed mode, set the resolution of the screen in fullscreen
185  /// @param Width This accepts a Whole.
186  void SetRenderWidth(const Whole& Width);
187  /// @brief Gets the Width of the Rendering Area
188  /// @details Gets the Width of the Rendering Area
189  /// @return This returns the Width of the Rendering Area
190  Whole GetRenderWidth() const;
191  /// @brief Sets the Height.
192  /// @details Set the Render Height inside the window in windowed mode, set the resolution of the screen in fullscreen
193  /// @param Height This accepts a Whole.
194  void SetRenderHeight(const Whole& Height);
195  /// @brief Gets the Height of the Rendering Area
196  /// @details Gets the Height of the Rendering Area
197  /// @return This returns the Height of the Rendering Area
198  Whole GetRenderHeight() const;
199  /// @brief Changes the X and Y Resolution at the same time
200  /// @details This should be useful in situations where it is not possible to update the width and height separately.
201  /// @param Width The new desired Width for the rendering area as a whole number
202  /// @param Height The new desired Width for the rendering area as a whole number
203  void SetRenderResolution(const Whole& Width, const Whole& Height);
204  /// @brief Set the Fullscreen Setting
205  /// @details Set the Fullscreen Setting
206  /// @param Fullscreen This accepts a bool. True for fullscreen, false for windowed
207  void SetFullscreen(const bool Fullscreen);
208  /// @brief Gets the Fullscreen Setting
209  /// @details Gets the Fullscreen Setting
210  /// @return This returns a bool, true if fullscreen is set, false otherwise
211  bool GetFullscreen() const;
212  /// @brief Changes the X Resolution, Y Resolution, and fullscreen at the same time
213  /// @details This should be useful in situations where it is not possible to update all of the options separately.
214  void SetRenderOptions(const WindowSettings& NewSettings);
215  /// @brief Gets the current window settings.
216  /// @param Returns a WindowSettings struct with the current window settings.
217  const WindowSettings& GetSettings();
218 
219  ///////////////////////////////////////////////////////////////////////////////
220  // Window Settings Methods
221 
222  /// @brief Gets the the text in the titlebar.
223  /// @return Returns a const string ref of the text in the titlebar.
224  const String& GetWindowCaption();
225  /// @brief Gets the current level of Anti-Aliasing enabled on this Window.
226  /// @return Returns a Whole indicating which level of AA is enabled on this window, or 0 if AA is disabled.
227  Whole GetFSAALevel() const;
228  /// @brief Enables (or disables) vsync on this window.
229  /// @param Enable Whether or not to enable vsync.
230  void EnableVsync(bool Enable);
231  /// @brief Gets whether or not vsync is currently enabled on this window.
232  /// @return Returns true if vsync is currently enabled, false otherwise.
233  Boolean VsyncEnabled() const;
234  /// @brief Hides (shows) the window.
235  /// @param Hidden Whether or not to hide the window.
236  void SetHidden(bool Hidden);
237  /// @brief Gets whether this window is hidden.
238  /// @return Returns true if this window is being hidden, false otherwise.
239  Boolean IsHidden() const;
240  /// @brief Gets whether or not this window has a resizeable border.
241  /// @return Returns true if this window has a border when not fullscreen and it can be resized, false otherwise.
242  Boolean BorderIsResizeable() const;
243  /// @brief Gets whether this window is borderless.
244  /// @return Returns true if this window has no border, false otherwise.
245  Boolean IsBorderless() const;
246 
247  ///////////////////////////////////////////////////////////////////////////////
248  // Window Stats Methods
249 
250  /// @brief Gets the FPS based on the last frame rendered.
251  /// @details This essentially determines how many frames could be rendered if all
252  /// frames within a second rendered at the same speed.
253  /// @return Returns a Real representing the framerate.
254  Real GetLastFPS() const;
255  /// @brief Gets the Average FPS.
256  /// @return Returns a Real representing the average framerate.
257  Real GetAverageFPS() const;
258  /// @brief Gets the Best FPS.
259  /// @return Returns a Real representing the best framerate.
260  Real GetBestFPS() const;
261  /// @brief Gets the Worst FPS.
262  /// @return Returns a Real representing the worst framerate.
263  Real GetWorstFPS() const;
264  /// @brief Gets the shortest amount of time it's taken to render a frame.
265  /// @return Returns a Real representing the best time for rendering a frame.
266  Real GetBestFrameTime() const;
267  /// @brief Gets the longest amount of time it's taken to render a frame.
268  /// @return Returns a Real representing the worst time for rendering a frame.
269  Real GetWorstFrameTime() const;
270 
271  ///////////////////////////////////////////////////////////////////////////////
272  // Internal Methods
273 
274  /// @internal
275  /// @brief This will get a pointer to the Ogre RenderWindow.
276  /// @return Returns a pointer to the Ogre RenderWindow class in use.
277  Ogre::RenderWindow* _GetOgreWindowPointer();
278  /// @internal
279  /// @brief This will get a pointer to the SDL Window.
280  /// @return Returns a pointer to the SDL Window class in use.
281  SDL_Window* _GetSDLWindowPointer();
282  };//GameWindow
283  }//Graphics
284 }//Mezzanine
285 
286 #endif