mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
some window moving
This commit is contained in:
@@ -79,6 +79,22 @@ void UIManager::inputEvent(const InputEvent& event)
|
||||
break;
|
||||
case Fw::MouseReleaseInputEvent:
|
||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||
if(m_draggingWidget && event.mouseButton == Fw::MouseLeftButton) {
|
||||
auto clickedChildren = m_rootWidget->recursiveGetChildrenByPos(event.mousePos);
|
||||
UIWidgetPtr droppedWidget;
|
||||
for(const UIWidgetPtr& child : clickedChildren) {
|
||||
if(child != m_draggingWidget) {
|
||||
droppedWidget = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(droppedWidget)
|
||||
droppedWidget->onDrop(m_draggingWidget, event.mousePos);
|
||||
|
||||
m_draggingWidget->onDragLeave(droppedWidget, event.mousePos);
|
||||
m_draggingWidget->setDragging(false);
|
||||
m_draggingWidget = nullptr;
|
||||
}
|
||||
break;
|
||||
case Fw::MouseMoveInputEvent:
|
||||
m_mouseReceiver->updateState(Fw::HoverState);
|
||||
|
@@ -743,12 +743,6 @@ void UIWidget::setPhantom(bool phantom)
|
||||
|
||||
void UIWidget::setDragging(bool dragging)
|
||||
{
|
||||
if(dragging) {
|
||||
g_ui.setDraggingWidget(asUIWidget());
|
||||
} else {
|
||||
if(g_ui.getDraggingWidget() == asUIWidget())
|
||||
g_ui.setDraggingWidget(nullptr);
|
||||
}
|
||||
m_dragging = dragging;
|
||||
}
|
||||
|
||||
@@ -898,6 +892,22 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
|
||||
{
|
||||
UIWidgetList children;
|
||||
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
|
||||
const UIWidgetPtr& child = (*it);
|
||||
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
|
||||
UIWidgetList subChildren = child->recursiveGetChildrenByPos(childPos);
|
||||
if(!subChildren.empty())
|
||||
children.insert(children.end(), subChildren.begin(), subChildren.end());
|
||||
else if(!child->isPhantom())
|
||||
children.push_back(child);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id)
|
||||
{
|
||||
UIWidgetPtr widget = getChildById(id);
|
||||
@@ -1141,6 +1151,11 @@ void UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
|
||||
callLuaField("onDragLeave", droppedWidget, mousePos);
|
||||
}
|
||||
|
||||
bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
|
||||
{
|
||||
return callLuaField("onDragMove", mousePos, mouseMoved);
|
||||
}
|
||||
|
||||
void UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
|
||||
{
|
||||
callLuaField("onDrop", draggedWidget, mousePos);
|
||||
@@ -1184,13 +1199,6 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
if(isPressed() && getRect().contains(mousePos))
|
||||
onClick(mousePos);
|
||||
|
||||
UIWidgetPtr draggedWidget = g_ui.getDraggingWidget();
|
||||
if(draggedWidget && button == Fw::MouseLeftButton && (containsPoint(mousePos) || asUIWidget() == g_ui.getRootWidget())) {
|
||||
onDrop(draggedWidget, mousePos);
|
||||
draggedWidget->onDragLeave(asUIWidget(), mousePos);
|
||||
draggedWidget->setDragging(false);
|
||||
}
|
||||
|
||||
return callLuaField<bool>("onMouseRelease", mousePos, button);
|
||||
}
|
||||
|
||||
@@ -1202,6 +1210,11 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||
onDragEnter(mousePos - mouseMoved);
|
||||
}
|
||||
|
||||
if(m_dragging) {
|
||||
if(onDragMove(mousePos, mouseMoved))
|
||||
return true;
|
||||
}
|
||||
|
||||
return callLuaField<bool>("onMouseMove", mousePos, mouseMoved);
|
||||
}
|
||||
|
||||
@@ -1354,7 +1367,7 @@ bool UIWidget::propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton bu
|
||||
UIWidgetList children;
|
||||
for(const UIWidgetPtr& child : m_children) {
|
||||
// events on hidden or disabled widgets are discarded
|
||||
if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
|
||||
if((!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) && (!child->isPressed() && button == Fw::MouseLeftButton))
|
||||
continue;
|
||||
|
||||
// mouse release events go to all children
|
||||
|
@@ -140,6 +140,7 @@ public:
|
||||
UIWidgetPtr getChildByIndex(int index);
|
||||
UIWidgetPtr recursiveGetChildById(const std::string& id);
|
||||
UIWidgetPtr recursiveGetChildByPos(const Point& childPos);
|
||||
UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
|
||||
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
|
||||
|
||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||
@@ -175,6 +176,7 @@ protected:
|
||||
virtual void onHoverChange(bool hovered);
|
||||
virtual void onDragEnter(const Point& mousePos);
|
||||
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
||||
virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
|
||||
virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
|
||||
virtual bool onKeyText(const std::string& keyText);
|
||||
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
|
||||
|
Reference in New Issue
Block a user