VideoWidget.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * TextControls.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "VideoWidget.h"
  12. #include "../CGameInfo.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../gui/WindowHandler.h"
  15. #include "../media/ISoundPlayer.h"
  16. #include "../media/IVideoPlayer.h"
  17. #include "../render/Canvas.h"
  18. VideoWidget::VideoWidget(const Point & position, const VideoPath & looped)
  19. : VideoWidget(position, VideoPath(), looped)
  20. {
  21. addUsedEvents(TIME);
  22. }
  23. VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped)
  24. : current(prologue)
  25. , next(looped)
  26. , videoSoundHandle(-1)
  27. {
  28. if(current.empty())
  29. videoInstance = CCS->videoh->open(looped, false);
  30. else
  31. videoInstance = CCS->videoh->open(current, false);
  32. }
  33. VideoWidget::~VideoWidget() = default;
  34. void VideoWidget::show(Canvas & to)
  35. {
  36. if(videoInstance)
  37. videoInstance->show(pos.topLeft(), to);
  38. }
  39. void VideoWidget::activate()
  40. {
  41. if(videoInstance)
  42. videoInstance->playAudio();
  43. if(videoSoundHandle != -1)
  44. {
  45. CCS->soundh->setCallback(
  46. videoSoundHandle,
  47. [this]()
  48. {
  49. if(GH.windows().isTopWindow(this))
  50. this->videoSoundHandle = -1;
  51. }
  52. );
  53. }
  54. }
  55. void VideoWidget::deactivate()
  56. {
  57. CCS->soundh->stopSound(videoSoundHandle);
  58. }
  59. void VideoWidget::showAll(Canvas & to)
  60. {
  61. if(videoInstance)
  62. videoInstance->show(pos.topLeft(), to);
  63. }
  64. void VideoWidget::tick(uint32_t msPassed)
  65. {
  66. if(videoInstance)
  67. {
  68. videoInstance->tick(msPassed);
  69. if(videoInstance->videoEnded())
  70. videoInstance = CCS->videoh->open(next, false);
  71. }
  72. }