Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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