Consider aspect ratio for loading screen background
More consistent with the main menu.actorid
parent
1265131203
commit
f5810b8e1c
@ -0,0 +1,63 @@
|
||||
#include "backgroundimage.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
void BackgroundImage::setBackgroundImage (const std::string& image, bool fixedRatio, bool correct)
|
||||
{
|
||||
if (mChild)
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(mChild);
|
||||
mChild = NULL;
|
||||
}
|
||||
if (correct)
|
||||
{
|
||||
setImageTexture("black.png");
|
||||
|
||||
if (fixedRatio)
|
||||
mAspect = 4.0/3.0;
|
||||
else
|
||||
mAspect = 0; // TODO
|
||||
|
||||
mChild = createWidgetReal<MyGUI::ImageBox>("ImageBox",
|
||||
MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Default);
|
||||
mChild->setImageTexture(image);
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
mAspect = 0;
|
||||
setImageTexture(image);
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundImage::adjustSize()
|
||||
{
|
||||
if (mAspect == 0)
|
||||
return;
|
||||
|
||||
MyGUI::IntSize screenSize = getSize();
|
||||
|
||||
int leftPadding = std::max(0.0, (screenSize.width - screenSize.height * mAspect) / 2);
|
||||
int topPadding = std::max(0.0, (screenSize.height - screenSize.width / mAspect) / 2);
|
||||
|
||||
mChild->setCoord(leftPadding, topPadding, screenSize.width - leftPadding*2, screenSize.height - topPadding*2);
|
||||
}
|
||||
|
||||
void BackgroundImage::setSize (const MyGUI::IntSize& _value)
|
||||
{
|
||||
MyGUI::Widget::setSize (_value);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void BackgroundImage::setCoord (const MyGUI::IntCoord& _value)
|
||||
{
|
||||
MyGUI::Widget::setCoord (_value);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#ifndef OPENMW_MWGUI_BACKGROUNDIMAGE_H
|
||||
#define OPENMW_MWGUI_BACKGROUNDIMAGE_H
|
||||
|
||||
#include <MyGUI_ImageBox.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A variant of MyGUI::ImageBox with aspect ratio correction using black bars
|
||||
*/
|
||||
class BackgroundImage : public MyGUI::ImageBox
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(BackgroundImage)
|
||||
|
||||
public:
|
||||
BackgroundImage() : mChild(NULL), mAspect(0) {}
|
||||
|
||||
/**
|
||||
* @param fixedRatio Use a fixed ratio of 4:3, regardless of the image dimensions
|
||||
* @param correct Add black bars?
|
||||
*/
|
||||
void setBackgroundImage (const std::string& image, bool fixedRatio=true, bool correct=true);
|
||||
|
||||
virtual void setSize (const MyGUI::IntSize &_value);
|
||||
virtual void setCoord (const MyGUI::IntCoord &_value);
|
||||
|
||||
private:
|
||||
MyGUI::ImageBox* mChild;
|
||||
double mAspect;
|
||||
|
||||
void adjustSize();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue