mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 05:49:56 +00:00
e197f5318b
conversion from 'const float' to 'int', possible loss of data conversion from 'double' to 'int', possible loss of data conversion from 'float' to 'int', possible loss of data
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "backgroundimage.hpp"
|
|
|
|
#include <MyGUI_Gui.h>
|
|
|
|
namespace MWGui
|
|
{
|
|
|
|
void BackgroundImage::setBackgroundImage (const std::string& image, bool fixedRatio, bool stretch)
|
|
{
|
|
if (mChild)
|
|
{
|
|
MyGUI::Gui::getInstance().destroyWidget(mChild);
|
|
mChild = NULL;
|
|
}
|
|
if (!stretch)
|
|
{
|
|
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, static_cast<int>(screenSize.width - screenSize.height * mAspect) / 2);
|
|
int topPadding = std::max(0, static_cast<int>(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();
|
|
}
|
|
|
|
|
|
}
|