afxStatusBar.cpp
Engine/source/afx/ui/afxStatusBar.cpp
Classes:
class
Public Functions
ConsoleDocClass(afxStatusBar , "@brief A GUI status bar <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> tracking and displaying health and energy of <a href="/coding/class/classshapebase/">ShapeBase</a> " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">objects.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxGUI\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
DefineEngineMethod(afxStatusBar , clearShape , void , () , "Clear out any <a href="/coding/class/classshapebase/">ShapeBase</a>-derived object associated with the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxStatusBar , setProgress , void , (float percentDone) , "Set the progress percentage on the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxStatusBar , setShape , void , (ShapeBase *shape) , "Associate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classshapebase/">ShapeBase</a>-derived object with the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
Detailed Description
Public Functions
ConsoleDocClass(afxStatusBar , "@brief A GUI status bar <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> tracking and displaying health and energy of <a href="/coding/class/classshapebase/">ShapeBase</a> " "<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">objects.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxGUI\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
DefineEngineMethod(afxStatusBar , clearShape , void , () , "Clear out any <a href="/coding/class/classshapebase/">ShapeBase</a>-derived object associated with the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxStatusBar , setProgress , void , (float percentDone) , "Set the progress percentage on the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
DefineEngineMethod(afxStatusBar , setShape , void , (ShapeBase *shape) , "Associate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classshapebase/">ShapeBase</a>-derived object with the status-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
IMPLEMENT_CONOBJECT(afxStatusBar )
1 2 3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 5// Copyright (C) 2015 Faust Logic, Inc. 6// 7// Permission is hereby granted, free of charge, to any person obtaining a copy 8// of this software and associated documentation files (the "Software"), to 9// deal in the Software without restriction, including without limitation the 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11// sell copies of the Software, and to permit persons to whom the Software is 12// furnished to do so, subject to the following conditions: 13// 14// The above copyright notice and this permission notice shall be included in 15// all copies or substantial portions of the Software. 16// 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23// IN THE SOFTWARE. 24// 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 26 27#include "afx/arcaneFX.h" 28 29#include "console/engineAPI.h" 30#include "gui/core/guiControl.h" 31#include "T3D/gameBase/gameConnection.h" 32#include "T3D/shapeBase.h" 33#include "gfx/gfxDrawUtil.h" 34 35#include "afx/ui/afxProgressBase.h" 36 37//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 38 39class afxStatusBar : public GuiControl, public afxProgressBase 40{ 41 typedef GuiControl Parent; 42 43 LinearColorF rgba_fill; 44 45 F32 fraction; 46 ShapeBase* shape; 47 bool show_energy; 48 bool monitor_player; 49 50public: 51 /*C*/ afxStatusBar(); 52 53 virtual void onRender(Point2I, const RectI&); 54 55 void setFraction(F32 frac); 56 F32 getFraction() const { return fraction; } 57 58 virtual void setProgress(F32 value) { setFraction(value); } 59 60 void setShape(ShapeBase* s); 61 void clearShape() { setShape(NULL); } 62 63 virtual bool onWake(); 64 virtual void onSleep(); 65 virtual void onMouseDown(const GuiEvent &event); 66 virtual void onDeleteNotify(SimObject*); 67 68 static void initPersistFields(); 69 70 DECLARE_CONOBJECT(afxStatusBar); 71 DECLARE_CATEGORY("AFX"); 72}; 73 74//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 75 76IMPLEMENT_CONOBJECT(afxStatusBar); 77 78ConsoleDocClass( afxStatusBar, 79 "@brief A GUI status bar for tracking and displaying health and energy of ShapeBase " 80 "objects.\n\n" 81 82 "@ingroup afxGUI\n" 83 "@ingroup AFX\n" 84); 85 86afxStatusBar::afxStatusBar() 87{ 88 rgba_fill.set(0.0f, 1.0f, 1.0f, 1.0f); 89 90 fraction = 1.0f; 91 shape = 0; 92 show_energy = false; 93 monitor_player = false; 94} 95 96void afxStatusBar::setFraction(F32 frac) 97{ 98 fraction = mClampF(frac, 0.0f, 1.0f); 99} 100 101void afxStatusBar::setShape(ShapeBase* s) 102{ 103 if (shape) 104 clearNotify(shape); 105 shape = s; 106 if (shape) 107 deleteNotify(shape); 108} 109 110void afxStatusBar::onDeleteNotify(SimObject* obj) 111{ 112 if (shape == (ShapeBase*)obj) 113 { 114 shape = NULL; 115 return; 116 } 117 118 Parent::onDeleteNotify(obj); 119} 120 121bool afxStatusBar::onWake() 122{ 123 if (!Parent::onWake()) 124 return false; 125 126 return true; 127} 128 129void afxStatusBar::onSleep() 130{ 131 //clearShape(); 132 Parent::onSleep(); 133} 134 135// STATIC 136void afxStatusBar::initPersistFields() 137{ 138 addField("fillColor", TypeColorF, Offset(rgba_fill, afxStatusBar), 139 "..."); 140 addField("displayEnergy", TypeBool, Offset(show_energy, afxStatusBar), 141 "..."); 142 addField("monitorPlayer", TypeBool, Offset(monitor_player, afxStatusBar), 143 "..."); 144 145 Parent::initPersistFields(); 146} 147 148//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 149 150 151void afxStatusBar::onRender(Point2I offset, const RectI &updateRect) 152{ 153 if (!shape) 154 return; 155 156 if (shape->getDamageState() != ShapeBase::Enabled) 157 fraction = 0.0f; 158 else 159 fraction = (show_energy) ? shape->getEnergyValue() : (1.0f - shape->getDamageValue()); 160 161 // set alpha value for the fill area 162 rgba_fill.alpha = 1.0f; 163 164 // calculate the rectangle dimensions 165 RectI rect(updateRect); 166 rect.extent.x = (S32)(rect.extent.x*fraction); 167 168 // draw the filled part of bar 169 GFX->getDrawUtil()->drawRectFill(rect, rgba_fill.toColorI()); 170} 171 172void afxStatusBar::onMouseDown(const GuiEvent &event) 173{ 174 GuiControl *parent = getParent(); 175 if (parent) 176 parent->onMouseDown(event); 177} 178 179//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 180 181DefineEngineMethod(afxStatusBar, setProgress, void, (float percentDone),, 182 "Set the progress percentage on the status-bar.\n\n" 183 "@ingroup AFX") 184{ 185 object->setFraction(percentDone); 186} 187 188DefineEngineMethod(afxStatusBar, setShape, void, (ShapeBase* shape),, 189 "Associate a ShapeBase-derived object with the status-bar.\n\n" 190 "@ingroup AFX") 191{ 192 object->setShape(shape); 193} 194 195DefineEngineMethod(afxStatusBar, clearShape, void, (),, 196 "Clear out any ShapeBase-derived object associated with the status-bar.\n\n" 197 "@ingroup AFX") 198{ 199 object->clearShape(); 200} 201 202 203//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 204