2024-05-02 21:14:50 +02:00
|
|
|
/*
|
|
|
|
* TextControls.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "VideoWidget.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/WindowHandler.h"
|
2024-05-03 18:07:00 +02:00
|
|
|
#include "../media/ISoundPlayer.h"
|
|
|
|
#include "../media/IVideoPlayer.h"
|
|
|
|
#include "../render/Canvas.h"
|
2024-05-02 21:14:50 +02:00
|
|
|
|
|
|
|
VideoWidget::VideoWidget(const Point & position, const VideoPath & looped)
|
|
|
|
: VideoWidget(position, VideoPath(), looped)
|
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
addUsedEvents(TIME);
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped)
|
2024-05-03 18:07:00 +02:00
|
|
|
: current(prologue)
|
|
|
|
, next(looped)
|
|
|
|
, videoSoundHandle(-1)
|
2024-05-02 21:14:50 +02:00
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
if(current.empty())
|
|
|
|
videoInstance = CCS->videoh->open(looped, false);
|
|
|
|
else
|
|
|
|
videoInstance = CCS->videoh->open(current, false);
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoWidget::~VideoWidget() = default;
|
|
|
|
|
|
|
|
void VideoWidget::show(Canvas & to)
|
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
if(videoInstance)
|
|
|
|
videoInstance->show(pos.topLeft(), to);
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoWidget::activate()
|
|
|
|
{
|
2024-05-04 18:09:45 +02:00
|
|
|
// if(videoInstance)
|
|
|
|
// videoInstance->playAudio();
|
2024-05-02 21:14:50 +02:00
|
|
|
|
2024-05-03 18:07:00 +02:00
|
|
|
if(videoSoundHandle != -1)
|
2024-05-02 21:14:50 +02:00
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
CCS->soundh->setCallback(
|
|
|
|
videoSoundHandle,
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
if(GH.windows().isTopWindow(this))
|
|
|
|
this->videoSoundHandle = -1;
|
|
|
|
}
|
|
|
|
);
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoWidget::deactivate()
|
|
|
|
{
|
|
|
|
CCS->soundh->stopSound(videoSoundHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoWidget::showAll(Canvas & to)
|
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
if(videoInstance)
|
|
|
|
videoInstance->show(pos.topLeft(), to);
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoWidget::tick(uint32_t msPassed)
|
|
|
|
{
|
2024-05-03 18:07:00 +02:00
|
|
|
if(videoInstance)
|
|
|
|
{
|
|
|
|
videoInstance->tick(msPassed);
|
2024-05-02 21:14:50 +02:00
|
|
|
|
2024-05-03 18:07:00 +02:00
|
|
|
if(videoInstance->videoEnded())
|
|
|
|
videoInstance = CCS->videoh->open(next, false);
|
|
|
|
}
|
2024-05-02 21:14:50 +02:00
|
|
|
}
|