VFadeTrack.cpp
Engine/source/Verve/Extension/GUI/VFadeTrack.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CONOBJECT(VFadeTrack )
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/VFadeTrack.h" 25#include "Verve/Extension/GUI/VFadeEvent.h" 26 27//----------------------------------------------------------------------------- 28IMPLEMENT_CONOBJECT( VFadeTrack ); 29//----------------------------------------------------------------------------- 30 31VFadeTrack::VFadeTrack( void ) 32{ 33 setLabel( "FadeTrack" ); 34} 35 36//----------------------------------------------------------------------------- 37// 38// Controller Methods. 39// 40//----------------------------------------------------------------------------- 41 42//----------------------------------------------------------------------------- 43// 44// VFadeTrack::onControllerEvent( pEvent ); 45// 46// When the controller's state changes, this method is called. If the 47// controller is paused, or stops playing, then the fade control will cease 48// playing. If the controller resumes play, the fade control will continue. 49// 50// For a full list of possible events, see the 'eControllerEventType' 51// declaration in VController.h. 52// 53//----------------------------------------------------------------------------- 54bool VFadeTrack::onControllerEvent( VController::eControllerEventType pEvent ) 55{ 56 if ( !Parent::onControllerEvent( pEvent ) ) 57 { 58 // Skip. 59 return false; 60 } 61 62 // Enabled? 63 if ( !isEnabled() ) 64 { 65 // Continue Processing Events. 66 return true; 67 } 68 69 // Fetch the next Event. 70 VFadeEvent *event; 71 if ( !getNextEvent( event ) ) 72 { 73 // No Event. 74 return true; 75 } 76 77 // Fetch GUI Control. 78 VFadeControl *fadeControl = dynamic_cast<VFadeControl*>( Sim::findObject( "VFadeControlGui" ) ); 79 if ( !fadeControl ) 80 { 81 // No Control. 82 return true; 83 } 84 85 switch ( pEvent ) 86 { 87 case VController::k_EventPlay: 88 { 89 // Play? 90 const S32 &time = getControllerTime(); 91 fadeControl->mActive = ( time > event->getTriggerTime() 92 && time < event->getFinishTime() ) ; 93 94 } break; 95 96 case VController::k_EventPause : 97 case VController::k_EventStop : 98 { 99 100 // Pause. 101 fadeControl->mActive = false; 102 103 } break; 104 } 105 106 return true; 107} 108 109//----------------------------------------------------------------------------- 110// 111// VFadeTrack::onControllerReset( pTime, pForward ); 112// 113// Reset the fade state of the fade control. 114// 115//----------------------------------------------------------------------------- 116void VFadeTrack::onControllerReset( const S32 &pTime, const bool &pForward ) 117{ 118 Parent::onControllerReset( pTime, pForward ); 119 120 // Fetch GUI Control. 121 VFadeControl *fadeControl; 122 if ( !Sim::findObject( "VFadeControlGUI", fadeControl ) ) 123 { 124 // Invalid. 125 return; 126 } 127 128 VFadeEvent *event; 129 if ( !getNextEvent( event ) ) 130 { 131 // No Events. 132 return; 133 } 134 135 // Apply Settings. 136 fadeControl->mActive = false; 137 fadeControl->mFadeType = event->getFadeType(); 138 fadeControl->mDuration = event->getDuration(); 139 fadeControl->mElapsedTime = getMax( pTime - event->getTriggerTime(), 0 ); 140} 141