afxSpellCastBar.cpp
Engine/source/afx/ui/afxSpellCastBar.cpp
Classes:
class
Public Functions
ConsoleDocClass(afxSpellCastBar , "@brief A GUI progress bar useful as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spell casting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\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(afxSpellCastBar , setProgress , void , (float percentDone) , "Set the progress percentage on the progress-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
Detailed Description
Public Functions
ConsoleDocClass(afxSpellCastBar , "@brief A GUI progress bar useful as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> spell casting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\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(afxSpellCastBar , setProgress , void , (float percentDone) , "Set the progress percentage on the progress-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">bar.\n\n</a>" "@ingroup AFX" )
IMPLEMENT_CONOBJECT(afxSpellCastBar )
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 "gfx/gfxDrawUtil.h" 32 33#include "afx/ui/afxProgressBase.h" 34 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 36 37class afxSpellCastBar : public GuiControl, public afxProgressBase 38{ 39 typedef GuiControl Parent; 40 41 bool want_border; 42 bool want_background; 43 bool use_alt_final_color; 44 LinearColorF rgba_background; 45 LinearColorF rgba_border; 46 LinearColorF rgba_fill; 47 LinearColorF rgba_fill_final; 48 49 F32 fraction; 50 51public: 52 /*C*/ afxSpellCastBar(); 53 54 virtual void onRender(Point2I, const RectI&); 55 56 void setFraction(F32 frac); 57 F32 getFraction() const { return fraction; } 58 59 virtual void setProgress(F32 value) { setFraction(value); } 60 virtual void onStaticModified(const char* slotName, const char* newValue = NULL); 61 62 static void initPersistFields(); 63 64 DECLARE_CONOBJECT(afxSpellCastBar); 65 DECLARE_CATEGORY("AFX"); 66}; 67 68//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 69 70IMPLEMENT_CONOBJECT(afxSpellCastBar); 71 72ConsoleDocClass( afxSpellCastBar, 73 "@brief A GUI progress bar useful as a spell casting bar.\n\n" 74 75 "@ingroup afxGUI\n" 76 "@ingroup AFX\n" 77); 78 79afxSpellCastBar::afxSpellCastBar() 80{ 81 want_border = true; 82 want_background = true; 83 use_alt_final_color = false; 84 rgba_background.set(0.0f, 0.0f, 0.0f, 0.5f); 85 rgba_border.set(0.5f, 0.5f, 0.5f, 1.0f); 86 rgba_fill.set(0.0f, 1.0f, 1.0f, 1.0f); 87 rgba_fill_final.set(0.0f, 1.0f, 1.0f, 1.0f); 88 89 fraction = 0.5f; 90} 91 92void afxSpellCastBar::setFraction(F32 frac) 93{ 94 fraction = mClampF(frac, 0.0f, 1.0f); 95} 96 97void afxSpellCastBar::onStaticModified(const char* slotName, const char* newValue) 98{ 99 Parent::onStaticModified(slotName, newValue); 100 if (dStricmp(slotName, "fillColorFinal") == 0) 101 use_alt_final_color = true; 102} 103 104// STATIC 105void afxSpellCastBar::initPersistFields() 106{ 107 addGroup("Colors"); 108 addField( "backgroundColor", TypeColorF, Offset(rgba_background, afxSpellCastBar), 109 "..."); 110 addField( "borderColor", TypeColorF, Offset(rgba_border, afxSpellCastBar), 111 "..."); 112 addField( "fillColor", TypeColorF, Offset(rgba_fill, afxSpellCastBar), 113 "..."); 114 addField( "fillColorFinal", TypeColorF, Offset(rgba_fill_final, afxSpellCastBar), 115 "..."); 116 endGroup("Colors"); 117 118 Parent::initPersistFields(); 119} 120 121//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 122 123void afxSpellCastBar::onRender(Point2I offset, const RectI &updateRect) 124{ 125 LinearColorF color; 126 127 // draw the background 128 if (want_background) 129 { 130 color.set(rgba_background.red, rgba_background.green, rgba_background.blue, rgba_background.alpha*fade_amt); 131 GFX->getDrawUtil()->drawRectFill(updateRect, color.toColorI()); 132 } 133 134 // calculate the rectangle dimensions 135 RectI rect(updateRect); 136 rect.extent.x = (S32)(rect.extent.x * fraction); 137 138 // draw the filled part of bar 139 if (fraction >= 1.0f && use_alt_final_color) 140 color.set(rgba_fill_final.red, rgba_fill_final.green, rgba_fill_final.blue, rgba_fill_final.alpha*fade_amt); 141 else 142 color.set(rgba_fill.red, rgba_fill.green, rgba_fill.blue, rgba_fill.alpha*fade_amt); 143 144 GFX->getDrawUtil()->drawRectFill(rect, color.toColorI()); 145 146 // draw the border 147 if (want_border) 148 { 149 color.set(rgba_border.red, rgba_border.green, rgba_border.blue, rgba_border.alpha*fade_amt); 150 GFX->getDrawUtil()->drawRect(updateRect, color.toColorI()); 151 } 152} 153 154//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 155 156DefineEngineMethod(afxSpellCastBar, setProgress, void, (float percentDone),, 157 "Set the progress percentage on the progress-bar.\n\n" 158 "@ingroup AFX") 159{ 160 object->setFraction(percentDone); 161} 162 163//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 164