VFadeEvent.cpp

Engine/source/Verve/Extension/GUI/VFadeEvent.cpp

More...

Public Functions

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(VFadeEvent )

  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/Extension/GUI/VFadeEvent.h"
 25
 26//-----------------------------------------------------------------------------
 27IMPLEMENT_CONOBJECT( VFadeEvent );
 28//-----------------------------------------------------------------------------
 29
 30VFadeEvent::VFadeEvent( void )
 31{
 32    setLabel( "FadeEvent" );
 33}
 34
 35//-----------------------------------------------------------------------------
 36//
 37// Callback Methods.
 38//
 39//-----------------------------------------------------------------------------
 40
 41//-----------------------------------------------------------------------------
 42// 
 43// VFadeEvent::onTrigger( pTime, pDelta );
 44// 
 45// Start the fade sequence if a valid fade control can be found.
 46// 
 47//-----------------------------------------------------------------------------
 48void VFadeEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
 49{
 50    Parent::onTrigger( pTime, pDelta );
 51
 52    // Fetch GUI Control.
 53    VFadeControl *fadeControl;
 54    if ( !Sim::findObject( "VFadeControlGUI", fadeControl ) )
 55    {
 56        // Invalid.
 57        return;
 58    }
 59
 60    // Start Fade.
 61    fadeControl->start( getFadeType(), mDuration );
 62
 63    // Set Elapsed Time.
 64    fadeControl->mElapsedTime = mAbs( pTime - getStartTime() );
 65}
 66
 67//-----------------------------------------------------------------------------
 68// 
 69// VFadeEvent::onComplete( pTime, pDelta );
 70// 
 71// Tidy up the fade control once the event has finished.
 72// 
 73//-----------------------------------------------------------------------------
 74void VFadeEvent::onComplete( const S32 &pTime, const S32 &pDelta )
 75{
 76    Parent::onTrigger( pTime, pDelta );
 77
 78    // Fetch GUI Control.
 79    VFadeControl *fadeControl;
 80    if ( !Sim::findObject( "VFadeControlGUI", fadeControl ) )
 81    {
 82        // Invalid.
 83        return;
 84    }
 85
 86    // Set Elapsed Time.
 87    fadeControl->mElapsedTime = mDuration;
 88}
 89
 90//-----------------------------------------------------------------------------
 91//
 92// Property Methods.
 93//
 94//-----------------------------------------------------------------------------
 95
 96//-----------------------------------------------------------------------------
 97// 
 98// VFadeEvent::getFadeType();
 99// 
100// Returns the type of fade (in or out) that this event will use. Zero and Even
101// indices will Fade Out, while Odd numbers will Fade In.
102// 
103//-----------------------------------------------------------------------------
104VFadeControl::eFadeType VFadeEvent::getFadeType( void )
105{
106    if ( !isControllerPlayingForward() )
107    {
108        return ( getIndex() % 2 == 0 ) ? VFadeControl::k_TypeOut : VFadeControl::k_TypeIn;
109    }
110
111    return ( getIndex() % 2 == 0 ) ? VFadeControl::k_TypeIn : VFadeControl::k_TypeOut;
112}
113