diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 681d3e84c..31e891cba 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -708,10 +708,10 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared else { CMM->openCampaignScreen(ourCampaign->campaignSet); - if(!ourCampaign->getOutroVideo().empty() && CCS->videoh->open(ourCampaign->getOutroVideo(), Point(0, 0))) + if(!ourCampaign->getOutroVideo().empty() && CCS->videoh->open(ourCampaign->getOutroVideo(), 1)) { CCS->musich->stopMusic(); - GH.windows().createAndPushWindow(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, [campaignScoreCalculator, statistic](){ + GH.windows().createAndPushWindow(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](){ GH.windows().createAndPushWindow(true, *campaignScoreCalculator, statistic); }); } diff --git a/client/NetPacksLobbyClient.cpp b/client/NetPacksLobbyClient.cpp index b01b71862..5c7822d97 100644 --- a/client/NetPacksLobbyClient.cpp +++ b/client/NetPacksLobbyClient.cpp @@ -207,10 +207,10 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState & { auto bonusSel = std::make_shared(); lobby->bonusSel = bonusSel; - if(!handler.si->campState->conqueredScenarios().size() && !handler.si->campState->getIntroVideo().empty() && CCS->videoh->open(handler.si->campState->getIntroVideo(), Point(0, 0))) + if(!handler.si->campState->conqueredScenarios().size() && !handler.si->campState->getIntroVideo().empty() && CCS->videoh->open(handler.si->campState->getIntroVideo(), 1)) { CCS->musich->stopMusic(); - GH.windows().createAndPushWindow(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, [bonusSel](){ + GH.windows().createAndPushWindow(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, 1, [bonusSel](){ if(!CSH->si->campState->getMusic().empty()) CCS->musich->playMusic(CSH->si->campState->getMusic(), true, false); GH.windows().pushWindow(bonusSel); diff --git a/client/lobby/CBonusSelection.cpp b/client/lobby/CBonusSelection.cpp index 5d1c56a2b..b6c5afc87 100644 --- a/client/lobby/CBonusSelection.cpp +++ b/client/lobby/CBonusSelection.cpp @@ -59,7 +59,7 @@ #include "../../lib/mapObjects/CGHeroInstance.h" -CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, std::function closeCb) +CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function closeCb) : CWindowObject(BORDERED), closeCb(closeCb) { OBJECT_CONSTRUCTION; @@ -73,8 +73,8 @@ CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBack } else { - videoPlayer = std::make_shared(Point(0, 0), video, true, [this](){ exit(); }); - pos = center(Rect(0, 0, videoPlayer->size().x, videoPlayer->size().y)); + videoPlayer = std::make_shared(Point(0, 0), video, true, scaleFactor, [this](){ exit(); }); + pos = center(Rect(0, 0, videoPlayer->pos.w, videoPlayer->pos.h)); } if(showBackground) diff --git a/client/lobby/CBonusSelection.h b/client/lobby/CBonusSelection.h index 3451e7f1c..13223f321 100644 --- a/client/lobby/CBonusSelection.h +++ b/client/lobby/CBonusSelection.h @@ -43,7 +43,7 @@ class CampaignRimVideo : public CWindowObject void exit(); public: - CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, std::function closeCb); + CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function closeCb); void clickPressed(const Point & cursorPosition) override; void keyPressed(EShortcut key) override; diff --git a/client/mainmenu/CMainMenu.cpp b/client/mainmenu/CMainMenu.cpp index df9b82493..835157d59 100644 --- a/client/mainmenu/CMainMenu.cpp +++ b/client/mainmenu/CMainMenu.cpp @@ -295,15 +295,19 @@ CMainMenu::CMainMenu(bool playVideoIntro) if(playVideoIntro) { - auto playVideo = [](std::string video, bool rim, std::function cb){ - if(CCS->videoh->open(VideoPath::builtin(video), Point(0, 0))) - GH.windows().createAndPushWindow(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, [cb](){ cb(); }); + auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function cb){ + if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor)) + GH.windows().createAndPushWindow(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](){ cb(); }); else cb(); }; - playVideo("3DOLOGO.SMK", false, [playVideo](){ playVideo("NWCLOGO.SMK", false, [playVideo](){ playVideo("H3INTRO.SMK", true, [](){ - CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true); - }); }); }); + playVideo("3DOLOGO.SMK", false, 1, [playVideo](){ + playVideo("NWCLOGO.SMK", false, 2, [playVideo](){ + playVideo("H3INTRO.SMK", true, 1, [](){ + CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true); + }); + }); + }); } else CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true); diff --git a/client/media/CEmptyVideoPlayer.h b/client/media/CEmptyVideoPlayer.h index fcc191421..619591c9b 100644 --- a/client/media/CEmptyVideoPlayer.h +++ b/client/media/CEmptyVideoPlayer.h @@ -19,7 +19,7 @@ public: } /// Load video from specified path - std::unique_ptr open(const VideoPath & name, const Point & scale) override + std::unique_ptr open(const VideoPath & name, float scaleFactor) override { return nullptr; }; diff --git a/client/media/CVideoHandler.cpp b/client/media/CVideoHandler.cpp index 45c1c1bdf..3ee1cca55 100644 --- a/client/media/CVideoHandler.cpp +++ b/client/media/CVideoHandler.cpp @@ -173,18 +173,10 @@ void CVideoInstance::openVideo() openCodec(findVideoStream()); } -void CVideoInstance::prepareOutput(Point scale, bool useTextureOutput) +void CVideoInstance::prepareOutput(float scaleFactor, bool useTextureOutput) { //setup scaling - if(scale.x > 0 && scale.y > 0) - { - dimensions.x = scale.x * GH.screenHandler().getScalingFactor(); - dimensions.y = scale.y * GH.screenHandler().getScalingFactor(); - } - else - { - dimensions = Point(getCodecContext()->width, getCodecContext()->height) * GH.screenHandler().getScalingFactor(); - } + dimensions = Point(getCodecContext()->width * scaleFactor, getCodecContext()->height * scaleFactor) * GH.screenHandler().getScalingFactor(); // Allocate a place to put our YUV image on that screen if (useTextureOutput) @@ -352,10 +344,7 @@ FFMpegStream::~FFMpegStream() Point CVideoInstance::size() { - if(!getCurrentFrame()) - throw std::runtime_error("Invalid video frame!"); - - return Point(getCurrentFrame()->width, getCurrentFrame()->height); + return dimensions; } void CVideoInstance::show(const Point & position, Canvas & canvas) @@ -587,7 +576,7 @@ bool CVideoPlayer::openAndPlayVideoImpl(const VideoPath & name, const Point & po return true; instance.openVideo(); - instance.prepareOutput(Point(0, 0), true); + instance.prepareOutput(1, true); auto lastTimePoint = boost::chrono::steady_clock::now(); @@ -638,7 +627,7 @@ void CVideoPlayer::playSpellbookAnimation(const VideoPath & name, const Point & openAndPlayVideoImpl(name, position * GH.screenHandler().getScalingFactor(), false, false); } -std::unique_ptr CVideoPlayer::open(const VideoPath & name, const Point & scale) +std::unique_ptr CVideoPlayer::open(const VideoPath & name, float scaleFactor) { auto result = std::make_unique(); @@ -646,7 +635,7 @@ std::unique_ptr CVideoPlayer::open(const VideoPath & name, const return nullptr; result->openVideo(); - result->prepareOutput(scale, false); + result->prepareOutput(scaleFactor, false); result->loadNextFrame(); // prepare 1st frame return result; diff --git a/client/media/CVideoHandler.h b/client/media/CVideoHandler.h index 11bfa844a..d40582b62 100644 --- a/client/media/CVideoHandler.h +++ b/client/media/CVideoHandler.h @@ -80,7 +80,7 @@ class CVideoInstance final : public IVideoInstance, public FFMpegStream /// video playback current progress, in seconds double frameTime = 0.0; - void prepareOutput(Point scale, bool useTextureOutput); + void prepareOutput(float scaleFactor, bool useTextureOutput); public: ~CVideoInstance(); @@ -102,7 +102,7 @@ class CVideoPlayer final : public IVideoPlayer public: void playSpellbookAnimation(const VideoPath & name, const Point & position) final; - std::unique_ptr open(const VideoPath & name, const Point & scale) final; + std::unique_ptr open(const VideoPath & name, float scaleFactor) final; std::pair, si64> getAudio(const VideoPath & videoToOpen) final; }; diff --git a/client/media/IVideoPlayer.h b/client/media/IVideoPlayer.h index 4c4c3b5d3..2c979a088 100644 --- a/client/media/IVideoPlayer.h +++ b/client/media/IVideoPlayer.h @@ -42,7 +42,7 @@ public: virtual void playSpellbookAnimation(const VideoPath & name, const Point & position) = 0; /// Load video from specified path. Returns nullptr on failure - virtual std::unique_ptr open(const VideoPath & name, const Point & scale) = 0; + virtual std::unique_ptr open(const VideoPath & name, float scaleFactor) = 0; /// Extracts audio data from provided video in wav format virtual std::pair, si64> getAudio(const VideoPath & videoToOpen) = 0; diff --git a/client/widgets/VideoWidget.cpp b/client/widgets/VideoWidget.cpp index a6281de6e..0fa6570cf 100644 --- a/client/widgets/VideoWidget.cpp +++ b/client/widgets/VideoWidget.cpp @@ -17,7 +17,12 @@ #include "../render/Canvas.h" VideoWidgetBase::VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio) - : playAudio(playAudio) + : VideoWidgetBase(position, video, playAudio, 1.0) +{ +} + +VideoWidgetBase::VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor) + : playAudio(playAudio), scaleFactor(scaleFactor) { addUsedEvents(TIME); pos += position; @@ -28,7 +33,7 @@ VideoWidgetBase::~VideoWidgetBase() = default; void VideoWidgetBase::playVideo(const VideoPath & fileToPlay) { - videoInstance = CCS->videoh->open(fileToPlay, Point(0, 0)); + videoInstance = CCS->videoh->open(fileToPlay, scaleFactor); if (videoInstance) { pos.w = videoInstance->size().x; @@ -119,11 +124,6 @@ void VideoWidgetBase::tick(uint32_t msPassed) } } -Point VideoWidgetBase::size() -{ - return videoInstance->size(); -} - VideoWidget::VideoWidget(const Point & position, const VideoPath & prologue, const VideoPath & looped, bool playAudio) : VideoWidgetBase(position, prologue, playAudio) , loopedVideo(looped) @@ -147,6 +147,12 @@ VideoWidgetOnce::VideoWidgetOnce(const Point & position, const VideoPath & video { } +VideoWidgetOnce::VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor, const std::function & callback) + : VideoWidgetBase(position, video, playAudio, scaleFactor) + , callback(callback) +{ +} + void VideoWidgetOnce::onPlaybackFinished() { callback(); diff --git a/client/widgets/VideoWidget.h b/client/widgets/VideoWidget.h index 22bf10457..b0264d58d 100644 --- a/client/widgets/VideoWidget.h +++ b/client/widgets/VideoWidget.h @@ -22,6 +22,7 @@ class VideoWidgetBase : public CIntObject std::pair, si64> audioData = {nullptr, 0}; int audioHandle = -1; bool playAudio = false; + float scaleFactor = 1.0; void loadAudio(const VideoPath & file); void startAudio(); @@ -29,6 +30,7 @@ class VideoWidgetBase : public CIntObject protected: VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio); + VideoWidgetBase(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor); virtual void onPlaybackFinished() = 0; void playVideo(const VideoPath & video); @@ -42,8 +44,6 @@ public: void showAll(Canvas & to) override; void tick(uint32_t msPassed) override; - Point size(); - void setPlaybackFinishedCallback(std::function); }; @@ -64,4 +64,5 @@ class VideoWidgetOnce final: public VideoWidgetBase void onPlaybackFinished() final; public: VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, const std::function & callback); + VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor, const std::function & callback); };