mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
scaling
This commit is contained in:
parent
822fa61bf2
commit
8fc3fe3cc3
@ -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<CampaignRimVideo>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, [campaignScoreCalculator, statistic](){
|
||||
GH.windows().createAndPushWindow<CampaignRimVideo>(ourCampaign->getOutroVideo(), ourCampaign->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : ourCampaign->getVideoRim(), false, 1, [campaignScoreCalculator, statistic](){
|
||||
GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
|
||||
});
|
||||
}
|
||||
|
@ -207,10 +207,10 @@ void ApplyOnLobbyScreenNetPackVisitor::visitLobbyUpdateState(LobbyUpdateState &
|
||||
{
|
||||
auto bonusSel = std::make_shared<CBonusSelection>();
|
||||
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<CampaignRimVideo>(handler.si->campState->getIntroVideo(), handler.si->campState->getVideoRim().empty() ? ImagePath::builtin("INTRORIM") : handler.si->campState->getVideoRim(), false, [bonusSel](){
|
||||
GH.windows().createAndPushWindow<CampaignRimVideo>(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);
|
||||
|
@ -59,7 +59,7 @@
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
|
||||
|
||||
CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, std::function<void()> closeCb)
|
||||
CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void()> closeCb)
|
||||
: CWindowObject(BORDERED), closeCb(closeCb)
|
||||
{
|
||||
OBJECT_CONSTRUCTION;
|
||||
@ -73,8 +73,8 @@ CampaignRimVideo::CampaignRimVideo(VideoPath video, ImagePath rim, bool showBack
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(0, 0), video, true, [this](){ exit(); });
|
||||
pos = center(Rect(0, 0, videoPlayer->size().x, videoPlayer->size().y));
|
||||
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(0, 0), video, true, scaleFactor, [this](){ exit(); });
|
||||
pos = center(Rect(0, 0, videoPlayer->pos.w, videoPlayer->pos.h));
|
||||
}
|
||||
|
||||
if(showBackground)
|
||||
|
@ -43,7 +43,7 @@ class CampaignRimVideo : public CWindowObject
|
||||
|
||||
void exit();
|
||||
public:
|
||||
CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, std::function<void()> closeCb);
|
||||
CampaignRimVideo(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void()> closeCb);
|
||||
|
||||
void clickPressed(const Point & cursorPosition) override;
|
||||
void keyPressed(EShortcut key) override;
|
||||
|
@ -295,15 +295,19 @@ CMainMenu::CMainMenu(bool playVideoIntro)
|
||||
|
||||
if(playVideoIntro)
|
||||
{
|
||||
auto playVideo = [](std::string video, bool rim, std::function<void()> cb){
|
||||
if(CCS->videoh->open(VideoPath::builtin(video), Point(0, 0)))
|
||||
GH.windows().createAndPushWindow<CampaignRimVideo>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, [cb](){ cb(); });
|
||||
auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function<void()> cb){
|
||||
if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor))
|
||||
GH.windows().createAndPushWindow<CampaignRimVideo>(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);
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
}
|
||||
|
||||
/// Load video from specified path
|
||||
std::unique_ptr<IVideoInstance> open(const VideoPath & name, const Point & scale) override
|
||||
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) override
|
||||
{
|
||||
return nullptr;
|
||||
};
|
||||
|
@ -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<IVideoInstance> CVideoPlayer::open(const VideoPath & name, const Point & scale)
|
||||
std::unique_ptr<IVideoInstance> CVideoPlayer::open(const VideoPath & name, float scaleFactor)
|
||||
{
|
||||
auto result = std::make_unique<CVideoInstance>();
|
||||
|
||||
@ -646,7 +635,7 @@ std::unique_ptr<IVideoInstance> 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;
|
||||
|
@ -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<IVideoInstance> open(const VideoPath & name, const Point & scale) final;
|
||||
std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) final;
|
||||
std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) final;
|
||||
};
|
||||
|
||||
|
@ -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<IVideoInstance> open(const VideoPath & name, const Point & scale) = 0;
|
||||
virtual std::unique_ptr<IVideoInstance> open(const VideoPath & name, float scaleFactor) = 0;
|
||||
|
||||
/// Extracts audio data from provided video in wav format
|
||||
virtual std::pair<std::unique_ptr<ui8[]>, si64> getAudio(const VideoPath & videoToOpen) = 0;
|
||||
|
@ -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<void()> & callback)
|
||||
: VideoWidgetBase(position, video, playAudio, scaleFactor)
|
||||
, callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
void VideoWidgetOnce::onPlaybackFinished()
|
||||
{
|
||||
callback();
|
||||
|
@ -22,6 +22,7 @@ class VideoWidgetBase : public CIntObject
|
||||
std::pair<std::unique_ptr<ui8[]>, 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<void()>);
|
||||
};
|
||||
|
||||
@ -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<void()> & callback);
|
||||
VideoWidgetOnce(const Point & position, const VideoPath & video, bool playAudio, float scaleFactor, const std::function<void()> & callback);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user