VFadeEvent.cpp 3.8 KB

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