1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

basic subtitle rendering

This commit is contained in:
Laserlicht
2024-10-16 02:36:26 +02:00
parent 52e0899d6f
commit 4d46a2084d
5 changed files with 22 additions and 0 deletions

View File

@@ -316,6 +316,12 @@ bool CVideoInstance::loadNextFrame()
return true; return true;
} }
double CVideoInstance::timeStamp()
{
return getCurrentFrameEndTime();
}
bool CVideoInstance::videoEnded() bool CVideoInstance::videoEnded()
{ {
return getCurrentFrame() == nullptr; return getCurrentFrame() == nullptr;

View File

@@ -88,6 +88,7 @@ public:
void openVideo(); void openVideo();
bool loadNextFrame(); bool loadNextFrame();
double timeStamp() final;
bool videoEnded() final; bool videoEnded() final;
Point size() final; Point size() final;

View File

@@ -20,6 +20,9 @@ VCMI_LIB_NAMESPACE_END
class IVideoInstance class IVideoInstance
{ {
public: public:
/// Returns current video timestamp
virtual double timeStamp() = 0;
/// Returns true if video playback is over /// Returns true if video playback is over
virtual bool videoEnded() = 0; virtual bool videoEnded() = 0;

View File

@@ -9,6 +9,7 @@
*/ */
#include "StdInc.h" #include "StdInc.h"
#include "VideoWidget.h" #include "VideoWidget.h"
#include "TextControls.h"
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
@@ -33,11 +34,14 @@ VideoWidgetBase::~VideoWidgetBase() = default;
void VideoWidgetBase::playVideo(const VideoPath & fileToPlay) void VideoWidgetBase::playVideo(const VideoPath & fileToPlay)
{ {
OBJECT_CONSTRUCTION;
videoInstance = CCS->videoh->open(fileToPlay, scaleFactor); videoInstance = CCS->videoh->open(fileToPlay, scaleFactor);
if (videoInstance) if (videoInstance)
{ {
pos.w = videoInstance->size().x; pos.w = videoInstance->size().x;
pos.h = videoInstance->size().y; pos.h = videoInstance->size().y;
subTitle = std::make_unique<CMultiLineLabel>(Rect(0, (pos.h / 5) * 4, pos.w, pos.h / 5), EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTER, Colors::WHITE, "");
} }
if (playAudio) if (playAudio)
@@ -52,6 +56,8 @@ void VideoWidgetBase::show(Canvas & to)
{ {
if(videoInstance) if(videoInstance)
videoInstance->show(pos.topLeft(), to); videoInstance->show(pos.topLeft(), to);
if(subTitle)
subTitle->showAll(to);
} }
void VideoWidgetBase::loadAudio(const VideoPath & fileToPlay) void VideoWidgetBase::loadAudio(const VideoPath & fileToPlay)
@@ -107,6 +113,8 @@ void VideoWidgetBase::showAll(Canvas & to)
{ {
if(videoInstance) if(videoInstance)
videoInstance->show(pos.topLeft(), to); videoInstance->show(pos.topLeft(), to);
if(subTitle)
subTitle->showAll(to);
} }
void VideoWidgetBase::tick(uint32_t msPassed) void VideoWidgetBase::tick(uint32_t msPassed)
@@ -122,6 +130,8 @@ void VideoWidgetBase::tick(uint32_t msPassed)
onPlaybackFinished(); onPlaybackFinished();
} }
} }
if(subTitle && videoInstance)
subTitle->setText(std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()) + "\n" + std::to_string(msPassed) + "\n" + std::to_string(videoInstance->timeStamp()));
} }
VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio) VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio)

View File

@@ -14,10 +14,12 @@
#include "../lib/filesystem/ResourcePath.h" #include "../lib/filesystem/ResourcePath.h"
class IVideoInstance; class IVideoInstance;
class CMultiLineLabel;
class VideoWidgetBase : public CIntObject class VideoWidgetBase : public CIntObject
{ {
std::unique_ptr<IVideoInstance> videoInstance; std::unique_ptr<IVideoInstance> videoInstance;
std::unique_ptr<CMultiLineLabel> subTitle;
std::pair<std::unique_ptr<ui8[]>, si64> audioData = {nullptr, 0}; std::pair<std::unique_ptr<ui8[]>, si64> audioData = {nullptr, 0};
int audioHandle = -1; int audioHandle = -1;