1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:19:56 +00:00
openmw-tes3mp/apps/openmw/mwgui/videowidget.cpp

120 lines
2.5 KiB
C++
Raw Normal View History

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