dragging fixes
This commit is contained in:
parent
d10a68613b
commit
efa9811342
|
@ -86,18 +86,25 @@ void UIManager::inputEvent(const InputEvent& event)
|
|||
updatePressedWidget(pressedWidget, event.mousePos);
|
||||
}
|
||||
break;
|
||||
case Fw::MouseReleaseInputEvent:
|
||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||
case Fw::MouseReleaseInputEvent: {
|
||||
bool accepted = false;
|
||||
if(event.mouseButton == Fw::MouseLeftButton) {
|
||||
// release pressed widget
|
||||
if(m_pressedWidget)
|
||||
updatePressedWidget(nullptr, event.mousePos);
|
||||
if(m_pressedWidget) {
|
||||
if(updatePressedWidget(nullptr, event.mousePos))
|
||||
accepted = true;
|
||||
}
|
||||
|
||||
// release dragging widget
|
||||
if(m_draggingWidget)
|
||||
updateDraggingWidget(nullptr, event.mousePos);
|
||||
if(m_draggingWidget) {
|
||||
if(updateDraggingWidget(nullptr, event.mousePos))
|
||||
accepted = true;
|
||||
}
|
||||
}
|
||||
if(!accepted)
|
||||
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
|
||||
break;
|
||||
}
|
||||
case Fw::MouseMoveInputEvent: {
|
||||
// start dragging when moves a pressed widget
|
||||
if(m_pressedWidget && m_pressedWidget->isDragable() && m_draggingWidget != m_pressedWidget)
|
||||
|
@ -119,8 +126,10 @@ void UIManager::inputEvent(const InputEvent& event)
|
|||
m_isOnInputEvent = false;
|
||||
}
|
||||
|
||||
void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos)
|
||||
bool UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos)
|
||||
{
|
||||
bool accepted = false;
|
||||
|
||||
UIWidgetPtr oldPressedWidget = m_pressedWidget;
|
||||
m_pressedWidget = newPressedWidget;
|
||||
|
||||
|
@ -134,12 +143,14 @@ void UIManager::updatePressedWidget(const UIWidgetPtr& newPressedWidget, const P
|
|||
// when releasing mouse inside pressed widget area send onClick event
|
||||
if(!clickedPos.isNull() && oldPressedWidget->containsPoint(clickedPos)) {
|
||||
// onMouseRelease will be already fired by mouseReceiver
|
||||
oldPressedWidget->onClick(clickedPos);
|
||||
accepted = oldPressedWidget->onClick(clickedPos);
|
||||
// must send mouse events even if the mouse is outside widget area when releasing a pressed widget
|
||||
} else
|
||||
oldPressedWidget->onMouseRelease(clickedPos, Fw::MouseLeftButton);
|
||||
accepted = oldPressedWidget->onMouseRelease(clickedPos, Fw::MouseLeftButton);
|
||||
}
|
||||
}
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
void UIManager::updateHoveredWidget()
|
||||
|
@ -168,8 +179,10 @@ void UIManager::updateHoveredWidget()
|
|||
m_hoverUpdateScheduled = true;
|
||||
}
|
||||
|
||||
void UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos)
|
||||
bool UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos)
|
||||
{
|
||||
bool accepted = false;
|
||||
|
||||
UIWidgetPtr oldDraggingWidget = m_draggingWidget;
|
||||
m_draggingWidget = nullptr;
|
||||
if(oldDraggingWidget) {
|
||||
|
@ -184,7 +197,7 @@ void UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Po
|
|||
}
|
||||
}
|
||||
|
||||
oldDraggingWidget->onDragLeave(droppedWidget, clickedPos);
|
||||
accepted = oldDraggingWidget->onDragLeave(droppedWidget, clickedPos);
|
||||
oldDraggingWidget->updateState(Fw::DraggingState);
|
||||
}
|
||||
|
||||
|
@ -194,6 +207,8 @@ void UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Po
|
|||
draggingWidget->updateState(Fw::DraggingState);
|
||||
}
|
||||
}
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
||||
void UIManager::onWidgetAppear(const UIWidgetPtr& widget)
|
||||
|
|
|
@ -37,9 +37,9 @@ public:
|
|||
void resize(const Size& size);
|
||||
void inputEvent(const InputEvent& event);
|
||||
|
||||
void updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point());
|
||||
bool updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point());
|
||||
void updateHoveredWidget();
|
||||
void updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
|
||||
bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
|
||||
|
||||
bool importStyle(const std::string& file);
|
||||
void importStyleFromOTML(const OTMLNodePtr& styleNode);
|
||||
|
|
|
@ -1235,9 +1235,9 @@ bool UIWidget::onDragEnter(const Point& mousePos)
|
|||
return callLuaField<bool>("onDragEnter", mousePos);
|
||||
}
|
||||
|
||||
void UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
|
||||
bool UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
|
||||
{
|
||||
callLuaField("onDragLeave", droppedWidget, mousePos);
|
||||
return callLuaField<bool>("onDragLeave", droppedWidget, mousePos);
|
||||
}
|
||||
|
||||
bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)
|
||||
|
|
|
@ -171,7 +171,7 @@ protected:
|
|||
virtual void onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason);
|
||||
virtual void onHoverChange(bool hovered);
|
||||
virtual bool onDragEnter(const Point& mousePos);
|
||||
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
||||
virtual bool onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
|
||||
virtual bool onDragMove(const Point& mousePos, const Point& mouseMoved);
|
||||
virtual bool onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
|
||||
virtual bool onKeyText(const std::string& keyText);
|
||||
|
|
Loading…
Reference in New Issue