1 /*-------------------------------------------------------------------------
2 This source file is a part of OGRE
3 (Object-oriented Graphics Rendering Engine)
4 
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE
25 -------------------------------------------------------------------------*/
26 #ifndef __RenderWindow_H__
27 #define __RenderWindow_H__
28 
29 #include "OgrePrerequisites.h"
30 
31 #include "OgreRenderTarget.h"
32 
33 namespace Ogre
34 {
35     /** \addtogroup Core
36     *  @{
37     */
38     /** \addtogroup RenderSystem
39     *  @{
40     */
41     /** Manages the target rendering window.
42         @remarks
43             This class handles a window into which the contents
44             of a scene are rendered. There is a many-to-1 relationship
45             between instances of this class an instance of RenderSystem
46             which controls the rendering of the scene. There may be
47             more than one window in the case of level editor tools etc.
48             This class is abstract since there may be
49             different implementations for different windowing systems.
50         @remarks
51             Instances are created and communicated with by the render system
52             although client programs can get a reference to it from
53             the render system if required for resizing or moving.
54             Note that you can have multiple viewpoints
55             in the window for effects like rear-view mirrors and
56             picture-in-picture views (see Viewport and Camera).
57         @author
58             Steven Streeting
59         @version
60             1.0
61     */
62     class _OgreExport RenderWindow : public RenderTarget
63     {
64 
65     public:
66         /** Default constructor.
67         */
68         RenderWindow();
69 
70         /** Many windowing systems that support HiDPI displays use special points to specify
71             size of the windows and controls, so that windows and controls with hardcoded
72             sizes does not become too small on HiDPI displays. Such points have constant density
73             ~ 100 points per inch (probably 96 on Windows and 72 on Mac), that is independent
74             of pixel density of real display, and are used through the all windowing system.
75 
76             Sometimes, such view points are choosen bigger for output devices that are viewed
77             from larger distances, like 30" TV comparing to 30" monitor, therefore maintaining
78             constant points angular density rather than constant linear density.
79 
80             In any case, all such windowing system provides the way to convert such view points
81             to pixels, be it DisplayProperties::LogicalDpi on WinRT or backingScaleFactor on MacOSX.
82             We use pixels consistently through the Ogre, but window/view management functions
83             takes view points for convenience, as does the rest of windowing system. Such parameters
84             are named using xxxxPt pattern, and should not be mixed with pixels without being
85             converted using getViewPointToPixelScale() function.
86 
87             Sometimes such scale factor can change on-the-fly, for example if window is dragged
88             to monitor with different DPI. In such situation, window size in view points is usually
89             preserved by windowing system, and Ogre should adjust pixel size of RenderWindow.
90         */
getViewPointToPixelScale()91         virtual float getViewPointToPixelScale() { return 1.0f; }
92 
93         /** Creates & displays the new window.
94             @param
95                 widthPt The width of the window in view points.
96             @param
97                 heightPt The height of the window in view points.
98             @param
99                 fullScreen If true, the window fills the screen,
100                 with no title bar or border.
101             @param
102                 miscParams A variable number of pointers to platform-specific arguments. The
103                 actual requirements must be defined by the implementing subclasses.
104         */
105         virtual void create(const String& name, unsigned int widthPt, unsigned int heightPt,
106                 bool fullScreen, const NameValuePairList *miscParams) = 0;
107 
108         /** Alter fullscreen mode options.
109         @note Nothing will happen unless the settings here are different from the
110             current settings.
111         @param fullScreen Whether to use fullscreen mode or not.
112         @param widthPt The new width to use
113         @param heightPt The new height to use
114         */
setFullscreen(bool fullScreen,unsigned int widthPt,unsigned int heightPt)115         virtual void setFullscreen(bool fullScreen, unsigned int widthPt, unsigned int heightPt)
116                 { (void)fullScreen; (void)widthPt; (void)heightPt; }
117 
118         /** Destroys the window.
119         */
120         virtual void destroy(void) = 0;
121 
122         /** Alter the size of the window.
123         */
124         virtual void resize(unsigned int widthPt, unsigned int heightPt) = 0;
125 
126         /** Notify that the window has been resized
127         @remarks
128             You don't need to call this unless you created the window externally.
129         */
windowMovedOrResized()130         virtual void windowMovedOrResized() {}
131 
132         /** Reposition the window.
133         */
134         virtual void reposition(int leftPt, int topPt) = 0;
135 
136         /** Indicates whether the window is visible (not minimized or obscured)
137         */
isVisible(void)138         virtual bool isVisible(void) const { return true; }
139 
140         /** Set the visibility state
141         */
setVisible(bool visible)142         virtual void setVisible(bool visible)
143         { (void)visible; }
144 
145         /** Indicates whether the window was set to hidden (not displayed)
146         */
isHidden(void)147         virtual bool isHidden(void) const { return false; }
148 
149         /** Hide (or show) the window. If called with hidden=true, this
150             will make the window completely invisible to the user.
151         @remarks
152             Setting a window to hidden is useful to create a dummy primary
153             RenderWindow hidden from the user so that you can create and
154             recreate your actual RenderWindows without having to recreate
155             all your resources.
156         */
setHidden(bool hidden)157         virtual void setHidden(bool hidden)
158         { (void)hidden; }
159 
160         /** Enable or disable vertical sync for the RenderWindow.
161         */
setVSyncEnabled(bool vsync)162         virtual void setVSyncEnabled(bool vsync)
163         { (void)vsync; }
164 
165         /** Indicates whether vertical sync is activated for the window.
166         */
isVSyncEnabled()167         virtual bool isVSyncEnabled() const { return false; }
168 
169         /** Set the vertical sync interval. This indicates the number of vertical retraces to wait for
170             before swapping buffers. A value of 1 is the default.
171         */
setVSyncInterval(unsigned int interval)172         virtual void setVSyncInterval(unsigned int interval)
173         { (void)interval; }
174 
175         /** Returns the vertical sync interval.
176         */
getVSyncInterval()177         virtual unsigned int getVSyncInterval() const { return 1; }
178 
179 
180         /** Overridden from RenderTarget, flags invisible windows as inactive
181         */
isActive(void)182         virtual bool isActive(void) const { return mActive && isVisible(); }
183 
184         /** Indicates whether the window has been closed by the user.
185         */
186         virtual bool isClosed(void) const = 0;
187 
188         /** Indicates whether the window is the primary window. The
189             primary window is special in that it is destroyed when
190             ogre is shut down, and cannot be destroyed directly.
191             This is the case because it holds the context for vertex,
192             index buffers and textures.
193         */
194         virtual bool isPrimary(void) const;
195 
196         /** Returns true if window is running in fullscreen mode.
197         */
198         virtual bool isFullScreen(void) const;
199 
200         /** Overloaded version of getMetrics from RenderTarget, including extra details
201             specific to windowing systems. Result is in pixels.
202         */
203         virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth,
204             int& left, int& top) const;
205 
206         /// @copydoc RenderTarget::getMetrics
207         using RenderTarget::getMetrics;
208 
209         /// Override since windows don't usually have alpha
suggestPixelFormat()210         PixelFormat suggestPixelFormat() const { return PF_BYTE_RGB; }
211 
212         /** Returns true if the window will automatically de-activate itself when it loses focus.
213         */
214         bool isDeactivatedOnFocusChange() const;
215 
216         /** Indicates whether the window will automatically deactivate itself when it loses focus.
217           * @param deactivate a value of 'true' will cause the window to deactivate itself when it loses focus.  'false' will allow it to continue to render even when window focus is lost.
218           * @note 'true' is the default behavior.
219           */
220         void setDeactivateOnFocusChange(bool deactivate);
221 
222 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN
223         virtual void _notifySurfaceDestroyed() = 0;
224         virtual void _notifySurfaceCreated(void* nativeWindow, void* config = NULL) = 0;
225 #endif
226 
227     protected:
228         bool mIsFullScreen;
229         bool mIsPrimary;
230         bool mAutoDeactivatedOnFocusChange;
231         int mLeft;
232         int mTop;
233 
234         /** Indicates that this is the primary window. Only to be called by
235             Ogre::Root
236         */
_setPrimary()237         void _setPrimary() { mIsPrimary = true; }
238 
239         friend class Root;
240     };
241     /** @} */
242     /** @} */
243 
244 } // Namespace
245 #endif
246