guiClockHud.cpp
Engine/source/T3D/fps/guiClockHud.cpp
Classes:
class
Vary basic HUD clock.
Public Functions
ConsoleDocClass(GuiClockHud , "@brief Basic HUD clock. Displays the current simulation time offset from some <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">base.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiclockhud/">GuiClockHud</a>()" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fillColor = \"0.0 1.0 0.0 1.0\"; // Fills with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> solid green <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">color\n</a>" " frameColor = \"1.0 1.0 1.0 1.0\"; // Solid white frame <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">color\n</a>" " textColor = \"1.0 1.0 1.0 1.0\"; // Solid white text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Color\n</a>" " showFill = \"true\";\n" " showFrame = \"true\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGame\n</a>" )
DefineEngineMethod(GuiClockHud , getTime , F32 , () , "Returns the current time, in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">seconds.\n</a>" " @return timeInseconds Current time)
DefineEngineMethod(GuiClockHud , setReverseTime , void , (F32 timeInSeconds) , (60) , "@brief Sets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> time <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> countdown <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clock.\n\n</a>" "Setting the time like this will cause the clock <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> backwards from the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">time.\n\n</a>" "@param timeInSeconds Time <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the clock, in seconds(IE:00:02 would be 120)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setTime\n</a>" )
DefineEngineMethod(GuiClockHud , setTime , void , (F32 timeInSeconds) , (60) , "Sets the current base time <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clock.\n</a>" "@param timeInSeconds Time <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the clock, in seconds(IE:00:02 would be 120)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Define the time)
Detailed Description
Public Functions
ConsoleDocClass(GuiClockHud , "@brief Basic HUD clock. Displays the current simulation time offset from some <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">base.\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a> <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classguiclockhud/">GuiClockHud</a>()" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fillColor = \"0.0 1.0 0.0 1.0\"; // Fills with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> solid green <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">color\n</a>" " frameColor = \"1.0 1.0 1.0 1.0\"; // Solid white frame <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">color\n</a>" " textColor = \"1.0 1.0 1.0 1.0\"; // Solid white text <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Color\n</a>" " showFill = \"true\";\n" " showFrame = \"true\";\n" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiGame\n</a>" )
DefineEngineMethod(GuiClockHud , getTime , F32 , () , "Returns the current time, in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">seconds.\n</a>" " @return timeInseconds Current time)
DefineEngineMethod(GuiClockHud , setReverseTime , void , (F32 timeInSeconds) , (60) , "@brief Sets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> time <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> countdown <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clock.\n\n</a>" "Setting the time like this will cause the clock <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1ad43c3812e6d13e0518d9f8b8f463ffcf">count</a> backwards from the specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">time.\n\n</a>" "@param timeInSeconds Time <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the clock, in seconds(IE:00:02 would be 120)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">setTime\n</a>" )
DefineEngineMethod(GuiClockHud , setTime , void , (F32 timeInSeconds) , (60) , "Sets the current base time <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">clock.\n</a>" "@param timeInSeconds Time <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set the clock, in seconds(IE:00:02 would be 120)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "//Define the time)
IMPLEMENT_CONOBJECT(GuiClockHud )
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 26#include "gui/core/guiControl.h" 27#include "console/consoleTypes.h" 28#include "T3D/shapeBase.h" 29#include "gfx/gfxDrawUtil.h" 30#include "console/engineAPI.h" 31 32//----------------------------------------------------------------------------- 33 34/// Vary basic HUD clock. 35/// Displays the current simulation time offset from some base. The base time 36/// is usually synchronized with the server as mission start time. This hud 37/// currently only displays minutes:seconds. 38class GuiClockHud : public GuiControl 39{ 40 typedef GuiControl Parent; 41 42 bool mShowFrame; 43 bool mShowFill; 44 bool mTimeReversed; 45 46 LinearColorF mFillColor; 47 LinearColorF mFrameColor; 48 LinearColorF mTextColor; 49 50 S32 mTimeOffset; 51 52public: 53 GuiClockHud(); 54 55 void setTime(F32 newTime); 56 void setReverseTime(F32 reverseTime); 57 F32 getTime(); 58 59 void onRender( Point2I, const RectI &); 60 static void initPersistFields(); 61 DECLARE_CONOBJECT( GuiClockHud ); 62 DECLARE_CATEGORY( "Gui Game" ); 63 DECLARE_DESCRIPTION( "Basic HUD clock. Displays the current simulation time offset from some base." ); 64}; 65 66 67//----------------------------------------------------------------------------- 68 69IMPLEMENT_CONOBJECT( GuiClockHud ); 70 71ConsoleDocClass( GuiClockHud, 72 "@brief Basic HUD clock. Displays the current simulation time offset from some base.\n" 73 74 "@tsexample\n" 75 "\n new GuiClockHud()" 76 "{\n" 77 " fillColor = \"0.0 1.0 0.0 1.0\"; // Fills with a solid green color\n" 78 " frameColor = \"1.0 1.0 1.0 1.0\"; // Solid white frame color\n" 79 " textColor = \"1.0 1.0 1.0 1.0\"; // Solid white text Color\n" 80 " showFill = \"true\";\n" 81 " showFrame = \"true\";\n" 82 "};\n" 83 "@endtsexample\n\n" 84 85 "@ingroup GuiGame\n" 86); 87 88GuiClockHud::GuiClockHud() 89{ 90 mShowFrame = mShowFill = true; 91 mTimeReversed = false; 92 mFillColor.set(0, 0, 0, 0.5); 93 mFrameColor.set(0, 1, 0, 1); 94 mTextColor.set( 0, 1, 0, 1 ); 95 96 mTimeOffset = 0; 97} 98 99void GuiClockHud::initPersistFields() 100{ 101 addGroup("Misc"); 102 addField( "showFill", TypeBool, Offset( mShowFill, GuiClockHud ), "If true, draws a background color behind the control."); 103 addField( "showFrame", TypeBool, Offset( mShowFrame, GuiClockHud ), "If true, draws a frame around the control." ); 104 addField( "fillColor", TypeColorF, Offset( mFillColor, GuiClockHud ), "Standard color for the background of the control." ); 105 addField( "frameColor", TypeColorF, Offset( mFrameColor, GuiClockHud ), "Color for the control's frame." ); 106 addField( "textColor", TypeColorF, Offset( mTextColor, GuiClockHud ), "Color for the text on this control." ); 107 endGroup("Misc"); 108 109 Parent::initPersistFields(); 110} 111 112 113//----------------------------------------------------------------------------- 114 115void GuiClockHud::onRender(Point2I offset, const RectI &updateRect) 116{ 117 GFXDrawUtil* drawUtil = GFX->getDrawUtil(); 118 119 // Background first 120 if (mShowFill) 121 drawUtil->drawRectFill(updateRect, mFillColor.toColorI()); 122 123 // Convert ms time into hours, minutes and seconds. 124 S32 time = S32(getTime()); 125 S32 secs = time % 60; 126 S32 mins = (time % 3600) / 60; 127 128 // Currently only displays min/sec 129 char buf[256]; 130 dSprintf(buf,sizeof(buf), "%02d:%02d",mins,secs); 131 132 // Center the text 133 offset.x += (getWidth() - mProfile->mFont->getStrWidth((const UTF8 *)buf)) / 2; 134 offset.y += (getHeight() - mProfile->mFont->getHeight()) / 2; 135 drawUtil->setBitmapModulation(mTextColor.toColorI()); 136 drawUtil->drawText(mProfile->mFont, offset, buf); 137 drawUtil->clearBitmapModulation(); 138 139 // Border last 140 if (mShowFrame) 141 drawUtil->drawRect(updateRect, mFrameColor.toColorI()); 142} 143 144 145//----------------------------------------------------------------------------- 146 147void GuiClockHud::setReverseTime(F32 time) 148{ 149 // Set the current time in seconds. 150 mTimeReversed = true; 151 mTimeOffset = S32(time * 1000) + Platform::getVirtualMilliseconds(); 152} 153 154void GuiClockHud::setTime(F32 time) 155{ 156 // Set the current time in seconds. 157 mTimeReversed = false; 158 mTimeOffset = S32(time * 1000) - Platform::getVirtualMilliseconds(); 159} 160 161F32 GuiClockHud::getTime() 162{ 163 // Return elapsed time in seconds. 164 if(mTimeReversed) 165 return F32(mTimeOffset - Platform::getVirtualMilliseconds()) / 1000; 166 else 167 return F32(mTimeOffset + Platform::getVirtualMilliseconds()) / 1000; 168} 169 170DefineEngineMethod(GuiClockHud, setTime, void, (F32 timeInSeconds),(60), "Sets the current base time for the clock.\n" 171 "@param timeInSeconds Time to set the clock, in seconds (IE: 00:02 would be 120)\n" 172 "@tsexample\n" 173 "// Define the time, in seconds\n" 174 "%timeInSeconds = 120;\n\n" 175 "// Change the time on the GuiClockHud control\n" 176 "%guiClockHud.setTime(%timeInSeconds);\n" 177 "@endtsexample\n" 178 ) 179{ 180 object->setTime(timeInSeconds); 181} 182 183DefineEngineMethod(GuiClockHud, setReverseTime, void, (F32 timeInSeconds),(60), "@brief Sets a time for a countdown clock.\n\n" 184 "Setting the time like this will cause the clock to count backwards from the specified time.\n\n" 185 "@param timeInSeconds Time to set the clock, in seconds (IE: 00:02 would be 120)\n\n" 186 "@see setTime\n" 187 ) 188{ 189 object->setReverseTime(timeInSeconds); 190} 191 192DefineEngineMethod(GuiClockHud, getTime, F32, (),, "Returns the current time, in seconds.\n" 193 "@return timeInseconds Current time, in seconds\n" 194 "@tsexample\n" 195 "// Get the current time from the GuiClockHud control\n" 196 "%timeInSeconds = %guiClockHud.getTime();\n" 197 "@endtsexample\n" 198 ) 199{ 200 return object->getTime(); 201} 202