dragging fixes

This commit is contained in:
Eduardo Bart 2012-03-23 19:48:18 -03:00
parent d10a68613b
commit efa9811342
4 changed files with 31 additions and 16 deletions

View File

@ -86,18 +86,25 @@ void UIManager::inputEvent(const InputEvent& event)
updatePressedWidget(pressedWidget, event.mousePos); updatePressedWidget(pressedWidget, event.mousePos);
} }
break; break;
case Fw::MouseReleaseInputEvent: case Fw::MouseReleaseInputEvent: {
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton); bool accepted = false;
if(event.mouseButton == Fw::MouseLeftButton) { if(event.mouseButton == Fw::MouseLeftButton) {
// release pressed widget // release pressed widget
if(m_pressedWidget) if(m_pressedWidget) {
updatePressedWidget(nullptr, event.mousePos); if(updatePressedWidget(nullptr, event.mousePos))
accepted = true;
}
// release dragging widget // release dragging widget
if(m_draggingWidget) if(m_draggingWidget) {
updateDraggingWidget(nullptr, event.mousePos); if(updateDraggingWidget(nullptr, event.mousePos))
accepted = true;
}
} }
if(!accepted)
m_mouseReceiver->propagateOnMouseRelease(event.mousePos, event.mouseButton);
break; break;
}
case Fw::MouseMoveInputEvent: { case Fw::MouseMoveInputEvent: {
// start dragging when moves a pressed widget // start dragging when moves a pressed widget
if(m_pressedWidget && m_pressedWidget->isDragable() && m_draggingWidget != m_pressedWidget) if(m_pressedWidget && m_pressedWidget->isDragable() && m_draggingWidget != m_pressedWidget)
@ -119,8 +126,10 @@ void UIManager::inputEvent(const InputEvent& event)
m_isOnInputEvent = false; 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; UIWidgetPtr oldPressedWidget = m_pressedWidget;
m_pressedWidget = newPressedWidget; 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 // when releasing mouse inside pressed widget area send onClick event
if(!clickedPos.isNull() && oldPressedWidget->containsPoint(clickedPos)) { if(!clickedPos.isNull() && oldPressedWidget->containsPoint(clickedPos)) {
// onMouseRelease will be already fired by mouseReceiver // 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 // must send mouse events even if the mouse is outside widget area when releasing a pressed widget
} else } else
oldPressedWidget->onMouseRelease(clickedPos, Fw::MouseLeftButton); accepted = oldPressedWidget->onMouseRelease(clickedPos, Fw::MouseLeftButton);
} }
} }
return accepted;
} }
void UIManager::updateHoveredWidget() void UIManager::updateHoveredWidget()
@ -168,8 +179,10 @@ void UIManager::updateHoveredWidget()
m_hoverUpdateScheduled = true; 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; UIWidgetPtr oldDraggingWidget = m_draggingWidget;
m_draggingWidget = nullptr; m_draggingWidget = nullptr;
if(oldDraggingWidget) { 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); oldDraggingWidget->updateState(Fw::DraggingState);
} }
@ -194,6 +207,8 @@ void UIManager::updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Po
draggingWidget->updateState(Fw::DraggingState); draggingWidget->updateState(Fw::DraggingState);
} }
} }
return accepted;
} }
void UIManager::onWidgetAppear(const UIWidgetPtr& widget) void UIManager::onWidgetAppear(const UIWidgetPtr& widget)

View File

@ -37,9 +37,9 @@ public:
void resize(const Size& size); void resize(const Size& size);
void inputEvent(const InputEvent& event); 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 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); bool importStyle(const std::string& file);
void importStyleFromOTML(const OTMLNodePtr& styleNode); void importStyleFromOTML(const OTMLNodePtr& styleNode);

View File

@ -1235,9 +1235,9 @@ bool UIWidget::onDragEnter(const Point& mousePos)
return callLuaField<bool>("onDragEnter", 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) bool UIWidget::onDragMove(const Point& mousePos, const Point& mouseMoved)

View File

@ -171,7 +171,7 @@ protected:
virtual void onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason); virtual void onChildFocusChange(const UIWidgetPtr& focusedChild, const UIWidgetPtr& unfocusedChild, Fw::FocusReason reason);
virtual void onHoverChange(bool hovered); virtual void onHoverChange(bool hovered);
virtual bool onDragEnter(const Point& mousePos); 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 onDragMove(const Point& mousePos, const Point& mouseMoved);
virtual bool onDrop(UIWidgetPtr draggedWidget, const Point& mousePos); virtual bool onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
virtual bool onKeyText(const std::string& keyText); virtual bool onKeyText(const std::string& keyText);