VFadeTrack.cpp 4.4 KB

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