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