[1] | 1 | |
---|
| 2 | /* |
---|
| 3 | ----------------------------------------------------------------------------- |
---|
| 4 | This source file is part of OGRE |
---|
| 5 | (Object-oriented Graphics Rendering Engine) |
---|
| 6 | For the latest info, see http://www.ogre3d.org/ |
---|
| 7 | |
---|
| 8 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 9 | Also see acknowledgements in Readme.html |
---|
| 10 | |
---|
| 11 | This program is free software you can redistribute it and/or modify it under |
---|
| 12 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 13 | Foundation either version 2 of the License, or (at your option) any later |
---|
| 14 | version. |
---|
| 15 | |
---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 17 | ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 21 | this program if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 23 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 24 | |
---|
| 25 | You may alternatively use this source under the terms of a specific version of |
---|
| 26 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 27 | Torus Knot Software Ltd. |
---|
| 28 | ----------------------------------------------------------------------------- |
---|
| 29 | */ |
---|
| 30 | #include "OgreStableHeaders.h" |
---|
| 31 | |
---|
| 32 | #include "OgreRoot.h" |
---|
| 33 | #include "OgreRenderSystem.h" |
---|
| 34 | #include "OgreOverlayElement.h" |
---|
| 35 | #include "OgreMaterialManager.h" |
---|
| 36 | #include "OgreOverlay.h" |
---|
| 37 | #include "OgreOverlayContainer.h" |
---|
| 38 | #include "OgreOverlayManager.h" |
---|
| 39 | #include "OgreException.h" |
---|
| 40 | #include "OgreRenderQueue.h" |
---|
| 41 | |
---|
| 42 | namespace Ogre { |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | //--------------------------------------------------------------------- |
---|
| 46 | // Define static members |
---|
| 47 | OverlayElementCommands::CmdLeft OverlayElement::msLeftCmd; |
---|
| 48 | OverlayElementCommands::CmdTop OverlayElement::msTopCmd; |
---|
| 49 | OverlayElementCommands::CmdWidth OverlayElement::msWidthCmd; |
---|
| 50 | OverlayElementCommands::CmdHeight OverlayElement::msHeightCmd; |
---|
| 51 | OverlayElementCommands::CmdMaterial OverlayElement::msMaterialCmd; |
---|
| 52 | OverlayElementCommands::CmdCaption OverlayElement::msCaptionCmd; |
---|
| 53 | OverlayElementCommands::CmdMetricsMode OverlayElement::msMetricsModeCmd; |
---|
| 54 | OverlayElementCommands::CmdHorizontalAlign OverlayElement::msHorizontalAlignCmd; |
---|
| 55 | OverlayElementCommands::CmdVerticalAlign OverlayElement::msVerticalAlignCmd; |
---|
| 56 | OverlayElementCommands::CmdVisible OverlayElement::msVisibleCmd; |
---|
| 57 | //--------------------------------------------------------------------- |
---|
| 58 | OverlayElement::OverlayElement(const String& name) |
---|
| 59 | : mName(name) |
---|
| 60 | , mVisible(true) |
---|
| 61 | , mCloneable(true) |
---|
| 62 | , mLeft(0.0f) |
---|
| 63 | , mTop(0.0f) |
---|
| 64 | , mWidth(1.0f) |
---|
| 65 | , mHeight(1.0f) |
---|
| 66 | , mMetricsMode(GMM_RELATIVE) |
---|
| 67 | , mHorzAlign(GHA_LEFT) |
---|
| 68 | , mVertAlign(GVA_TOP) |
---|
| 69 | , mPixelTop(0.0) |
---|
| 70 | , mPixelLeft(0.0) |
---|
| 71 | , mPixelWidth(1.0) |
---|
| 72 | , mPixelHeight(1.0) |
---|
| 73 | , mPixelScaleX(1.0) |
---|
| 74 | , mPixelScaleY(1.0) |
---|
| 75 | , mParent(0) |
---|
| 76 | , mOverlay(0) |
---|
| 77 | , mDerivedOutOfDate(true) |
---|
| 78 | , mGeomPositionsOutOfDate(true) |
---|
| 79 | , mGeomUVsOutOfDate(true) |
---|
| 80 | , mZOrder(0) |
---|
| 81 | , mEnabled(true) |
---|
| 82 | , mInitialised(false) |
---|
| 83 | , mSourceTemplate(0) |
---|
| 84 | { |
---|
| 85 | // default overlays to preserve their own detail level |
---|
| 86 | mPolygonModeOverrideable = false; |
---|
| 87 | |
---|
| 88 | // use identity projection and view matrices |
---|
| 89 | mUseIdentityProjection = true; |
---|
| 90 | mUseIdentityView = true; |
---|
| 91 | } |
---|
| 92 | //--------------------------------------------------------------------- |
---|
| 93 | OverlayElement::~OverlayElement() |
---|
| 94 | { |
---|
| 95 | if (mParent) |
---|
| 96 | { |
---|
| 97 | mParent->removeChild(mName); |
---|
| 98 | mParent = 0; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | //--------------------------------------------------------------------- |
---|
| 102 | const String& OverlayElement::getName(void) const |
---|
| 103 | { |
---|
| 104 | return mName; |
---|
| 105 | } |
---|
| 106 | //--------------------------------------------------------------------- |
---|
| 107 | void OverlayElement::show(void) |
---|
| 108 | { |
---|
| 109 | mVisible = true; |
---|
| 110 | } |
---|
| 111 | //--------------------------------------------------------------------- |
---|
| 112 | void OverlayElement::hide(void) |
---|
| 113 | { |
---|
| 114 | mVisible = false; |
---|
| 115 | } |
---|
| 116 | //--------------------------------------------------------------------- |
---|
| 117 | bool OverlayElement::isVisible(void) const |
---|
| 118 | { |
---|
| 119 | return mVisible; |
---|
| 120 | } |
---|
| 121 | //--------------------------------------------------------------------- |
---|
| 122 | void OverlayElement::setDimensions(Real width, Real height) |
---|
| 123 | { |
---|
| 124 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 125 | { |
---|
| 126 | mPixelWidth = width; |
---|
| 127 | mPixelHeight = height; |
---|
| 128 | } |
---|
| 129 | else |
---|
| 130 | { |
---|
| 131 | mWidth = width; |
---|
| 132 | mHeight = height; |
---|
| 133 | } |
---|
| 134 | mDerivedOutOfDate = true; |
---|
| 135 | _positionsOutOfDate(); |
---|
| 136 | } |
---|
| 137 | //--------------------------------------------------------------------- |
---|
| 138 | void OverlayElement::setPosition(Real left, Real top) |
---|
| 139 | { |
---|
| 140 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 141 | { |
---|
| 142 | mPixelLeft = left; |
---|
| 143 | mPixelTop = top; |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | mLeft = left; |
---|
| 148 | mTop = top; |
---|
| 149 | } |
---|
| 150 | mDerivedOutOfDate = true; |
---|
| 151 | _positionsOutOfDate(); |
---|
| 152 | |
---|
| 153 | } |
---|
| 154 | //--------------------------------------------------------------------- |
---|
| 155 | void OverlayElement::setWidth(Real width) |
---|
| 156 | { |
---|
| 157 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 158 | { |
---|
| 159 | mPixelWidth = width; |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | mWidth = width; |
---|
| 164 | } |
---|
| 165 | mDerivedOutOfDate = true; |
---|
| 166 | _positionsOutOfDate(); |
---|
| 167 | } |
---|
| 168 | //--------------------------------------------------------------------- |
---|
| 169 | Real OverlayElement::getWidth(void) const |
---|
| 170 | { |
---|
| 171 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 172 | { |
---|
| 173 | return mPixelWidth; |
---|
| 174 | } |
---|
| 175 | else |
---|
| 176 | { |
---|
| 177 | return mWidth; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | //--------------------------------------------------------------------- |
---|
| 181 | void OverlayElement::setHeight(Real height) |
---|
| 182 | { |
---|
| 183 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 184 | { |
---|
| 185 | mPixelHeight = height; |
---|
| 186 | } |
---|
| 187 | else |
---|
| 188 | { |
---|
| 189 | mHeight = height; |
---|
| 190 | } |
---|
| 191 | mDerivedOutOfDate = true; |
---|
| 192 | _positionsOutOfDate(); |
---|
| 193 | } |
---|
| 194 | //--------------------------------------------------------------------- |
---|
| 195 | Real OverlayElement::getHeight(void) const |
---|
| 196 | { |
---|
| 197 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 198 | { |
---|
| 199 | return mPixelHeight; |
---|
| 200 | } |
---|
| 201 | else |
---|
| 202 | { |
---|
| 203 | return mHeight; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | //--------------------------------------------------------------------- |
---|
| 207 | void OverlayElement::setLeft(Real left) |
---|
| 208 | { |
---|
| 209 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 210 | { |
---|
| 211 | mPixelLeft = left; |
---|
| 212 | } |
---|
| 213 | else |
---|
| 214 | { |
---|
| 215 | mLeft = left; |
---|
| 216 | } |
---|
| 217 | mDerivedOutOfDate = true; |
---|
| 218 | _positionsOutOfDate(); |
---|
| 219 | } |
---|
| 220 | //--------------------------------------------------------------------- |
---|
| 221 | Real OverlayElement::getLeft(void) const |
---|
| 222 | { |
---|
| 223 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 224 | { |
---|
| 225 | return mPixelLeft; |
---|
| 226 | } |
---|
| 227 | else |
---|
| 228 | { |
---|
| 229 | return mLeft; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | //--------------------------------------------------------------------- |
---|
| 233 | void OverlayElement::setTop(Real top) |
---|
| 234 | { |
---|
| 235 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 236 | { |
---|
| 237 | mPixelTop = top; |
---|
| 238 | } |
---|
| 239 | else |
---|
| 240 | { |
---|
| 241 | mTop = top; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | mDerivedOutOfDate = true; |
---|
| 245 | _positionsOutOfDate(); |
---|
| 246 | } |
---|
| 247 | //--------------------------------------------------------------------- |
---|
| 248 | Real OverlayElement::getTop(void) const |
---|
| 249 | { |
---|
| 250 | if (mMetricsMode != GMM_RELATIVE) |
---|
| 251 | { |
---|
| 252 | return mPixelTop; |
---|
| 253 | } |
---|
| 254 | else |
---|
| 255 | { |
---|
| 256 | return mTop; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | //--------------------------------------------------------------------- |
---|
| 260 | void OverlayElement::_setLeft(Real left) |
---|
| 261 | { |
---|
| 262 | mLeft = left; |
---|
| 263 | mPixelLeft = left / mPixelScaleX; |
---|
| 264 | |
---|
| 265 | mDerivedOutOfDate = true; |
---|
| 266 | _positionsOutOfDate(); |
---|
| 267 | } |
---|
| 268 | //--------------------------------------------------------------------- |
---|
| 269 | void OverlayElement::_setTop(Real top) |
---|
| 270 | { |
---|
| 271 | mTop = top; |
---|
| 272 | mPixelTop = top / mPixelScaleY; |
---|
| 273 | |
---|
| 274 | mDerivedOutOfDate = true; |
---|
| 275 | _positionsOutOfDate(); |
---|
| 276 | } |
---|
| 277 | //--------------------------------------------------------------------- |
---|
| 278 | void OverlayElement::_setWidth(Real width) |
---|
| 279 | { |
---|
| 280 | mWidth = width; |
---|
| 281 | mPixelWidth = width / mPixelScaleX; |
---|
| 282 | |
---|
| 283 | mDerivedOutOfDate = true; |
---|
| 284 | _positionsOutOfDate(); |
---|
| 285 | } |
---|
| 286 | //--------------------------------------------------------------------- |
---|
| 287 | void OverlayElement::_setHeight(Real height) |
---|
| 288 | { |
---|
| 289 | mHeight = height; |
---|
| 290 | mPixelHeight = height / mPixelScaleY; |
---|
| 291 | |
---|
| 292 | mDerivedOutOfDate = true; |
---|
| 293 | _positionsOutOfDate(); |
---|
| 294 | } |
---|
| 295 | //--------------------------------------------------------------------- |
---|
| 296 | void OverlayElement::_setPosition(Real left, Real top) |
---|
| 297 | { |
---|
| 298 | mLeft = left; |
---|
| 299 | mTop = top; |
---|
| 300 | mPixelLeft = left / mPixelScaleX; |
---|
| 301 | mPixelTop = top / mPixelScaleY; |
---|
| 302 | |
---|
| 303 | mDerivedOutOfDate = true; |
---|
| 304 | _positionsOutOfDate(); |
---|
| 305 | } |
---|
| 306 | //--------------------------------------------------------------------- |
---|
| 307 | void OverlayElement::_setDimensions(Real width, Real height) |
---|
| 308 | { |
---|
| 309 | mWidth = width; |
---|
| 310 | mHeight = height; |
---|
| 311 | mPixelWidth = width / mPixelScaleX; |
---|
| 312 | mPixelHeight = height / mPixelScaleY; |
---|
| 313 | |
---|
| 314 | mDerivedOutOfDate = true; |
---|
| 315 | _positionsOutOfDate(); |
---|
| 316 | } |
---|
| 317 | //--------------------------------------------------------------------- |
---|
| 318 | const String& OverlayElement::getMaterialName(void) const |
---|
| 319 | { |
---|
| 320 | return mMaterialName; |
---|
| 321 | |
---|
| 322 | } |
---|
| 323 | //--------------------------------------------------------------------- |
---|
| 324 | void OverlayElement::setMaterialName(const String& matName) |
---|
| 325 | { |
---|
| 326 | mMaterialName = matName; |
---|
| 327 | mpMaterial = MaterialManager::getSingleton().getByName(matName); |
---|
| 328 | if (mpMaterial.isNull()) |
---|
| 329 | OGRE_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "Could not find material " + matName, |
---|
| 330 | "OverlayElement::setMaterialName" ); |
---|
| 331 | mpMaterial->load(); |
---|
| 332 | // Set some prerequisites to be sure |
---|
| 333 | mpMaterial->setLightingEnabled(false); |
---|
| 334 | mpMaterial->setDepthCheckEnabled(false); |
---|
| 335 | |
---|
| 336 | } |
---|
| 337 | //--------------------------------------------------------------------- |
---|
| 338 | const MaterialPtr& OverlayElement::getMaterial(void) const |
---|
| 339 | { |
---|
| 340 | return mpMaterial; |
---|
| 341 | } |
---|
| 342 | //--------------------------------------------------------------------- |
---|
| 343 | void OverlayElement::getWorldTransforms(Matrix4* xform) const |
---|
| 344 | { |
---|
| 345 | mOverlay->_getWorldTransforms(xform); |
---|
| 346 | } |
---|
| 347 | //----------------------------------------------------------------------- |
---|
| 348 | const Quaternion& OverlayElement::getWorldOrientation(void) const |
---|
| 349 | { |
---|
| 350 | return mOverlay->getWorldOrientation(); |
---|
| 351 | } |
---|
| 352 | //----------------------------------------------------------------------- |
---|
| 353 | const Vector3& OverlayElement::getWorldPosition(void) const |
---|
| 354 | { |
---|
| 355 | return mOverlay->getWorldPosition(); |
---|
| 356 | } |
---|
| 357 | //--------------------------------------------------------------------- |
---|
| 358 | void OverlayElement::_positionsOutOfDate(void) |
---|
| 359 | { |
---|
| 360 | mGeomPositionsOutOfDate = true; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | //--------------------------------------------------------------------- |
---|
| 364 | void OverlayElement::_update(void) |
---|
| 365 | { |
---|
| 366 | // Check size if pixel-based |
---|
| 367 | switch (mMetricsMode) |
---|
| 368 | { |
---|
| 369 | case GMM_PIXELS : |
---|
| 370 | if (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate) |
---|
| 371 | { |
---|
| 372 | Real vpWidth, vpHeight; |
---|
| 373 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 374 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 375 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 376 | |
---|
| 377 | mPixelScaleX = 1.0 / vpWidth; |
---|
| 378 | mPixelScaleY = 1.0 / vpHeight; |
---|
| 379 | |
---|
| 380 | mLeft = mPixelLeft * mPixelScaleX; |
---|
| 381 | mTop = mPixelTop * mPixelScaleY; |
---|
| 382 | mWidth = mPixelWidth * mPixelScaleX; |
---|
| 383 | mHeight = mPixelHeight * mPixelScaleY; |
---|
| 384 | } |
---|
| 385 | break; |
---|
| 386 | |
---|
| 387 | case GMM_RELATIVE_ASPECT_ADJUSTED : |
---|
| 388 | if (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate) |
---|
| 389 | { |
---|
| 390 | Real vpWidth, vpHeight; |
---|
| 391 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 392 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 393 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 394 | |
---|
| 395 | mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight)); |
---|
| 396 | mPixelScaleY = 1.0 / 10000.0; |
---|
| 397 | |
---|
| 398 | mLeft = mPixelLeft * mPixelScaleX; |
---|
| 399 | mTop = mPixelTop * mPixelScaleY; |
---|
| 400 | mWidth = mPixelWidth * mPixelScaleX; |
---|
| 401 | mHeight = mPixelHeight * mPixelScaleY; |
---|
| 402 | } |
---|
| 403 | break; |
---|
| 404 | default: |
---|
| 405 | break; |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | _updateFromParent(); |
---|
| 409 | // NB container subclasses will update children too |
---|
| 410 | |
---|
| 411 | // Tell self to update own position geometry |
---|
| 412 | if (mGeomPositionsOutOfDate && mInitialised) |
---|
| 413 | { |
---|
| 414 | updatePositionGeometry(); |
---|
| 415 | mGeomPositionsOutOfDate = false; |
---|
| 416 | } |
---|
| 417 | // Tell self to update own texture geometry |
---|
| 418 | if (mGeomUVsOutOfDate && mInitialised) |
---|
| 419 | { |
---|
| 420 | updateTextureGeometry(); |
---|
| 421 | mGeomUVsOutOfDate = false; |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | //--------------------------------------------------------------------- |
---|
| 425 | void OverlayElement::_updateFromParent(void) |
---|
| 426 | { |
---|
| 427 | Real parentLeft, parentTop, parentBottom, parentRight; |
---|
| 428 | |
---|
| 429 | if (mParent) |
---|
| 430 | { |
---|
| 431 | parentLeft = mParent->_getDerivedLeft(); |
---|
| 432 | parentTop = mParent->_getDerivedTop(); |
---|
| 433 | if (mHorzAlign == GHA_CENTER || mHorzAlign == GHA_RIGHT) |
---|
| 434 | { |
---|
| 435 | parentRight = parentLeft + mParent->_getRelativeWidth(); |
---|
| 436 | } |
---|
| 437 | if (mVertAlign == GVA_CENTER || mVertAlign == GVA_BOTTOM) |
---|
| 438 | { |
---|
| 439 | parentBottom = parentTop + mParent->_getRelativeHeight(); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | } |
---|
| 443 | else |
---|
| 444 | { |
---|
| 445 | RenderSystem* rSys = Root::getSingleton().getRenderSystem(); |
---|
| 446 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 447 | |
---|
| 448 | // Calculate offsets required for mapping texel origins to pixel origins in the |
---|
| 449 | // current rendersystem |
---|
| 450 | Real hOffset = rSys->getHorizontalTexelOffset() / oMgr.getViewportWidth(); |
---|
| 451 | Real vOffset = rSys->getVerticalTexelOffset() / oMgr.getViewportHeight(); |
---|
| 452 | |
---|
| 453 | parentLeft = 0.0f + hOffset; |
---|
| 454 | parentTop = 0.0f + vOffset; |
---|
| 455 | parentRight = 1.0f + hOffset; |
---|
| 456 | parentBottom = 1.0f + vOffset; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | // Sort out position based on alignment |
---|
| 460 | // NB all we do is derived the origin, we don't automatically sort out the position |
---|
| 461 | // This is more flexible than forcing absolute right & middle |
---|
| 462 | switch(mHorzAlign) |
---|
| 463 | { |
---|
| 464 | case GHA_CENTER: |
---|
| 465 | mDerivedLeft = ((parentLeft + parentRight) * 0.5f) + mLeft; |
---|
| 466 | break; |
---|
| 467 | case GHA_LEFT: |
---|
| 468 | mDerivedLeft = parentLeft + mLeft; |
---|
| 469 | break; |
---|
| 470 | case GHA_RIGHT: |
---|
| 471 | mDerivedLeft = parentRight + mLeft; |
---|
| 472 | break; |
---|
| 473 | }; |
---|
| 474 | switch(mVertAlign) |
---|
| 475 | { |
---|
| 476 | case GVA_CENTER: |
---|
| 477 | mDerivedTop = ((parentTop + parentBottom) * 0.5f) + mTop; |
---|
| 478 | break; |
---|
| 479 | case GVA_TOP: |
---|
| 480 | mDerivedTop = parentTop + mTop; |
---|
| 481 | break; |
---|
| 482 | case GVA_BOTTOM: |
---|
| 483 | mDerivedTop = parentBottom + mTop; |
---|
| 484 | break; |
---|
| 485 | }; |
---|
| 486 | |
---|
| 487 | mDerivedOutOfDate = false; |
---|
| 488 | |
---|
| 489 | if (mParent != 0) |
---|
| 490 | { |
---|
| 491 | Rectangle parent; |
---|
| 492 | Rectangle child; |
---|
| 493 | |
---|
| 494 | mParent->_getClippingRegion(parent); |
---|
| 495 | |
---|
| 496 | child.left = mDerivedLeft; |
---|
| 497 | child.top = mDerivedTop; |
---|
| 498 | child.right = mDerivedLeft + mWidth; |
---|
| 499 | child.bottom = mDerivedTop + mHeight; |
---|
| 500 | |
---|
| 501 | mClippingRegion = intersect(parent, child); |
---|
| 502 | } |
---|
| 503 | else |
---|
| 504 | { |
---|
| 505 | mClippingRegion.left = mDerivedLeft; |
---|
| 506 | mClippingRegion.top = mDerivedTop; |
---|
| 507 | mClippingRegion.right = mDerivedLeft + mWidth; |
---|
| 508 | mClippingRegion.bottom = mDerivedTop + mHeight; |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | //--------------------------------------------------------------------- |
---|
| 512 | void OverlayElement::_notifyParent(OverlayContainer* parent, Overlay* overlay) |
---|
| 513 | { |
---|
| 514 | mParent = parent; |
---|
| 515 | mOverlay = overlay; |
---|
| 516 | |
---|
| 517 | if (mOverlay && mOverlay->isInitialised() && !mInitialised) |
---|
| 518 | { |
---|
| 519 | initialise(); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | mDerivedOutOfDate = true; |
---|
| 523 | } |
---|
| 524 | //--------------------------------------------------------------------- |
---|
| 525 | Real OverlayElement::_getDerivedLeft(void) |
---|
| 526 | { |
---|
| 527 | if (mDerivedOutOfDate) |
---|
| 528 | { |
---|
| 529 | _updateFromParent(); |
---|
| 530 | } |
---|
| 531 | return mDerivedLeft; |
---|
| 532 | } |
---|
| 533 | //--------------------------------------------------------------------- |
---|
| 534 | Real OverlayElement::_getDerivedTop(void) |
---|
| 535 | { |
---|
| 536 | if (mDerivedOutOfDate) |
---|
| 537 | { |
---|
| 538 | _updateFromParent(); |
---|
| 539 | } |
---|
| 540 | return mDerivedTop; |
---|
| 541 | } |
---|
| 542 | //--------------------------------------------------------------------- |
---|
| 543 | Real OverlayElement::_getRelativeWidth(void) |
---|
| 544 | { |
---|
| 545 | return mWidth; |
---|
| 546 | } |
---|
| 547 | //--------------------------------------------------------------------- |
---|
| 548 | Real OverlayElement::_getRelativeHeight(void) |
---|
| 549 | { |
---|
| 550 | return mHeight; |
---|
| 551 | } |
---|
| 552 | //--------------------------------------------------------------------- |
---|
| 553 | void OverlayElement::_getClippingRegion(Rectangle &clippingRegion) |
---|
| 554 | { |
---|
| 555 | if (mDerivedOutOfDate) |
---|
| 556 | { |
---|
| 557 | _updateFromParent(); |
---|
| 558 | } |
---|
| 559 | clippingRegion = mClippingRegion; |
---|
| 560 | } |
---|
| 561 | //--------------------------------------------------------------------- |
---|
| 562 | void OverlayElement::_notifyZOrder(ushort newZOrder) |
---|
| 563 | { |
---|
| 564 | mZOrder = newZOrder; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | //--------------------------------------------------------------------- |
---|
| 568 | void OverlayElement::_notifyWorldTransforms(const Matrix4& xform) |
---|
| 569 | { |
---|
| 570 | mXForm = xform; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | //--------------------------------------------------------------------- |
---|
| 574 | void OverlayElement::_notifyViewport() |
---|
| 575 | { |
---|
| 576 | switch (mMetricsMode) |
---|
| 577 | { |
---|
| 578 | case GMM_PIXELS : |
---|
| 579 | { |
---|
| 580 | Real vpWidth, vpHeight; |
---|
| 581 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 582 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 583 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 584 | |
---|
| 585 | mPixelScaleX = 1.0 / vpWidth; |
---|
| 586 | mPixelScaleY = 1.0 / vpHeight; |
---|
| 587 | } |
---|
| 588 | break; |
---|
| 589 | |
---|
| 590 | case GMM_RELATIVE_ASPECT_ADJUSTED : |
---|
| 591 | { |
---|
| 592 | Real vpWidth, vpHeight; |
---|
| 593 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 594 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 595 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 596 | |
---|
| 597 | mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight)); |
---|
| 598 | mPixelScaleY = 1.0 / 10000.0; |
---|
| 599 | } |
---|
| 600 | break; |
---|
| 601 | |
---|
| 602 | case GMM_RELATIVE : |
---|
| 603 | mPixelScaleX = 1.0; |
---|
| 604 | mPixelScaleY = 1.0; |
---|
| 605 | mPixelLeft = mLeft; |
---|
| 606 | mPixelTop = mTop; |
---|
| 607 | mPixelWidth = mWidth; |
---|
| 608 | mPixelHeight = mHeight; |
---|
| 609 | break; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | mLeft = mPixelLeft * mPixelScaleX; |
---|
| 613 | mTop = mPixelTop * mPixelScaleY; |
---|
| 614 | mWidth = mPixelWidth * mPixelScaleX; |
---|
| 615 | mHeight = mPixelHeight * mPixelScaleY; |
---|
| 616 | |
---|
| 617 | mGeomPositionsOutOfDate = true; |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | //--------------------------------------------------------------------- |
---|
| 621 | void OverlayElement::_updateRenderQueue(RenderQueue* queue) |
---|
| 622 | { |
---|
| 623 | if (mVisible) |
---|
| 624 | { |
---|
| 625 | queue->addRenderable(this, RENDER_QUEUE_OVERLAY, mZOrder); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | } |
---|
| 629 | //----------------------------------------------------------------------- |
---|
| 630 | void OverlayElement::addBaseParameters(void) |
---|
| 631 | { |
---|
| 632 | ParamDictionary* dict = getParamDictionary(); |
---|
| 633 | |
---|
| 634 | dict->addParameter(ParameterDef("left", |
---|
| 635 | "The position of the left border of the gui element." |
---|
| 636 | , PT_REAL), |
---|
| 637 | &msLeftCmd); |
---|
| 638 | dict->addParameter(ParameterDef("top", |
---|
| 639 | "The position of the top border of the gui element." |
---|
| 640 | , PT_REAL), |
---|
| 641 | &msTopCmd); |
---|
| 642 | dict->addParameter(ParameterDef("width", |
---|
| 643 | "The width of the element." |
---|
| 644 | , PT_REAL), |
---|
| 645 | &msWidthCmd); |
---|
| 646 | dict->addParameter(ParameterDef("height", |
---|
| 647 | "The height of the element." |
---|
| 648 | , PT_REAL), |
---|
| 649 | &msHeightCmd); |
---|
| 650 | dict->addParameter(ParameterDef("material", |
---|
| 651 | "The name of the material to use." |
---|
| 652 | , PT_STRING), |
---|
| 653 | &msMaterialCmd); |
---|
| 654 | dict->addParameter(ParameterDef("caption", |
---|
| 655 | "The element caption, if supported." |
---|
| 656 | , PT_STRING), |
---|
| 657 | &msCaptionCmd); |
---|
| 658 | dict->addParameter(ParameterDef("metrics_mode", |
---|
| 659 | "The type of metrics to use, either 'relative' to the screen, 'pixels' or 'relative_aspect_adjusted'." |
---|
| 660 | , PT_STRING), |
---|
| 661 | &msMetricsModeCmd); |
---|
| 662 | dict->addParameter(ParameterDef("horz_align", |
---|
| 663 | "The horizontal alignment, 'left', 'right' or 'center'." |
---|
| 664 | , PT_STRING), |
---|
| 665 | &msHorizontalAlignCmd); |
---|
| 666 | dict->addParameter(ParameterDef("vert_align", |
---|
| 667 | "The vertical alignment, 'top', 'bottom' or 'center'." |
---|
| 668 | , PT_STRING), |
---|
| 669 | &msVerticalAlignCmd); |
---|
| 670 | dict->addParameter(ParameterDef("visible", |
---|
| 671 | "Initial visibility of element, either 'true' or 'false' (default true)." |
---|
| 672 | , PT_STRING), |
---|
| 673 | &msVisibleCmd); |
---|
| 674 | } |
---|
| 675 | //----------------------------------------------------------------------- |
---|
| 676 | void OverlayElement::setCaption( const DisplayString& caption ) |
---|
| 677 | { |
---|
| 678 | mCaption = caption; |
---|
| 679 | _positionsOutOfDate(); |
---|
| 680 | } |
---|
| 681 | //----------------------------------------------------------------------- |
---|
| 682 | const DisplayString& OverlayElement::getCaption() const |
---|
| 683 | { |
---|
| 684 | return mCaption; |
---|
| 685 | } |
---|
| 686 | //----------------------------------------------------------------------- |
---|
| 687 | void OverlayElement::setColour(const ColourValue& col) |
---|
| 688 | { |
---|
| 689 | mColour = col; |
---|
| 690 | } |
---|
| 691 | //----------------------------------------------------------------------- |
---|
| 692 | const ColourValue& OverlayElement::getColour(void) const |
---|
| 693 | { |
---|
| 694 | return mColour; |
---|
| 695 | } |
---|
| 696 | //----------------------------------------------------------------------- |
---|
| 697 | void OverlayElement::setMetricsMode(GuiMetricsMode gmm) |
---|
| 698 | { |
---|
| 699 | switch (gmm) |
---|
| 700 | { |
---|
| 701 | case GMM_PIXELS : |
---|
| 702 | { |
---|
| 703 | Real vpWidth, vpHeight; |
---|
| 704 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 705 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 706 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 707 | |
---|
| 708 | mPixelScaleX = 1.0 / vpWidth; |
---|
| 709 | mPixelScaleY = 1.0 / vpHeight; |
---|
| 710 | |
---|
| 711 | if (mMetricsMode == GMM_RELATIVE) |
---|
| 712 | { |
---|
| 713 | mPixelLeft = mLeft; |
---|
| 714 | mPixelTop = mTop; |
---|
| 715 | mPixelWidth = mWidth; |
---|
| 716 | mPixelHeight = mHeight; |
---|
| 717 | } |
---|
| 718 | } |
---|
| 719 | break; |
---|
| 720 | |
---|
| 721 | case GMM_RELATIVE_ASPECT_ADJUSTED : |
---|
| 722 | { |
---|
| 723 | Real vpWidth, vpHeight; |
---|
| 724 | OverlayManager& oMgr = OverlayManager::getSingleton(); |
---|
| 725 | vpWidth = (Real) (oMgr.getViewportWidth()); |
---|
| 726 | vpHeight = (Real) (oMgr.getViewportHeight()); |
---|
| 727 | |
---|
| 728 | mPixelScaleX = 1.0 / (10000.0 * (vpWidth / vpHeight)); |
---|
| 729 | mPixelScaleY = 1.0 / 10000.0; |
---|
| 730 | |
---|
| 731 | if (mMetricsMode == GMM_RELATIVE) |
---|
| 732 | { |
---|
| 733 | mPixelLeft = mLeft; |
---|
| 734 | mPixelTop = mTop; |
---|
| 735 | mPixelWidth = mWidth; |
---|
| 736 | mPixelHeight = mHeight; |
---|
| 737 | } |
---|
| 738 | } |
---|
| 739 | break; |
---|
| 740 | |
---|
| 741 | case GMM_RELATIVE : |
---|
| 742 | mPixelScaleX = 1.0; |
---|
| 743 | mPixelScaleY = 1.0; |
---|
| 744 | mPixelLeft = mLeft; |
---|
| 745 | mPixelTop = mTop; |
---|
| 746 | mPixelWidth = mWidth; |
---|
| 747 | mPixelHeight = mHeight; |
---|
| 748 | break; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | mLeft = mPixelLeft * mPixelScaleX; |
---|
| 752 | mTop = mPixelTop * mPixelScaleY; |
---|
| 753 | mWidth = mPixelWidth * mPixelScaleX; |
---|
| 754 | mHeight = mPixelHeight * mPixelScaleY; |
---|
| 755 | |
---|
| 756 | mMetricsMode = gmm; |
---|
| 757 | mDerivedOutOfDate = true; |
---|
| 758 | _positionsOutOfDate(); |
---|
| 759 | } |
---|
| 760 | //----------------------------------------------------------------------- |
---|
| 761 | GuiMetricsMode OverlayElement::getMetricsMode(void) const |
---|
| 762 | { |
---|
| 763 | return mMetricsMode; |
---|
| 764 | } |
---|
| 765 | //----------------------------------------------------------------------- |
---|
| 766 | void OverlayElement::setHorizontalAlignment(GuiHorizontalAlignment gha) |
---|
| 767 | { |
---|
| 768 | mHorzAlign = gha; |
---|
| 769 | _positionsOutOfDate(); |
---|
| 770 | } |
---|
| 771 | //----------------------------------------------------------------------- |
---|
| 772 | GuiHorizontalAlignment OverlayElement::getHorizontalAlignment(void) const |
---|
| 773 | { |
---|
| 774 | return mHorzAlign; |
---|
| 775 | } |
---|
| 776 | //----------------------------------------------------------------------- |
---|
| 777 | void OverlayElement::setVerticalAlignment(GuiVerticalAlignment gva) |
---|
| 778 | { |
---|
| 779 | mVertAlign = gva; |
---|
| 780 | _positionsOutOfDate(); |
---|
| 781 | } |
---|
| 782 | //----------------------------------------------------------------------- |
---|
| 783 | GuiVerticalAlignment OverlayElement::getVerticalAlignment(void) const |
---|
| 784 | { |
---|
| 785 | return mVertAlign; |
---|
| 786 | } |
---|
| 787 | //----------------------------------------------------------------------- |
---|
| 788 | |
---|
| 789 | |
---|
| 790 | //----------------------------------------------------------------------- |
---|
| 791 | bool OverlayElement::contains(Real x, Real y) const |
---|
| 792 | { |
---|
| 793 | return mClippingRegion.inside(x, y); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | //----------------------------------------------------------------------- |
---|
| 797 | OverlayElement* OverlayElement::findElementAt(Real x, Real y) // relative to parent |
---|
| 798 | { |
---|
| 799 | OverlayElement* ret = NULL; |
---|
| 800 | if (contains(x , y )) |
---|
| 801 | { |
---|
| 802 | ret = this; |
---|
| 803 | } |
---|
| 804 | return ret; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | //----------------------------------------------------------------------- |
---|
| 808 | OverlayContainer* OverlayElement::getParent() |
---|
| 809 | { |
---|
| 810 | return mParent; |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | void OverlayElement::copyFromTemplate(OverlayElement* templateOverlay) |
---|
| 814 | { |
---|
| 815 | templateOverlay->copyParametersTo(this); |
---|
| 816 | mSourceTemplate = templateOverlay ; |
---|
| 817 | return; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | OverlayElement* OverlayElement::clone(const String& instanceName) |
---|
| 821 | { |
---|
| 822 | OverlayElement* newElement; |
---|
| 823 | |
---|
| 824 | newElement = OverlayManager::getSingleton().createOverlayElement( |
---|
| 825 | getTypeName(), instanceName + "/" + mName); |
---|
| 826 | copyParametersTo(newElement); |
---|
| 827 | |
---|
| 828 | return newElement; |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | //----------------------------------------------------------------------- |
---|
| 832 | bool OverlayElement::isEnabled() const |
---|
| 833 | { |
---|
| 834 | return mEnabled; |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | //----------------------------------------------------------------------- |
---|
| 838 | void OverlayElement::setEnabled(bool b) |
---|
| 839 | { |
---|
| 840 | mEnabled = b; |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | |
---|
| 844 | } |
---|
| 845 | |
---|