Add option to stretch menu backgrounds/cutscenes to the whole screen

This commit is contained in:
scrawl 2015-01-28 00:02:05 +01:00
parent 6c08e05fc3
commit 9bcc84ceec
8 changed files with 43 additions and 27 deletions

View file

@ -5,14 +5,14 @@
namespace MWGui namespace MWGui
{ {
void BackgroundImage::setBackgroundImage (const std::string& image, bool fixedRatio, bool correct) void BackgroundImage::setBackgroundImage (const std::string& image, bool fixedRatio, bool stretch)
{ {
if (mChild) if (mChild)
{ {
MyGUI::Gui::getInstance().destroyWidget(mChild); MyGUI::Gui::getInstance().destroyWidget(mChild);
mChild = NULL; mChild = NULL;
} }
if (correct) if (!stretch)
{ {
setImageTexture("black.png"); setImageTexture("black.png");

View file

@ -18,9 +18,9 @@ namespace MWGui
/** /**
* @param fixedRatio Use a fixed ratio of 4:3, regardless of the image dimensions * @param fixedRatio Use a fixed ratio of 4:3, regardless of the image dimensions
* @param correct Add black bars? * @param stretch Stretch to fill the whole screen, or add black bars?
*/ */
void setBackgroundImage (const std::string& image, bool fixedRatio=true, bool correct=true); void setBackgroundImage (const std::string& image, bool fixedRatio=true, bool stretch=true);
virtual void setSize (const MyGUI::IntSize &_value); virtual void setSize (const MyGUI::IntSize &_value);
virtual void setCoord (const MyGUI::IntCoord &_value); virtual void setCoord (const MyGUI::IntCoord &_value);

View file

@ -149,7 +149,9 @@ namespace MWGui
Ogre::TextureManager::getSingleton ().load (randomSplash, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); Ogre::TextureManager::getSingleton ().load (randomSplash, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
// TODO: add option (filename pattern?) to use image aspect ratio instead of 4:3 // TODO: add option (filename pattern?) to use image aspect ratio instead of 4:3
mBackgroundImage->setBackgroundImage(randomSplash, true, true); // we can't do this by default, because the Morrowind splash screens are 1024x1024, but should be displayed as 4:3
bool stretch = Settings::Manager::getBool("stretch menu background", "GUI");
mBackgroundImage->setBackgroundImage(randomSplash, true, stretch);
} }
else else
std::cerr << "No loading screens found!" << std::endl; std::cerr << "No loading screens found!" << std::endl;

View file

@ -160,6 +160,8 @@ namespace MWGui
if (!show) if (!show)
return; return;
bool stretch = Settings::Manager::getBool("stretch menu background", "GUI");
if (mHasAnimatedMenu) if (mHasAnimatedMenu)
{ {
if (!mVideo) if (!mVideo)
@ -180,16 +182,7 @@ namespace MWGui
int screenHeight = viewSize.height; int screenHeight = viewSize.height;
mVideoBackground->setSize(screenWidth, screenHeight); mVideoBackground->setSize(screenWidth, screenHeight);
if (mVideo->getVideoHeight() > 0) mVideo->autoResize(stretch);
{
double imageaspect = static_cast<double>(mVideo->getVideoWidth())/mVideo->getVideoHeight();
int leftPadding = std::max(0.0, (screenWidth - screenHeight * imageaspect) / 2);
int topPadding = std::max(0.0, (screenHeight - screenWidth / imageaspect) / 2);
mVideo->setCoord(leftPadding, topPadding,
screenWidth - leftPadding*2, screenHeight - topPadding*2);
}
mVideo->setVisible(true); mVideo->setVisible(true);
} }
@ -199,7 +192,7 @@ namespace MWGui
{ {
mBackground = MyGUI::Gui::getInstance().createWidgetReal<BackgroundImage>("ImageBox", 0,0,1,1, mBackground = MyGUI::Gui::getInstance().createWidgetReal<BackgroundImage>("ImageBox", 0,0,1,1,
MyGUI::Align::Stretch, "Menu"); MyGUI::Align::Stretch, "Menu");
mBackground->setBackgroundImage("textures\\menu_morrowind.dds"); mBackground->setBackgroundImage("textures\\menu_morrowind.dds", true, stretch);
} }
mBackground->setVisible(true); mBackground->setVisible(true);
} }

View file

@ -2,6 +2,8 @@
#include <extern/ogre-ffmpeg-videoplayer/videoplayer.hpp> #include <extern/ogre-ffmpeg-videoplayer/videoplayer.hpp>
#include <MyGUI_RenderManager.h>
#include "../mwsound/movieaudiofactory.hpp" #include "../mwsound/movieaudiofactory.hpp"
namespace MWGui namespace MWGui
@ -46,4 +48,24 @@ bool VideoWidget::hasAudioStream()
return mPlayer->hasAudioStream(); 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.0, (screenSize.width - screenSize.height * imageaspect) / 2);
int topPadding = std::max(0.0, (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);
}
} }

View file

@ -35,6 +35,12 @@ namespace MWGui
/// Stop video and free resources (done automatically on destruction) /// Stop video and free resources (done automatically on destruction)
void stop(); void stop();
/// Adjust the coordinates of this video widget relative to its parent,
/// based on the dimensions of the playing video.
/// @param stretch Stretch the video to fill the whole screen? If false,
/// black bars may be added to fix the aspect ratio.
void autoResize (bool stretch);
private: private:
std::auto_ptr<Video::VideoPlayer> mPlayer; std::auto_ptr<Video::VideoPlayer> mPlayer;
}; };

View file

@ -1712,18 +1712,9 @@ namespace MWGui
void WindowManager::sizeVideo(int screenWidth, int screenHeight) void WindowManager::sizeVideo(int screenWidth, int screenHeight)
{ {
// Use black bars to correct aspect ratio // Use black bars to correct aspect ratio
bool stretch = Settings::Manager::getBool("stretch menu background", "GUI");
mVideoBackground->setSize(screenWidth, screenHeight); mVideoBackground->setSize(screenWidth, screenHeight);
mVideoWidget->autoResize(stretch);
if (mVideoWidget->getVideoHeight() > 0)
{
double imageaspect = static_cast<double>(mVideoWidget->getVideoWidth())/mVideoWidget->getVideoHeight();
int leftPadding = std::max(0.0, (screenWidth - screenHeight * imageaspect) / 2);
int topPadding = std::max(0.0, (screenHeight - screenWidth / imageaspect) / 2);
mVideoWidget->setCoord(leftPadding, topPadding,
screenWidth - leftPadding*2, screenHeight - topPadding*2);
}
} }
WindowModal* WindowManager::getCurrentModal() const WindowModal* WindowManager::getCurrentModal() const

View file

@ -45,6 +45,8 @@ subtitles = false
hit fader = true hit fader = true
werewolf overlay = true werewolf overlay = true
stretch menu background = false
[General] [General]
# Camera field of view # Camera field of view
field of view = 55 field of view = 55