Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/Overlay/OgreOverlay.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 11.6 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __Overlay_H__
30#define __Overlay_H__
31
32#include "OgreOverlayPrerequisites.h"
33#include "OgreSceneNode.h"
34#include "OgreIteratorWrappers.h"
35#include "OgreMatrix4.h"
36
37namespace Ogre {
38
39
40        /** \addtogroup Core
41        *  @{
42        */
43        /** \addtogroup Overlays
44        *  @{
45        */
46        /** Represents a layer which is rendered on top of the 'normal' scene contents.
47    @remarks
48        An overlay is a container for visual components (2D and 3D) which will be
49        rendered after the main scene in order to composite heads-up-displays, menus
50        or other layers on top of the contents of the scene.
51    @par
52        An overlay always takes up the entire size of the viewport, although the
53        components attached to it do not have to. An overlay has no visual element
54        in itself, it it merely a container for visual elements.
55    @par
56        Overlays are created by calling OverlayManager::create, or by defining them
57        in special text scripts (.overlay files). As many overlays
58        as you like can be defined; after creation an overlay is hidden i.e. not
59        visible until you specifically enable it by calling 'show'. This allows you to have multiple
60        overlays predefined (menus etc) which you make visible only when you want.
61        It is possible to have multiple overlays enabled at once; in this case the
62        relative 'zorder' parameter of the overlays determine which one is displayed
63        on top.
64    @par
65        By default overlays are rendered into all viewports. This is fine when you only
66        have fullscreen viewports, but if you have picture-in-picture views, you probably
67        don't want the overlay displayed in the smaller viewports. You turn this off for
68        a specific viewport by calling the Viewport::setDisplayOverlays method.
69    */
70        class _OgreOverlayExport Overlay : public OverlayAlloc
71    {
72
73    public:
74              typedef list<OverlayContainer*>::type OverlayContainerList;
75    protected:
76        String mName;
77        /// Internal root node, used as parent for 3D objects
78        SceneNode* mRootNode;
79        /** 2D elements
80            OverlayContainers, linked list for easy sorting by zorder later
81            Not a map because sort can be saved since changes infrequent (unlike render queue) */
82        OverlayContainerList m2DElements;
83
84        /// Degrees of rotation around center
85        Radian mRotate;
86        /// Scroll values, offsets
87        Real mScrollX, mScrollY;
88        /// Scale values
89        Real mScaleX, mScaleY;
90
91        mutable Matrix4 mTransform;
92        mutable bool mTransformOutOfDate;
93        bool mTransformUpdated;
94        ulong mZOrder;
95        bool mVisible;
96                bool mInitialised;
97                String mOrigin;
98        /** Internal lazy update method. */
99        void updateTransform(void) const;
100                /** Internal method for initialising an overlay */
101                void initialise(void);
102                /** Internal method for updating container elements' Z-ordering */
103                void assignZOrders(void);
104
105    public:
106        /// Constructor: do not call direct, use OverlayManager::create
107        Overlay(const String& name);
108        virtual ~Overlay();
109
110
111            OverlayContainer* getChild(const String& name);
112
113        /** Gets the name of this overlay. */
114        const String& getName(void) const;
115       
116        /** Alters the Z-order of this overlay.
117        @remarks
118            Values between 0 and 650 are valid here.
119        */
120        void setZOrder(ushort zorder);
121        /** Gets the Z-order of this overlay. */
122        ushort getZOrder(void) const;
123
124        /** Gets whether the overlay is displayed or not. */
125        bool isVisible(void) const;
126
127                /** Gets whether the overlay is initialised or not. */
128                bool isInitialised(void) const { return mInitialised; }
129
130                /** Shows the overlay if it was hidden. */
131        void show(void);
132
133        /** Hides the overlay if it was visible. */
134        void hide(void);
135
136        /** Adds a 2D 'container' to the overlay.
137        @remarks
138            Containers are created and managed using the OverlayManager. A container
139            could be as simple as a square panel, or something more complex like
140            a grid or tree view. Containers group collections of other elements,
141            giving them a relative coordinate space and a common z-order.
142            If you want to attach a GUI widget to an overlay, you have to do it via
143            a container.
144        @param cont Pointer to a container to add, created using OverlayManager.
145        */
146        void add2D(OverlayContainer* cont);
147
148
149        /** Removes a 2D container from the overlay.
150        @remarks
151            NOT FAST. Consider OverlayElement::hide.
152        */
153        void remove2D(OverlayContainer* cont);
154
155        /** Adds a node capable of holding 3D objects to the overlay.
156        @remarks   
157            Although overlays are traditionally associated with 2D elements, there
158            are reasons why you might want to attach 3D elements to the overlay too.
159            For example, if you wanted to have a 3D cockpit, which was overlaid with a
160            HUD, then you would create 2 overlays, one with a 3D object attached for the
161            cockpit, and one with the HUD elements attached (the zorder of the HUD
162            overlay would be higher than the cockpit to ensure it was always on top).
163        @par   
164            A SceneNode can have any number of 3D objects attached to it. SceneNodes
165            are usually created using SceneManager::createSceneNode, but in this case
166                        you should create a standard SceneNode instance <b>manually</b>; this is
167                        because these scene nodes are not managed by the SceneManager and some custom
168                        SceneManager plugins will rely on specialist behaviour the overlay does not
169                        support. By attaching a SceneNode to an overlay, you indicate that:<OL>
170            <LI>You want the contents of this node to only appear when the overlay is active</LI>
171            <LI>You want the node to inherit a coordinate space relative to the camera,
172                rather than relative to the root scene node</LI>
173            <LI>You want these objects to be rendered after the contents of the main scene
174                to ensure they are rendered on top</LI>
175            </OL>
176            One major consideration when using 3D objects in overlays is the behaviour of
177            the depth buffer. Overlays should use materials with depth checking off, to ensure
178            that their contents are always displayed on top of the main scene (to do
179            otherwise would result in objects 'poking through' the overlay). The problem
180            with using 3D objects is that if they are concave, or self-overlap, then you
181            can get artefacts because of the lack of depth buffer checking. So you should
182            ensure that any 3D objects you us in the overlay are convex, and don't overlap
183            each other. If they must overlap, split them up and put them in 2 overlays.
184                        Alternatively, use a 2D element underneath them which will clear the depth buffer
185                        values underneath ready for the 3D element to be rendered correctly.
186        */
187        void add3D(SceneNode* node);
188
189        /** Removes a 3D element from the overlay. */
190        void remove3D(SceneNode* node);
191
192        /** Clears the overlay of all attached items. */
193        void clear();
194
195        /** Sets the scrolling factor of this overlay.
196        @remarks
197            You can use this to set an offset to be used to scroll an
198            overlay around the screen.
199        @param x Horizontal scroll value, where 0 = normal, -0.5 = scroll so that only
200            the right half the screen is visible etc
201        @param y Vertical scroll value, where 0 = normal, 0.5 = scroll down by half
202            a screen etc.
203        */
204        void setScroll(Real x, Real y);
205
206        /** Gets the current X scroll value */
207        Real getScrollX(void) const;
208
209        /** Gets the current Y scroll value */
210        Real getScrollY(void) const;
211
212        /** Scrolls the overlay by the offsets provided.
213        @remarks
214            This method moves the overlay by the amounts provided. As with
215            other methods on this object, a full screen width / height is represented
216            by the value 1.0.
217        */
218        void scroll(Real xoff, Real yoff);
219
220        /** Sets the rotation applied to this overlay.*/
221        void setRotate(const Radian& angle);
222
223        /** Gets the rotation applied to this overlay, in degrees.*/
224        const Radian &getRotate(void) const { return mRotate; }
225
226        /** Adds the passed in angle to the rotation applied to this overlay. */
227        void rotate(const Radian& angle);
228
229        /** Sets the scaling factor of this overlay.
230        @remarks
231            You can use this to set an scale factor to be used to zoom an
232            overlay.
233        @param x Horizontal scale value, where 1.0 = normal, 0.5 = half size etc
234        @param y Vertical scale value, where 1.0 = normal, 0.5 = half size etc
235        */
236        void setScale(Real x, Real y);
237
238        /** Gets the current X scale value */
239        Real getScaleX(void) const;
240
241        /** Gets the current Y scale value */
242        Real getScaleY(void) const;
243
244        /** Used to transform the overlay when scrolling, scaling etc. */
245        void _getWorldTransforms(Matrix4* xform) const;
246
247        /** Internal method to put the overlay contents onto the render queue. */
248        void _findVisibleObjects(Camera* cam, RenderQueue* queue);
249
250        /** This returns a OverlayElement at position x,y. */
251                virtual OverlayElement* findElementAt(Real x, Real y);
252
253        /** Returns an iterator over all 2D elements in this manager.
254        @remarks
255            VectorIterator is actually a too generic name, since it also works for lists.
256        */
257        typedef VectorIterator<OverlayContainerList> Overlay2DElementsIterator ;
258        Overlay2DElementsIterator get2DElementsIterator ()
259        {
260            return Overlay2DElementsIterator (m2DElements.begin(), m2DElements.end());
261        }
262                /** Get the origin of this overlay, e.g. a script file name.
263                @remarks
264                        This property will only contain something if the creator of
265                        this overlay chose to populate it. Script loaders are advised
266                        to populate it.
267                */
268                const String& getOrigin(void) const { return mOrigin; }
269                /// Notify this overlay of it's origin
270                void _notifyOrigin(const String& origin) { mOrigin = origin; }
271
272
273    };
274        /** @} */
275        /** @} */
276
277}
278
279
280#endif
281
Note: See TracBrowser for help on using the repository browser.