Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
3.2 kB · 99 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100#include "window.hpp"
#include <MyGUI_Delegate.h>#include <MyGUI_MouseButton.h>#include <MyGUI_Types.h>
namespace LuaUi{ LuaWindow::LuaWindow() : mCaption(nullptr) { }
void LuaWindow::updateTemplate() { for (auto& [w, _] : mActionWidgets) { w->eventMouseButtonPressed.clear(); w->eventMouseDrag.clear(); } mActionWidgets.clear();
WidgetExtension* captionWidget = findDeepInTemplates("caption"); mCaption = dynamic_cast<LuaText*>(captionWidget);
if (mCaption) mActionWidgets.emplace(mCaption->widget(), mCaption); for (WidgetExtension* ext : findAllInTemplates("action")) mActionWidgets.emplace(ext->widget(), ext);
for (auto& [w, _] : mActionWidgets) { w->eventMouseButtonPressed += MyGUI::newDelegate(this, &LuaWindow::notifyMousePress); w->eventMouseDrag += MyGUI::newDelegate(this, &LuaWindow::notifyMouseDrag); }
WidgetExtension::updateTemplate(); }
void LuaWindow::updateProperties() { if (mCaption) mCaption->setCaption(propertyValue("caption", std::string())); mMoveResize = MyGUI::IntCoord(); clearForced(); WidgetExtension::updateProperties(); }
const std::vector<std::string_view>& LuaWindow::allUsedProperties() const { static std::vector<std::string_view> usedProps = std::invoke([this] { std::vector<std::string_view> props = { "caption" }; auto baseProps = WidgetExtension::allUsedProperties(); props.insert(props.end(), baseProps.begin(), baseProps.end()); return props; }); return usedProps; }
void LuaWindow::notifyMousePress(MyGUI::Widget* sender, int left, int top, MyGUI::MouseButton id) { if (id != MyGUI::MouseButton::Left) return;
mPreviousMouse.left = left; mPreviousMouse.top = top;
WidgetExtension* ext = mActionWidgets[sender];
mChangeScale = MyGUI::IntCoord( ext->externalValue("move", MyGUI::IntPoint(1, 1)), ext->externalValue("resize", MyGUI::IntSize(0, 0))); }
void LuaWindow::notifyMouseDrag(MyGUI::Widget* /*sender*/, int left, int top, MyGUI::MouseButton id) { if (id != MyGUI::MouseButton::Left) return;
MyGUI::IntCoord change = mChangeScale; change.left *= (left - mPreviousMouse.left); change.top *= (top - mPreviousMouse.top); change.width *= (left - mPreviousMouse.left); change.height *= (top - mPreviousMouse.top);
mMoveResize = mMoveResize + change; forceCoord(mMoveResize); updateCoord();
mPreviousMouse.left = left; mPreviousMouse.top = top;
protectedCall([this](LuaUtil::LuaView& view) { sol::table table = view.newTable(); table["position"] = osg::Vec2f(static_cast<float>(mCoord.left), static_cast<float>(mCoord.top)); table["size"] = osg::Vec2f(static_cast<float>(mCoord.width), static_cast<float>(mCoord.height)); triggerEvent("windowDrag", table); }); }}