1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +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;
}
double CVideoInstance::timeStamp()
{
return getCurrentFrameEndTime();
}
bool CVideoInstance::videoEnded()
{
return getCurrentFrame() == nullptr;

View File

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

View File

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

View File

@ -9,6 +9,7 @@
*/
#include "StdInc.h"
#include "VideoWidget.h"
#include "TextControls.h"
#include "../CGameInfo.h"
#include "../gui/CGuiHandler.h"
@ -33,11 +34,14 @@ VideoWidgetBase::~VideoWidgetBase() = default;
void VideoWidgetBase::playVideo(const VideoPath & fileToPlay)
{
OBJECT_CONSTRUCTION;
videoInstance = CCS->videoh->open(fileToPlay, scaleFactor);
if (videoInstance)
{
pos.w = videoInstance->size().x;
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)
@ -52,6 +56,8 @@ void VideoWidgetBase::show(Canvas & to)
{
if(videoInstance)
videoInstance->show(pos.topLeft(), to);
if(subTitle)
subTitle->showAll(to);
}
void VideoWidgetBase::loadAudio(const VideoPath & fileToPlay)
@ -107,6 +113,8 @@ void VideoWidgetBase::showAll(Canvas & to)
{
if(videoInstance)
videoInstance->show(pos.topLeft(), to);
if(subTitle)
subTitle->showAll(to);
}
void VideoWidgetBase::tick(uint32_t msPassed)
@ -122,6 +130,8 @@ void VideoWidgetBase::tick(uint32_t msPassed)
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)

View File

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