1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 09:32:45 +00:00
OpenMW/apps/openmw/mwgui/videowidget.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
2.8 KiB
C++
Raw Normal View History

#include "videowidget.hpp"
2015-05-01 03:03:44 +02:00
#include <extern/osg-ffmpeg-videoplayer/videoplayer.hpp>
2015-01-10 01:00:52 +01:00
#include <MyGUI_RenderManager.h>
2015-05-01 03:03:44 +02:00
#include <osg/Texture2D>
2018-08-14 23:05:43 +04:00
#include <components/debug/debuglog.hpp>
2015-05-01 03:03:44 +02:00
#include <components/myguiplatform/myguitexture.hpp>
#include <components/vfs/manager.hpp>
#include "../mwsound/movieaudiofactory.hpp"
namespace MWGui
{
VideoWidget::VideoWidget()
2018-10-09 10:21:12 +04:00
: mVFS(nullptr)
{
2022-05-29 13:24:48 +02:00
mPlayer = std::make_unique<Video::VideoPlayer>();
setNeedKeyFocus(true);
2015-05-01 03:03:44 +02:00
}
VideoWidget::~VideoWidget() = default;
2015-05-01 03:03:44 +02:00
2015-05-15 00:23:31 +02:00
void VideoWidget::setVFS(const VFS::Manager* vfs)
{
mVFS = vfs;
}
2022-09-22 21:26:05 +03:00
2015-05-15 00:23:31 +02:00
void VideoWidget::playVideo(const std::string& video)
{
2018-08-14 23:05:43 +04:00
mPlayer->setAudioFactory(new MWSound::MovieAudioFactory());
2015-05-15 00:23:31 +02:00
2022-04-15 02:15:39 +02:00
Files::IStreamPtr videoStream;
2022-09-22 21:26:05 +03:00
try
{
2022-04-15 02:15:39 +02:00
videoStream = mVFS->get(video);
2022-09-22 21:26:05 +03:00
}
2022-04-15 02:15:39 +02:00
catch (std::exception& e)
2022-09-22 21:26:05 +03:00
{
2022-04-15 02:15:39 +02:00
Log(Debug::Error) << "Failed to open video: " << e.what();
2022-09-22 21:26:05 +03:00
return;
}
2015-05-01 03:03:44 +02:00
mPlayer->playVideo(std::move(videoStream), video);
2022-05-29 13:24:48 +02:00
osg::ref_ptr<osg::Texture2D> texture = mPlayer->getVideoTexture();
if (!texture)
2022-09-22 21:26:05 +03:00
return;
2015-05-01 03:03:44 +02:00
mTexture = std::make_unique<osgMyGUI::OSGTexture>(texture);
2015-05-01 03:03:44 +02:00
setRenderItemTexture(mTexture.get());
getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 1.f, 1.f, 0.f));
}
int VideoWidget::getVideoWidth()
{
2015-05-01 03:03:44 +02:00
return mPlayer->getVideoWidth();
}
int VideoWidget::getVideoHeight()
{
2015-05-01 03:03:44 +02:00
return mPlayer->getVideoHeight();
}
bool VideoWidget::update()
{
2015-05-01 03:03:44 +02:00
return mPlayer->update();
}
void VideoWidget::stop()
{
mPlayer->close();
}
void VideoWidget::pause()
{
mPlayer->pause();
}
void VideoWidget::resume()
{
mPlayer->play();
}
bool VideoWidget::isPaused() const
{
2015-05-01 03:03:44 +02:00
return mPlayer->isPaused();
}
bool VideoWidget::hasAudioStream()
{
return mPlayer->hasAudioStream();
2022-09-22 21:26:05 +03:00
}
void VideoWidget::autoResize(bool stretch)
{
MyGUI::IntSize screenSize = MyGUI::RenderManager::getInstance().getViewSize();
if (getParent())
screenSize = getParent()->getSize();
2022-09-22 21:26:05 +03:00
if (getVideoHeight() > 0 && !stretch)
2022-09-22 21:26:05 +03:00
{
double imageaspect = static_cast<double>(getVideoWidth()) / getVideoHeight();
int leftPadding = std::max(0, static_cast<int>(screenSize.width - screenSize.height * imageaspect) / 2);
int topPadding = std::max(0, static_cast<int>(screenSize.height - screenSize.width / imageaspect) / 2);
setCoord(leftPadding, topPadding, screenSize.width - leftPadding * 2, screenSize.height - topPadding * 2);
2022-09-22 21:26:05 +03:00
}
else
setCoord(0, 0, screenSize.width, screenSize.height);
}
}