guiBitmapBarCtrl.cpp
Engine/source/gui/controls/guiBitmapBarCtrl.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CONOBJECT(GuiBitmapBarCtrl )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gui/controls/guiBitmapBarCtrl.h" 26 27#include "console/console.h" 28#include "console/consoleTypes.h" 29#include "console/engineAPI.h" 30#include "gfx/gfxDevice.h" 31#include "gfx/gfxDrawUtil.h" 32 33 34 35IMPLEMENT_CONOBJECT(GuiBitmapBarCtrl); 36 37GuiBitmapBarCtrl::GuiBitmapBarCtrl(void) 38{ 39 mPercent = 100.0; 40 mVertical = false; 41 mFlipClip = false; 42} 43 44 45void GuiBitmapBarCtrl::initPersistFields() 46{ 47 addField("percent", TypeF32, Offset(mPercent, GuiBitmapBarCtrl), 48 "% shown"); 49 addField("vertical", TypeBool, Offset(mVertical, GuiBitmapBarCtrl), 50 "If true, the bitmap is clipped vertically."); 51 addField("flipClip", TypeBool, Offset(mFlipClip, GuiBitmapBarCtrl), 52 "If true, the bitmap is clipped in the oposite direction."); 53 Parent::initPersistFields(); 54 removeField("wrap"); 55} 56 57void GuiBitmapBarCtrl::onRender(Point2I offset, const RectI &updateRect) 58{ 59 if (mTextureObject) 60 { 61 GFX->getDrawUtil()->clearBitmapModulation(); 62 GFX->getDrawUtil()->setBitmapModulation(mColor); 63 F32 pct = (mPercent / 100.0); 64 GFXTextureObject* texture = mTextureObject; 65 Point2I modifiedSRC; 66 modifiedSRC.x = mVertical ? (F32)texture->mBitmapSize.x : (F32)(texture->mBitmapSize.x*pct); 67 modifiedSRC.y = mVertical ? (F32)(texture->mBitmapSize.y*pct) : (F32)texture->mBitmapSize.y; 68 RectI srcRegion; 69 Point2I offsetSRC = Point2I::Zero; 70 if (mFlipClip) 71 { 72 offsetSRC.x = texture->mBitmapSize.x - modifiedSRC.x; 73 offsetSRC.y = texture->mBitmapSize.y - modifiedSRC.y; 74 } 75 76 srcRegion.set(offsetSRC, modifiedSRC); 77 78 RectI destRegion; 79 Point2I modifiedDest; 80 modifiedDest.x = mVertical ? (F32)updateRect.len_x() : (F32)(updateRect.len_x()*pct); 81 modifiedDest.y = mVertical ? (F32)(updateRect.len_y()*pct) : (F32)updateRect.len_y(); 82 83 Point2I offsetDest = Point2I::Zero; 84 if (mFlipClip) 85 { 86 offsetDest.x = updateRect.len_x() - modifiedDest.x; 87 offsetDest.y = updateRect.len_y() - modifiedDest.y; 88 } 89 offsetDest += offset; 90 destRegion.set(offsetDest, modifiedDest); 91 92 GFX->getDrawUtil()->drawBitmapStretchSR(texture, destRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear, false); 93 } 94 95 if (mProfile->mBorder || !mTextureObject) 96 { 97 RectI rect(offset, getExtent()); 98 GFX->getDrawUtil()->drawRect(rect, mProfile->mBorderColor); 99 } 100 101 renderChildControls(offset, updateRect); 102} 103