mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
Render text and images correctly in templates with slots
This commit is contained in:
parent
e092ee2624
commit
fc50724f5c
9 changed files with 30 additions and 20 deletions
|
@ -283,7 +283,7 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
LuaUi::TextureData data;
|
LuaUi::TextureData data;
|
||||||
sol::object path = LuaUtil::getFieldOrNil(options, "path");
|
sol::object path = LuaUtil::getFieldOrNil(options, "path");
|
||||||
if (path.is<std::string>() and !path.as<std::string>().empty())
|
if (path.is<std::string>() && !path.as<std::string>().empty())
|
||||||
data.mPath = path.as<std::string>();
|
data.mPath = path.as<std::string>();
|
||||||
else
|
else
|
||||||
throw sol::error("Invalid texture path");
|
throw sol::error("Invalid texture path");
|
||||||
|
|
|
@ -130,8 +130,7 @@ namespace LuaUi
|
||||||
|
|
||||||
void updateWidget(WidgetExtension* ext, const sol::table& layout)
|
void updateWidget(WidgetExtension* ext, const sol::table& layout)
|
||||||
{
|
{
|
||||||
ext->resetSlot(); // otherwise if template gets changed, all non-template children will get destroyed
|
ext->reset();
|
||||||
|
|
||||||
ext->setLayout(layout);
|
ext->setLayout(layout);
|
||||||
ext->setExternal(layout.get<sol::object>(LayoutKeys::external));
|
ext->setExternal(layout.get<sol::object>(LayoutKeys::external));
|
||||||
setTemplate(ext, layout.get<sol::object>(LayoutKeys::templateLayout));
|
setTemplate(ext, layout.get<sol::object>(LayoutKeys::templateLayout));
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace LuaUi
|
||||||
mTileSize.height = 1e7;
|
mTileSize.height = 1e7;
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaImage::LuaImage()
|
void LuaImage::initialize()
|
||||||
{
|
{
|
||||||
changeWidgetSkin("LuaImage");
|
changeWidgetSkin("LuaImage");
|
||||||
mTileRect = dynamic_cast<LuaTileRect*>(getSubWidgetMain());
|
mTileRect = dynamic_cast<LuaTileRect*>(getSubWidgetMain());
|
||||||
|
|
|
@ -25,10 +25,8 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
MYGUI_RTTI_DERIVED(LuaImage)
|
MYGUI_RTTI_DERIVED(LuaImage)
|
||||||
|
|
||||||
public:
|
|
||||||
LuaImage();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void initialize() override;
|
||||||
void updateProperties() override;
|
void updateProperties() override;
|
||||||
LuaTileRect* mTileRect;
|
LuaTileRect* mTileRect;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace LuaUi
|
||||||
|
|
||||||
void LuaText::initialize()
|
void LuaText::initialize()
|
||||||
{
|
{
|
||||||
changeWidgetSkin("SandText");
|
changeWidgetSkin("LuaText");
|
||||||
setEditStatic(true);
|
setEditStatic(true);
|
||||||
setVisibleHScroll(false);
|
setVisibleHScroll(false);
|
||||||
setVisibleVScroll(false);
|
setVisibleVScroll(false);
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
void LuaTextEdit::initialize()
|
void LuaTextEdit::initialize()
|
||||||
{
|
{
|
||||||
changeWidgetSkin("LuaTextEdit");
|
changeWidgetSkin("LuaText");
|
||||||
|
|
||||||
eventEditTextChange += MyGUI::newDelegate(this, &LuaTextEdit::textChange);
|
eventEditTextChange += MyGUI::newDelegate(this, &LuaTextEdit::textChange);
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,8 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
mLua = lua;
|
mLua = lua;
|
||||||
mWidget = self;
|
mWidget = self;
|
||||||
updateTemplate();
|
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
updateTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExtension::initialize()
|
void WidgetExtension::initialize()
|
||||||
|
@ -72,6 +71,13 @@ namespace LuaUi
|
||||||
w->deinitialize();
|
w->deinitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WidgetExtension::reset()
|
||||||
|
{
|
||||||
|
// detach all children from the slot widget, in case it gets destroyed
|
||||||
|
for (auto& w: mChildren)
|
||||||
|
w->widget()->detachFromWidget();
|
||||||
|
}
|
||||||
|
|
||||||
void WidgetExtension::attach(WidgetExtension* ext)
|
void WidgetExtension::attach(WidgetExtension* ext)
|
||||||
{
|
{
|
||||||
ext->mParent = this;
|
ext->mParent = this;
|
||||||
|
@ -182,8 +188,15 @@ namespace LuaUi
|
||||||
else
|
else
|
||||||
mSlot = slot->mSlot;
|
mSlot = slot->mSlot;
|
||||||
if (mSlot != oldSlot)
|
if (mSlot != oldSlot)
|
||||||
for (WidgetExtension* w : mChildren)
|
{
|
||||||
attach(w);
|
MyGUI::IntSize slotSize = mSlot->widget()->getSize();
|
||||||
|
MyGUI::IntPoint slotPosition = mSlot->widget()->getAbsolutePosition() - widget()->getAbsolutePosition();
|
||||||
|
MyGUI::IntCoord slotCoord(slotPosition, slotSize);
|
||||||
|
if (mWidget->getSubWidgetMain())
|
||||||
|
mWidget->getSubWidgetMain()->setCoord(slotCoord);
|
||||||
|
if (mWidget->getSubWidgetText())
|
||||||
|
mWidget->getSubWidgetText()->setCoord(slotCoord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExtension::setCallback(const std::string& name, const LuaUtil::Callback& callback)
|
void WidgetExtension::setCallback(const std::string& name, const LuaUtil::Callback& callback)
|
||||||
|
|
|
@ -28,6 +28,9 @@ namespace LuaUi
|
||||||
virtual void deinitialize();
|
virtual void deinitialize();
|
||||||
|
|
||||||
MyGUI::Widget* widget() const { return mWidget; }
|
MyGUI::Widget* widget() const { return mWidget; }
|
||||||
|
WidgetExtension* slot() const { return mSlot; }
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
const std::vector<WidgetExtension*>& children() { return mChildren; }
|
const std::vector<WidgetExtension*>& children() { return mChildren; }
|
||||||
void setChildren(const std::vector<WidgetExtension*>&);
|
void setChildren(const std::vector<WidgetExtension*>&);
|
||||||
|
@ -50,7 +53,6 @@ namespace LuaUi
|
||||||
|
|
||||||
const sol::table& getLayout() { return mLayout; }
|
const sol::table& getLayout() { return mLayout; }
|
||||||
void setLayout(const sol::table& layout) { mLayout = layout; }
|
void setLayout(const sol::table& layout) { mLayout = layout; }
|
||||||
void resetSlot() { mSlot = this; }
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T externalValue(std::string_view name, const T& defaultValue)
|
T externalValue(std::string_view name, const T& defaultValue)
|
||||||
|
|
|
@ -4,12 +4,10 @@
|
||||||
<Resource type="ResourceSkin" name="LuaImage">
|
<Resource type="ResourceSkin" name="LuaImage">
|
||||||
<BasisSkin type="LuaTileRect"/>
|
<BasisSkin type="LuaTileRect"/>
|
||||||
</Resource>
|
</Resource>
|
||||||
|
|
||||||
<Resource type="ResourceSkin" name="LuaTextEdit" size="512 20">
|
|
||||||
<Property key="FontName" value="Default"/>
|
|
||||||
<Property key="TextAlign" value="Left VCenter"/>
|
|
||||||
<Property key="TextColour" value="#{fontcolour=normal}"/>
|
|
||||||
|
|
||||||
<Child type="TextBox" skin="MW_TextEditClient" offset="0 0 502 20" align="Stretch" name="Client"/>
|
<Resource type="ResourceSkin" name="LuaText" size="16 16">
|
||||||
|
<Property key="FontName" value="Default"/>
|
||||||
|
<Property key="TextAlign" value="Left Top"/>
|
||||||
|
<BasisSkin type="SimpleText" offset="0 0 16 16" align="Stretch" />
|
||||||
</Resource>
|
</Resource>
|
||||||
</MyGUI>
|
</MyGUI>
|
Loading…
Reference in a new issue