Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreOverlay.h @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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