guiProgressCtrl.cpp
Engine/source/gui/game/guiProgressCtrl.cpp
Public Functions
ConsoleDocClass(GuiProgressCtrl , "@brief GUI Control which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> horizontal bar which increases as the progress <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> of 0.0 - 1.0 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">increases.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" " <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiprogressctrl/">GuiProgressCtrl</a>(JS_statusBar)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" " };\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Define the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the progress bar" "% value)
Detailed Description
Public Functions
ConsoleDocClass(GuiProgressCtrl , "@brief GUI Control which displays <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> horizontal bar which increases as the progress <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> of 0.0 - 1.0 <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">increases.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" " <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiprogressctrl/">GuiProgressCtrl</a>(JS_statusBar)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " //Properties not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> this <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> have been omitted from this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">example.\n</a>" " };\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Define the <a href="/coding/file/pointer_8h/#pointer_8h_1a32aff7c6c4cd253fdf6563677afab5ce">value</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the progress bar" "% value)
IMPLEMENT_CONOBJECT(GuiProgressCtrl )
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/game/guiProgressCtrl.h" 26 27#include "console/console.h" 28#include "console/consoleTypes.h" 29#include "gfx/gfxDrawUtil.h" 30#include "console/engineAPI.h" 31 32IMPLEMENT_CONOBJECT(GuiProgressCtrl); 33 34ConsoleDocClass( GuiProgressCtrl, 35 "@brief GUI Control which displays a horizontal bar which increases as the progress value of 0.0 - 1.0 increases.\n\n" 36 37 "@tsexample\n" 38 " new GuiProgressCtrl(JS_statusBar)\n" 39 " {\n" 40 " //Properties not specific to this control have been omitted from this example.\n" 41 " };\n\n" 42 "// Define the value to set the progress bar" 43 "%value = \"0.5f\"\n\n" 44 "// Set the value of the progress bar, from 0.0 - 1.0\n" 45 "%thisGuiProgressCtrl.setValue(%value);\n" 46 "// Get the value of the progress bar.\n" 47 "%progress = %thisGuiProgressCtrl.getValue();\n" 48 "@endtsexample\n\n" 49 50 "@see GuiTextCtrl\n" 51 "@see GuiControl\n\n" 52 53 "@ingroup GuiValues\n" 54); 55 56GuiProgressCtrl::GuiProgressCtrl() 57{ 58 mProgress = 0.0f; 59} 60 61const char* GuiProgressCtrl::getScriptValue() 62{ 63 static const U32 bufSize = 64; 64 char * ret = Con::getReturnBuffer(bufSize); 65 dSprintf(ret, bufSize, "%g", mProgress); 66 return ret; 67} 68 69void GuiProgressCtrl::setScriptValue(const char *value) 70{ 71 //set the value 72 if (! value) 73 mProgress = 0.0f; 74 else 75 mProgress = dAtof(value); 76 77 //validate the value 78 mProgress = mClampF(mProgress, 0.f, 1.f); 79 setUpdate(); 80} 81 82void GuiProgressCtrl::onPreRender() 83{ 84 const char * var = getVariable(); 85 if(var) 86 { 87 F32 value = mClampF(dAtof(var), 0.f, 1.f); 88 if(value != mProgress) 89 { 90 mProgress = value; 91 setUpdate(); 92 } 93 } 94} 95 96void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect) 97{ 98 RectI ctrlRect(offset, getExtent()); 99 100 //draw the progress 101 S32 width = (S32)((F32)(getWidth()) * mProgress); 102 if (width > 0) 103 { 104 RectI progressRect = ctrlRect; 105 progressRect.extent.x = width; 106 GFX->getDrawUtil()->drawRectFill(progressRect, mProfile->mFillColor); 107 } 108 109 //now draw the border 110 if (mProfile->mBorder) 111 GFX->getDrawUtil()->drawRect(ctrlRect, mProfile->mBorderColor); 112 113 Parent::onRender( offset, updateRect ); 114 115 //render the children 116 renderChildControls(offset, updateRect); 117} 118 119