guiFadeinBitmapCtrl.cpp
Engine/source/gui/game/guiFadeinBitmapCtrl.cpp
Public Functions
ConsoleDocClass(GuiFadeinBitmapCtrl , "@brief A GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> which renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> black square over <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap image. The black square will fade out, then fade back in after <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> determined <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">time.\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> is especially useful <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> transitions and splash <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">screens.\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/classguifadeinbitmapctrl/">GuiFadeinBitmapCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeinTime=\"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " waitTime = \"2000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeoutTime = \"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " done = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Additional GUI properties that are not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/class/classguifadeinbitmapctrl/">GuiFadeinBitmapCtrl</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</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiBitmapCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
IMPLEMENT_CALLBACK(GuiFadeinBitmapCtrl , click , void , () , () , "@brief Informs the script level that this object received <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Click event from the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">keyboard.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "GuiFadeInBitmapCtrl::click(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Code <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run when click <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">occurs\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n\n</a>" )
IMPLEMENT_CALLBACK(GuiFadeinBitmapCtrl , onDone , void , () , () , "@brief Informs the script level that this object has completed is fade <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cycle.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "GuiFadeInBitmapCtrl::onDone(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Code <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run when the fade cycle <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">completes\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n\n</a>" )
Detailed Description
Public Functions
ConsoleDocClass(GuiFadeinBitmapCtrl , "@brief A GUI <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> which renders <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> black square over <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> bitmap image. The black square will fade out, then fade back in after <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> determined <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">time.\n</a>" "This <a href="/coding/file/guieditctrl_8cpp/#guieditctrl_8cpp_1abb04e3738c4c5a96b3ade6fa47013a6c">control</a> is especially useful <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> transitions and splash <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">screens.\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/classguifadeinbitmapctrl/">GuiFadeinBitmapCtrl</a>()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeinTime=\"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " waitTime = \"2000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " fadeoutTime = \"1000\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " done = \"1\";\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Additional GUI properties that are not specific <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/class/classguifadeinbitmapctrl/">GuiFadeinBitmapCtrl</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</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiBitmapCtrl\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n</a>" )
IMPLEMENT_CALLBACK(GuiFadeinBitmapCtrl , click , void , () , () , "@brief Informs the script level that this object received <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Click event from the <a href="/coding/file/sdlcursorcontroller_8cpp/#sdlcursorcontroller_8cpp_1a06e8dd1f849973ccc456f8553601e8b9">cursor</a> or <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">keyboard.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "GuiFadeInBitmapCtrl::click(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Code <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run when click <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">occurs\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n\n</a>" )
IMPLEMENT_CALLBACK(GuiFadeinBitmapCtrl , onDone , void , () , () , "@brief Informs the script level that this object has completed is fade <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">cycle.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "GuiFadeInBitmapCtrl::onDone(%this)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " {\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " // Code <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> run when the fade cycle <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">completes\n</a>" " }\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiCore\n\n</a>" )
IMPLEMENT_CONOBJECT(GuiFadeinBitmapCtrl )
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/guiFadeinBitmapCtrl.h" 26#include "console/console.h" 27#include "console/consoleTypes.h" 28#include "gfx/gfxDrawUtil.h" 29#include "math/mathTypes.h" 30#include "console/engineAPI.h" 31 32IMPLEMENT_CONOBJECT( GuiFadeinBitmapCtrl ); 33 34ConsoleDocClass( GuiFadeinBitmapCtrl, 35 "@brief A GUI control which renders a black square over a bitmap image. The black square will fade out, then fade back in after a determined time.\n" 36 "This control is especially useful for transitions and splash screens.\n\n" 37 38 "@tsexample\n" 39 "new GuiFadeinBitmapCtrl()\n" 40 " {\n" 41 " fadeinTime = \"1000\";\n" 42 " waitTime = \"2000\";\n" 43 " fadeoutTime = \"1000\";\n" 44 " done = \"1\";\n" 45 " // Additional GUI properties that are not specific to GuiFadeinBitmapCtrl have been omitted from this example.\n" 46 " };\n" 47 "@endtsexample\n\n" 48 49 "@see GuiBitmapCtrl\n\n" 50 "@ingroup GuiCore\n" 51); 52 53IMPLEMENT_CALLBACK( GuiFadeinBitmapCtrl, click, void, (),(), 54 "@brief Informs the script level that this object received a Click event from the cursor or keyboard.\n\n" 55 "@tsexample\n" 56 "GuiFadeInBitmapCtrl::click(%this)\n" 57 " {\n" 58 " // Code to run when click occurs\n" 59 " }\n" 60 "@endtsexample\n\n" 61 "@see GuiCore\n\n" 62); 63 64IMPLEMENT_CALLBACK( GuiFadeinBitmapCtrl, onDone, void, (),(), 65 "@brief Informs the script level that this object has completed is fade cycle.\n\n" 66 "@tsexample\n" 67 "GuiFadeInBitmapCtrl::onDone(%this)\n" 68 " {\n" 69 " // Code to run when the fade cycle completes\n" 70 " }\n" 71 "@endtsexample\n\n" 72 "@see GuiCore\n\n" 73); 74 75//----------------------------------------------------------------------------- 76 77GuiFadeinBitmapCtrl::GuiFadeinBitmapCtrl() 78 : mFadeColor( 0.f, 0.f, 0.f ), 79 mStartTime( 0 ), 80 mFadeInTime( 1000 ), 81 mWaitTime( 2000 ), 82 mFadeOutTime( 1000 ), 83 mDone( false ) 84{ 85} 86 87//----------------------------------------------------------------------------- 88 89void GuiFadeinBitmapCtrl::initPersistFields() 90{ 91 addGroup( "Fading" ); 92 93 addField( "fadeColor", TypeColorF, Offset( mFadeColor, GuiFadeinBitmapCtrl ), 94 "Color to fade in from and fade out to." ); 95 addField( "fadeInTime", TypeS32, Offset( mFadeInTime, GuiFadeinBitmapCtrl ), 96 "Milliseconds for the bitmap to fade in." ); 97 addField( "waitTime", TypeS32, Offset( mWaitTime, GuiFadeinBitmapCtrl ), 98 "Milliseconds to wait after fading in before fading out the bitmap." ); 99 addField( "fadeOutTime", TypeS32, Offset( mFadeOutTime, GuiFadeinBitmapCtrl ), 100 "Milliseconds for the bitmap to fade out." ); 101 addField( "fadeInEase", TypeEaseF, Offset( mFadeInEase, GuiFadeinBitmapCtrl ), 102 "Easing curve for fade-in." ); 103 addField( "fadeOutEase", TypeEaseF, Offset( mFadeOutEase, GuiFadeinBitmapCtrl ), 104 "Easing curve for fade-out." ); 105 addField( "done", TypeBool, Offset( mDone, GuiFadeinBitmapCtrl ), 106 "Whether the fade cycle has finished running." ); 107 108 endGroup( "Fading" ); 109 110 Parent::initPersistFields(); 111} 112 113//----------------------------------------------------------------------------- 114 115void GuiFadeinBitmapCtrl::onPreRender() 116{ 117 Parent::onPreRender(); 118 setUpdate(); 119} 120 121//----------------------------------------------------------------------------- 122 123void GuiFadeinBitmapCtrl::onMouseDown(const GuiEvent &) 124{ 125 click_callback(); 126} 127 128//----------------------------------------------------------------------------- 129 130bool GuiFadeinBitmapCtrl::onKeyDown(const GuiEvent &) 131{ 132 click_callback(); 133 return true; 134} 135 136bool GuiFadeinBitmapCtrl::onGamepadButtonDown(const GuiEvent& event) 137{ 138 click_callback(); 139 return true; 140} 141 142//----------------------------------------------------------------------------- 143 144bool GuiFadeinBitmapCtrl::onWake() 145{ 146 if( !Parent::onWake() ) 147 return false; 148 149 // Reset reference time. 150 mStartTime = 0; 151 152 return true; 153} 154 155//----------------------------------------------------------------------------- 156 157void GuiFadeinBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) 158{ 159 Parent::onRender(offset, updateRect); 160 161 // Set reference time if we haven't already. This is done here when rendering 162 // starts so that we begin counting from the time the control is actually 163 // visible rather than from its onWake() (which may be a considerable time 164 // before the control actually gets to render). 165 166 if( !mStartTime ) 167 mStartTime = Platform::getRealMilliseconds(); 168 169 // Compute overlay alpha. 170 171 U32 elapsed = Platform::getRealMilliseconds() - mStartTime; 172 173 U32 alpha; 174 if( elapsed < mFadeInTime ) 175 { 176 // fade-in 177 alpha = 255.f * ( 1.0f - mFadeInEase.getValue( elapsed, 0.f, 1.f, mFadeInTime ) ); 178 } 179 else if( elapsed < ( mFadeInTime + mWaitTime ) ) 180 { 181 // wait 182 alpha = 0; 183 } 184 else if( elapsed < ( mFadeInTime + mWaitTime + mFadeOutTime ) ) 185 { 186 // fade out 187 elapsed -= ( mFadeInTime + mWaitTime ); 188 alpha = mFadeOutEase.getValue( elapsed, 0.f, 255.f, mFadeOutTime ); 189 } 190 else 191 { 192 // done state 193 alpha = mFadeOutTime ? 255 : 0; 194 mDone = true; 195 196 // Trigger onDone callback except when in Gui Editor. 197 198 if( !smDesignTime ) 199 onDone_callback(); 200 } 201 202 // Render overlay on top of bitmap. 203 204 ColorI color = mFadeColor.toColorI(); 205 color.alpha = alpha; 206 207 GFX->getDrawUtil()->drawRectFill( offset, getExtent() + offset, color ); 208} 209