1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include "image.hpp"
#include <MyGUI_RenderManager.h>
#include "resources.hpp"
namespace LuaUi
{
void LuaTileRect::_setAlign(const MyGUI::IntSize& _oldsize)
{
mCoord.set(0, 0, mCroppedParent->getWidth(), mCroppedParent->getHeight());
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)
mTileSize.width = 1e7;
if (mTileSize.height <= 0)
mTileSize.height = 1e7;
MyGUI::TileRect::_updateView();
}
void LuaImage::initialize()
{
changeWidgetSkin("LuaImage");
mTileRect = dynamic_cast<LuaTileRect*>(getSubWidgetMain());
WidgetExtension::initialize();
}
void LuaImage::updateProperties()
{
deleteAllItems();
TextureResource* resource = propertyValue<TextureResource*>("resource", nullptr);
MyGUI::IntCoord atlasCoord;
if (resource)
{
atlasCoord
= 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);
}
bool tileH = propertyValue("tileH", false);
bool tileV = propertyValue("tileV", false);
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;
mTileRect->updateSize(MyGUI::IntSize(tileH ? atlasCoord.width : 0, tileV ? atlasCoord.height : 0));
setImageTile(atlasCoord.size());
setImageCoord(atlasCoord);
setColour(propertyValue("color", MyGUI::Colour(1, 1, 1, 1)));
WidgetExtension::updateProperties();
}
}
|