Torque3D Documentation / _generateds / VFadeControl.cpp

VFadeControl.cpp

Engine/source/Verve/GUI/VFadeControl.cpp

More...

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(VFadeControl )

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#include "Verve/GUI/VFadeControl.h"
 25
 26#include "console/consoleTypes.h"
 27#include "gfx/gfxDrawUtil.h"
 28#include "math/mMathFn.h"
 29
 30//-----------------------------------------------------------------------------
 31IMPLEMENT_CONOBJECT( VFadeControl );
 32//-----------------------------------------------------------------------------
 33
 34VFadeControl::VFadeControl( void ) : 
 35        mActive( false ),
 36        mFadeType( k_TypeInvalid ),
 37        mElapsedTime( 0 ),
 38        mDuration( 1000 ),
 39        mLastTime( 0 )
 40{
 41    // Void.
 42}
 43
 44//-----------------------------------------------------------------------------
 45//
 46// Render Methods.
 47//
 48//-----------------------------------------------------------------------------
 49
 50void VFadeControl::onRender( Point2I pOffset, const RectI &pUpdateRect )
 51{
 52    Parent::onRender( pOffset, pUpdateRect );
 53
 54    if ( mFadeType == k_TypeInvalid )
 55    {
 56        // Invalid Fade State.
 57        return;
 58    }
 59
 60    // Fetch Time.
 61    const U32 time  = Platform::getRealMilliseconds();
 62    // Fetch Delta.
 63    const U32 delta = ( time - mLastTime );
 64    // Store Time.
 65    mLastTime       = time;
 66
 67    if ( mActive )
 68    {
 69        // Update Elapsed Time.
 70        mElapsedTime += delta;
 71    }
 72
 73    F32 alpha = 1.f - mClampF( F32( mElapsedTime ) / F32( mDuration ), 0.f, 1.f );
 74
 75    if ( mFadeType == k_TypeOut )
 76    {
 77        // Flip.
 78        alpha = 1.f - alpha;
 79    }
 80
 81    if ( alpha > 0.f )
 82    {
 83        // Render.
 84        GFX->getDrawUtil()->drawRectFill( pOffset, pOffset + getExtent(), ColorI( 0, 0, 0, alpha * 255 ) );
 85    }
 86
 87    if ( mElapsedTime >= mDuration )
 88    {
 89        // Stop.
 90        mActive = false;
 91    }
 92}
 93
 94//-----------------------------------------------------------------------------
 95//
 96// Control Methods.
 97//
 98//-----------------------------------------------------------------------------
 99
100void VFadeControl::start( eFadeType pType, S32 pDuration )
101{
102    mActive      = true;
103
104    mFadeType    = pType;
105
106    mElapsedTime = 0;
107    mDuration    = pDuration;
108
109    mLastTime    = Platform::getRealMilliseconds();
110}
111
112void VFadeControl::pause( void )
113{
114    mActive = false;
115}
116