Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

=hoffentlich gehts jetzt

File size: 14.7 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-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 __BorderPanelOverlayElement_H__
31#define __BorderPanelOverlayElement_H__
32
33#include "OgrePanelOverlayElement.h"
34
35namespace Ogre {
36
37    class BorderRenderable;
38   
39    /** A specialisation of the PanelOverlayElement to provide a panel with a border.
40    @remarks
41        Whilst the standard panel can use a single tiled material, this class allows
42        panels with a tileable backdrop plus a border texture. This is handy for large
43        panels that are too big to use a single large texture with a border, or
44        for multiple different size panels where you want the border a constant width
45        but the center to repeat.
46    @par
47        In addition to the usual PanelOverlayElement properties, this class has a 'border
48        material', which specifies the material used for the edges of the panel,
49        a border width (which can either be constant all the way around, or specified
50        per edge), and the texture coordinates for each of the border sections.
51    */
52    class _OgreExport BorderPanelOverlayElement : public PanelOverlayElement
53    {
54        friend class BorderRenderable;
55    public:
56        /** Constructor */
57        BorderPanelOverlayElement(const String& name);
58        virtual ~BorderPanelOverlayElement();
59
60        virtual void initialise(void);
61
62                const String& getTypeName(void) const;
63        /** Sets the size of the border.
64        @remarks
65            This method sets a constant size for all borders. There are also alternative
66            methods which allow you to set border widths for individual edges separately.
67            Remember that the dimensions specified here are in relation to the size of
68            the screen, so 0.1 is 1/10th of the screen width or height. Also note that because
69            most screen resolutions are 1.333:1 width:height ratio that using the same
70            border size will look slightly bigger across than up.
71        @param size The size of the border as a factor of the screen dimensions ie 0.2 is one-fifth
72            of the screen size.
73        */
74        void setBorderSize(Real size);
75
76        /** Sets the size of the border, with different sizes for vertical and horizontal borders.
77        @remarks
78            This method sets a size for the side and top / bottom borders separately.
79            Remember that the dimensions specified here are in relation to the size of
80            the screen, so 0.1 is 1/10th of the screen width or height. Also note that because
81            most screen resolutions are 1.333:1 width:height ratio that using the same
82            border size will look slightly bigger across than up.
83        @param sides The size of the side borders as a factor of the screen dimensions ie 0.2 is one-fifth
84            of the screen size.
85        @param topAndBottom The size of the top and bottom borders as a factor of the screen dimensions.
86        */
87        void setBorderSize(Real sides, Real topAndBottom);
88
89        /** Sets the size of the border separately for all borders.
90        @remarks
91            This method sets a size all borders separately.
92            Remember that the dimensions specified here are in relation to the size of
93            the screen, so 0.1 is 1/10th of the screen width or height. Also note that because
94            most screen resolutions are 1.333:1 width:height ratio that using the same
95            border size will look slightly bigger across than up.
96        @param left The size of the left border as a factor of the screen dimensions ie 0.2 is one-fifth
97            of the screen size.
98        @param right The size of the left border as a factor of the screen dimensions.
99        @param top The size of the top border as a factor of the screen dimensions.
100        @param bottom The size of the bottom border as a factor of the screen dimensions.
101        */
102        void setBorderSize(Real left, Real right, Real top, Real bottom);
103
104        /** Gets the size of the left border. */
105        Real getLeftBorderSize(void) const;
106        /** Gets the size of the right border. */
107        Real getRightBorderSize(void) const;
108        /** Gets the size of the top border. */
109        Real getTopBorderSize(void) const;
110        /** Gets the size of the bottom border. */
111        Real getBottomBorderSize(void) const;
112
113        /** Sets the texture coordinates for the left edge of the border.
114        @remarks
115            The border panel uses 8 panels for the border (9 including the center).
116            Imagine a table with 3 rows and 3 columns. The corners are always the same size,
117            but the edges stretch depending on how big the panel is. Those who have done
118            resizable HTML tables will be familiar with this approach.
119        @par
120            We only require 2 sets of uv coordinates, one for the top-left and one for the
121            bottom-right of the panel, since it is assumed the sections are aligned on the texture.
122        */
123        void setLeftBorderUV(Real u1, Real v1, Real u2, Real v2);
124        /** Sets the texture coordinates for the right edge of the border.
125        @remarks See setLeftBorderUV.
126        */
127        void setRightBorderUV(Real u1, Real v1, Real u2, Real v2);
128        /** Sets the texture coordinates for the top edge of the border.
129        @remarks See setLeftBorderUV.
130        */
131        void setTopBorderUV(Real u1, Real v1, Real u2, Real v2);
132        /** Sets the texture coordinates for the bottom edge of the border.
133        @remarks See setLeftBorderUV.
134        */
135        void setBottomBorderUV(Real u1, Real v1, Real u2, Real v2);
136        /** Sets the texture coordinates for the top-left corner of the border.
137        @remarks See setLeftBorderUV.
138        */
139        void setTopLeftBorderUV(Real u1, Real v1, Real u2, Real v2);
140        /** Sets the texture coordinates for the top-right corner of the border.
141        @remarks See setLeftBorderUV.
142        */
143        void setTopRightBorderUV(Real u1, Real v1, Real u2, Real v2);
144        /** Sets the texture coordinates for the bottom-left corner of the border.
145        @remarks See setLeftBorderUV.
146        */
147        void setBottomLeftBorderUV(Real u1, Real v1, Real u2, Real v2);
148        /** Sets the texture coordinates for the bottom-right corner of the border.
149        @remarks See setLeftBorderUV.
150        */
151        void setBottomRightBorderUV(Real u1, Real v1, Real u2, Real v2);
152
153                String getLeftBorderUVString() const;
154                String getRightBorderUVString() const;
155                String getTopBorderUVString() const;
156                String getBottomBorderUVString() const;
157                String getTopLeftBorderUVString() const;
158                String getTopRightBorderUVString() const;
159                String getBottomLeftBorderUVString() const;
160                String getBottomRightBorderUVString() const;
161
162
163
164
165        /** Sets the name of the material to use for the borders. */
166        void setBorderMaterialName(const String& name);
167        /** Gets the name of the material to use for the borders. */
168        const String& getBorderMaterialName(void) const;
169
170        /** Overridden from OverlayContainer */
171        void _updateRenderQueue(RenderQueue* queue);
172
173        /** Overridden from OverlayElement */
174        void setMetricsMode(GuiMetricsMode gmm);
175
176        /** Overridden from OverlayElement */
177        void _update(void);
178
179
180        /** Command object for specifying border sizes (see ParamCommand).*/
181        class _OgrePrivate CmdBorderSize : public ParamCommand
182        {
183        public:
184            String doGet(const void* target) const;
185            void doSet(void* target, const String& val);
186        };
187        /** Command object for specifying the Material for the border (see ParamCommand).*/
188        class _OgrePrivate CmdBorderMaterial : public ParamCommand
189        {
190        public:
191            String doGet(const void* target) const;
192            void doSet(void* target, const String& val);
193        };
194        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
195        class _OgrePrivate CmdBorderLeftUV : public ParamCommand
196        {
197        public:
198            String doGet(const void* target) const;
199            void doSet(void* target, const String& val);
200        };
201        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
202        class _OgrePrivate CmdBorderTopUV : public ParamCommand
203        {
204        public:
205            String doGet(const void* target) const;
206            void doSet(void* target, const String& val);
207        };
208        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
209        class _OgrePrivate CmdBorderRightUV : public ParamCommand
210        {
211        public:
212            String doGet(const void* target) const;
213            void doSet(void* target, const String& val);
214        };
215        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
216        class _OgrePrivate CmdBorderBottomUV : public ParamCommand
217        {
218        public:
219            String doGet(const void* target) const;
220            void doSet(void* target, const String& val);
221        };
222        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
223        class _OgrePrivate CmdBorderTopLeftUV : public ParamCommand
224        {
225        public:
226            String doGet(const void* target) const;
227            void doSet(void* target, const String& val);
228        };
229        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
230        class _OgrePrivate CmdBorderBottomLeftUV : public ParamCommand
231        {
232        public:
233            String doGet(const void* target) const;
234            void doSet(void* target, const String& val);
235        };
236        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
237        class _OgrePrivate CmdBorderBottomRightUV : public ParamCommand
238        {
239        public:
240            String doGet(const void* target) const;
241            void doSet(void* target, const String& val);
242        };
243        /** Command object for specifying texture coordinates for the border (see ParamCommand).*/
244        class _OgrePrivate CmdBorderTopRightUV : public ParamCommand
245        {
246        public:
247            String doGet(const void* target) const;
248            void doSet(void* target, const String& val);
249        };
250    protected:
251        Real mLeftBorderSize;
252        Real mRightBorderSize;
253        Real mTopBorderSize;
254        Real mBottomBorderSize;
255                struct CellUV {
256                        Real u1, v1, u2, v2;
257                };
258                CellUV mBorderUV[8];
259
260        ushort mPixelLeftBorderSize;
261        ushort mPixelRightBorderSize;
262        ushort mPixelTopBorderSize;
263        ushort mPixelBottomBorderSize;
264
265        String mBorderMaterialName;
266        MaterialPtr mpBorderMaterial;
267
268        // Render operation for the border area
269        RenderOperation mRenderOp2;
270
271        static String msTypeName;
272
273        /// internal method for setting up geometry, called by OverlayElement::update
274        void updatePositionGeometry(void);
275                /// internal method for setting up geometry, called by OverlayElement::update
276                void updateTextureGeometry(void);
277        /// Internal method for setting up parameters
278        void addBaseParameters(void);
279
280        enum BorderCellIndex {
281            BCELL_TOP_LEFT = 0,
282            BCELL_TOP = 1,
283            BCELL_TOP_RIGHT = 2,
284            BCELL_LEFT = 3,
285            BCELL_RIGHT = 4,
286            BCELL_BOTTOM_LEFT = 5,
287            BCELL_BOTTOM = 6,
288            BCELL_BOTTOM_RIGHT = 7
289        };
290            String getCellUVString(BorderCellIndex idx) const;
291
292        // Command objects
293        static CmdBorderSize msCmdBorderSize;
294        static CmdBorderMaterial msCmdBorderMaterial;
295        static CmdBorderLeftUV msCmdBorderLeftUV;
296        static CmdBorderTopUV msCmdBorderTopUV;
297        static CmdBorderBottomUV msCmdBorderBottomUV;
298        static CmdBorderRightUV msCmdBorderRightUV;
299        static CmdBorderTopLeftUV msCmdBorderTopLeftUV;
300        static CmdBorderBottomLeftUV msCmdBorderBottomLeftUV;
301        static CmdBorderTopRightUV msCmdBorderTopRightUV;
302        static CmdBorderBottomRightUV msCmdBorderBottomRightUV;
303
304        BorderRenderable* mBorderRenderable;
305    };
306
307    /** Class for rendering the border of a BorderPanelOverlayElement.
308    @remarks
309        We need this because we have to render twice, once with the inner panel's repeating
310        material (handled by superclass) and once for the border's separate meterial.
311    */
312    class _OgreExport BorderRenderable : public Renderable
313    {
314    protected:
315        BorderPanelOverlayElement* mParent;
316    public:
317        /** Constructed with pointers to parent. */
318        BorderRenderable(BorderPanelOverlayElement* parent) : mParent(parent)
319        {
320            mUseIdentityProjection = true;
321            mUseIdentityView = true;
322        }
323        const MaterialPtr& getMaterial(void) const { return mParent->mpBorderMaterial; }
324        void getRenderOperation(RenderOperation& op) { op = mParent->mRenderOp2; }
325        void getWorldTransforms(Matrix4* xform) const { mParent->getWorldTransforms(xform); }
326        const Quaternion& getWorldOrientation(void) const { return Quaternion::IDENTITY; }
327        const Vector3& getWorldPosition(void) const { return Vector3::ZERO; }
328        unsigned short getNumWorldTransforms(void) const { return 1; }
329        Real getSquaredViewDepth(const Camera* cam) const { return mParent->getSquaredViewDepth(cam); }
330        const LightList& getLights(void) const
331        {
332            // N/A, panels are not lit
333            static LightList ll;
334            return ll;
335        }
336                bool getPolygonModeOverrideable(void) const
337                {
338                        return mParent->getPolygonModeOverrideable();
339                }
340    };
341
342}
343
344#endif
Note: See TracBrowser for help on using the repository browser.