VideoWidget.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * VideoWidget.h, 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. #pragma once
  11. #include "../gui/CIntObject.h"
  12. #include "../lib/filesystem/ResourcePath.h"
  13. class IVideoInstance;
  14. class VideoWidgetBase : public CIntObject
  15. {
  16. std::unique_ptr<IVideoInstance> videoInstance;
  17. std::pair<std::unique_ptr<ui8[]>, si64> audioData = {nullptr, 0};
  18. int audioHandle = -1;
  19. bool playAudio = false;
  20. float scaleFactor = 1.0;
  21. void loadAudio(const VideoPath & file);
  22. void startAudio();
  23. void stopAudio();
  24. protected:
  25. VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio);
  26. VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor);
  27. virtual void onPlaybackFinished() = 0;
  28. void playVideo(const VideoPath & video);
  29. public:
  30. ~VideoWidgetBase();
  31. void activate() override;
  32. void deactivate() override;
  33. void show(Canvas & to) override;
  34. void showAll(Canvas & to) override;
  35. void tick(uint32_t msPassed) override;
  36. void setPlaybackFinishedCallback(std::function<void()>);
  37. };
  38. class VideoWidget final: public VideoWidgetBase
  39. {
  40. VideoPath loopedVideo;
  41. void onPlaybackFinished() final;
  42. public:
  43. VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio);
  44. VideoWidget(const Point & position, const VideoPath & looped, bool playAudio);
  45. };
  46. class VideoWidgetOnce final: public VideoWidgetBase
  47. {
  48. std::function<void()> callback;
  49. void onPlaybackFinished() final;
  50. public:
  51. VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, const std::function<void()> & callback);
  52. VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor, const std::function<void()> & callback);
  53. };