Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
3.4 kB · 93 lines
C++
at master
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394#include "image.hpp"
#include <MyGUI_RenderManager.h>
#include <algorithm>
#include "resources.hpp"
namespace LuaUi{ void LuaTileRect::_setAlign(const MyGUI::IntSize& /*oldSize*/) { const int width = std::max(0, mCroppedParent->getWidth() - mPadding.mLeft - mPadding.mRight); const int height = std::max(0, mCroppedParent->getHeight() - mPadding.mTop - mPadding.mBottom);
mCoord.set(mPadding.mLeft, mPadding.mTop, width, height); 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 = 10000000; if (mTileSize.height <= 0) mTileSize.height = 10000000;
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();
mTileRect->updatePadding(mPadding); // _setAlign() normally runs when the parent is resized. Padding changes only // the TileRect's internal drawing area, so invoke the MyGUI hook explicitly to // recalculate the padded rectangle and refresh the tiled image mTileRect->_setAlign(widget()->getSize()); }
const std::vector<std::string_view>& LuaImage::allUsedProperties() const { static std::vector<std::string_view> usedProps = std::invoke([this] { std::vector<std::string_view> props = { "resource", "tileH", "tileV", "color" }; auto baseProps = WidgetExtension::allUsedProperties(); props.insert(props.end(), baseProps.begin(), baseProps.end()); return props; }); return usedProps; }}