2024-05-02 21:14:50 +02:00
|
|
|
/*
|
|
|
|
* VideoWidget.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../gui/CIntObject.h"
|
|
|
|
|
|
|
|
#include "../lib/filesystem/ResourcePath.h"
|
2024-10-16 22:37:18 +02:00
|
|
|
#include "../lib/json/JsonNode.h"
|
2024-05-02 21:14:50 +02:00
|
|
|
|
2024-12-07 17:37:03 +02:00
|
|
|
class IVideoHolder;
|
2024-05-03 18:07:00 +02:00
|
|
|
class IVideoInstance;
|
2024-10-16 02:36:26 +02:00
|
|
|
class CMultiLineLabel;
|
2024-05-03 18:07:00 +02:00
|
|
|
|
2024-05-15 18:34:23 +02:00
|
|
|
class VideoWidgetBase : public CIntObject
|
2024-05-02 21:14:50 +02:00
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
std::unique_ptr<IVideoInstance> videoInstance;
|
2024-10-16 02:36:26 +02:00
|
|
|
std::unique_ptr<CMultiLineLabel> subTitle;
|
2024-05-03 18:07:00 +02:00
|
|
|
|
2024-05-15 18:34:23 +02:00
|
|
|
std::pair<std::unique_ptr<ui8[]>, si64> audioData = {nullptr, 0};
|
|
|
|
int audioHandle = -1;
|
|
|
|
bool playAudio = false;
|
2024-09-12 23:06:33 +02:00
|
|
|
float scaleFactor = 1.0;
|
2024-10-16 22:37:18 +02:00
|
|
|
JsonNode subTitleData;
|
2024-05-02 21:14:50 +02:00
|
|
|
|
2024-05-15 18:34:23 +02:00
|
|
|
void loadAudio(const VideoPath & file);
|
|
|
|
void startAudio();
|
|
|
|
void stopAudio();
|
2024-10-16 03:48:14 +02:00
|
|
|
std::string getSubTitleLine(double timestamp);
|
2024-05-15 18:34:23 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio);
|
2024-09-12 23:06:33 +02:00
|
|
|
VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor);
|
2024-05-15 18:34:23 +02:00
|
|
|
|
|
|
|
virtual void onPlaybackFinished() = 0;
|
|
|
|
void playVideo(const VideoPath & video);
|
2024-05-03 18:07:00 +02:00
|
|
|
|
2024-05-02 21:14:50 +02:00
|
|
|
public:
|
2024-05-15 18:34:23 +02:00
|
|
|
~VideoWidgetBase();
|
2024-05-02 21:14:50 +02:00
|
|
|
|
|
|
|
void activate() override;
|
|
|
|
void deactivate() override;
|
|
|
|
void show(Canvas & to) override;
|
|
|
|
void showAll(Canvas & to) override;
|
|
|
|
void tick(uint32_t msPassed) override;
|
2024-05-15 18:34:23 +02:00
|
|
|
|
|
|
|
void setPlaybackFinishedCallback(std::function<void()>);
|
|
|
|
};
|
|
|
|
|
|
|
|
class VideoWidget final: public VideoWidgetBase
|
|
|
|
{
|
|
|
|
VideoPath loopedVideo;
|
|
|
|
|
|
|
|
void onPlaybackFinished() final;
|
|
|
|
public:
|
|
|
|
VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio);
|
|
|
|
VideoWidget(const Point & position, const VideoPath & looped, bool playAudio);
|
|
|
|
};
|
|
|
|
|
|
|
|
class VideoWidgetOnce final: public VideoWidgetBase
|
|
|
|
{
|
2024-12-07 17:37:03 +02:00
|
|
|
IVideoHolder * owner;
|
2024-05-15 18:34:23 +02:00
|
|
|
|
|
|
|
void onPlaybackFinished() final;
|
|
|
|
public:
|
2024-12-07 17:37:03 +02:00
|
|
|
VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, IVideoHolder * owner);
|
|
|
|
VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor, IVideoHolder * owner);
|
2024-05-02 21:14:50 +02:00
|
|
|
};
|