1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/components/lua_ui/image.cpp

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

72 lines
2.3 KiB
C++
Raw Normal View History

2022-01-28 09:31:45 +00:00
#include "image.hpp"
#include <MyGUI_RenderManager.h>
#include "resources.hpp"
2022-01-28 09:31:45 +00:00
namespace LuaUi
{
void LuaTileRect::_setAlign(const MyGUI::IntSize& _oldsize)
{
2023-10-26 18:46:34 +00:00
mCoord.set(0, 0, mCroppedParent->getWidth(), mCroppedParent->getHeight());
2022-01-28 09:31:45 +00:00
mTileSize = mSetTileSize;
// zero tilesize stands for not tiling
if (mTileSize.width == 0)
mTileSize.width = mCoord.width;
if (mTileSize.height == 0)
mTileSize.height = mCoord.height;
// mCoord could be zero, prevent division by 0
// use arbitrary large numbers to prevent performance issues
if (mTileSize.width <= 0)
2022-01-28 09:31:45 +00:00
mTileSize.width = 1e7;
if (mTileSize.height <= 0)
2022-01-28 09:31:45 +00:00
mTileSize.height = 1e7;
2023-10-26 18:46:34 +00:00
MyGUI::TileRect::_updateView();
2022-01-28 09:31:45 +00:00
}
void LuaImage::initialize()
2022-01-28 09:31:45 +00:00
{
changeWidgetSkin("LuaImage");
mTileRect = dynamic_cast<LuaTileRect*>(getSubWidgetMain());
2022-05-14 10:27:30 +00:00
WidgetExtension::initialize();
2022-01-28 09:31:45 +00:00
}
void LuaImage::updateProperties()
{
2022-03-19 20:26:02 +00:00
deleteAllItems();
TextureResource* resource = propertyValue<TextureResource*>("resource", nullptr);
MyGUI::IntCoord atlasCoord;
if (resource)
{
atlasCoord
2022-02-26 11:10:55 +00:00
= MyGUI::IntCoord(static_cast<int>(resource->mOffset.x()), static_cast<int>(resource->mOffset.y()),
static_cast<int>(resource->mSize.x()), static_cast<int>(resource->mSize.y()));
setImageTexture(resource->mPath);
}
2022-01-28 09:31:45 +00:00
bool tileH = propertyValue("tileH", false);
bool tileV = propertyValue("tileV", false);
2022-01-28 09:31:45 +00:00
MyGUI::ITexture* texture = MyGUI::RenderManager::getInstance().getTexture(_getTextureName());
MyGUI::IntSize textureSize;
if (texture != nullptr)
textureSize = MyGUI::IntSize(texture->getWidth(), texture->getHeight());
if (atlasCoord.width == 0)
atlasCoord.width = textureSize.width;
if (atlasCoord.height == 0)
atlasCoord.height = textureSize.height;
2023-10-26 18:46:34 +00:00
mTileRect->updateSize(MyGUI::IntSize(tileH ? atlasCoord.width : 0, tileV ? atlasCoord.height : 0));
setImageTile(atlasCoord.size());
setImageCoord(atlasCoord);
2022-03-22 05:00:32 +00:00
setColour(propertyValue("color", MyGUI::Colour(1, 1, 1, 1)));
2022-01-28 09:31:45 +00:00
WidgetExtension::updateProperties();
}
}