From 75777b34971fff17666a0d60e3c7ee71e73d57b3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 1 Apr 2020 10:09:47 +0800 Subject: [PATCH] Fix R2 input handling. Probably broken by GUI refactoring. Fix kaetemi/ryzomclassic#81 --- .../interface_v3/input_handler_manager.cpp | 103 +++++++++++++++--- .../src/interface_v3/input_handler_manager.h | 2 +- 2 files changed, 86 insertions(+), 19 deletions(-) diff --git a/ryzom/client/src/interface_v3/input_handler_manager.cpp b/ryzom/client/src/interface_v3/input_handler_manager.cpp index 9d1e9292d..67a1b2350 100644 --- a/ryzom/client/src/interface_v3/input_handler_manager.cpp +++ b/ryzom/client/src/interface_v3/input_handler_manager.cpp @@ -271,16 +271,16 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) { - CViewPointer &rIP = *static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() ); + CViewPointer &rIP = *static_cast(CWidgetManager::getInstance()->getPointer()); NLGUI::CEventDescriptorMouse eventDesc; - sint32 x,y; - rIP.getPointerDispPos (x, y); - eventDesc.setX (x); - eventDesc.setY (y); + sint32 x, y; + rIP.getPointerDispPos(x, y); + eventDesc.setX(x); + eventDesc.setY(y); - bool handled= false; + bool handled = false; // button down ? static volatile bool doTest = false; @@ -291,7 +291,7 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) { if (_RecoverFocusLost) { - handled |= updateMousePos((CEventMouse&)event, eventDesc); // must update mouse pos here, + handled |= updateMousePos((CEventMouse&)event); // must update mouse pos here, // because when app window focus is gained by a mouse click, this is // the only place where we can retrieve mouse pos before a mouse move _RecoverFocusLost = false; @@ -299,10 +299,19 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) if (!handled) { if (R2::getEditor().isInitialized() - && (R2::isEditionCurrent() || R2::getEditor().getCurrentTool()) - ) + && (R2::isEditionCurrent() || R2::getEditor().getCurrentTool())) { - handled |= R2::getEditor().handleEvent(eventDesc); + const NLMISC::CEventMouseDown *mouseDownEvent = static_cast(&event); + if (mouseDownEvent->Button & NLMISC::leftButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouseleftdown); + handled |= R2::getEditor().handleEvent(eventDesc); + } + if (mouseDownEvent->Button & NLMISC::rightButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouserightdown); + handled |= R2::getEditor().handleEvent(eventDesc); + } } } handled |= inputHandler.handleMouseButtonDownEvent( event ); @@ -321,7 +330,7 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) // mouse move? else if(event == EventMouseMoveId) { - handled |= updateMousePos((CEventMouse&)event, eventDesc); + handled |= updateMousePos((CEventMouse&)event); } else if (event == EventMouseWheelId) { @@ -330,19 +339,77 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) } // if Event not handled, post to Action Manager - if( !handled ) + if (!handled) { - bool handled = false; if (R2::getEditor().isInitialized() - && (R2::isEditionCurrent() || R2::getEditor().getCurrentTool()) - ) + && (R2::isEditionCurrent() || R2::getEditor().getCurrentTool())) { - handled = R2::getEditor().handleEvent(eventDesc); + if (event == EventMouseDownId) + { + const NLMISC::CEventMouseDown *mouseDownEvent = static_cast(&event); + if (mouseDownEvent->Button & NLMISC::leftButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouseleftdown); + handled |= R2::getEditor().handleEvent(eventDesc); + } + if (mouseDownEvent->Button & NLMISC::rightButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouserightdown); + handled |= R2::getEditor().handleEvent(eventDesc); + } + } + else if (event == EventMouseUpId) + { + const NLMISC::CEventMouseUp *mouseUpEvent = static_cast(&event); + if (mouseUpEvent->Button & NLMISC::leftButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouseleftup); + handled |= R2::getEditor().handleEvent(eventDesc); + } + if (mouseUpEvent->Button & NLMISC::rightButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouserightup); + handled |= R2::getEditor().handleEvent(eventDesc); + } + } + else if (event == EventMouseDblClkId) + { + const NLMISC::CEventMouseDblClk *mouseDblClkEvent = static_cast(&event); + if (mouseDblClkEvent->Button & NLMISC::leftButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouseleftdblclk); + handled |= R2::getEditor().handleEvent(eventDesc); + } + if (mouseDblClkEvent->Button & NLMISC::rightButton) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mouserightdblclk); + handled |= R2::getEditor().handleEvent(eventDesc); + } + } + else + { + if (event == EventMouseWheelId) + { + const NLMISC::CEventMouseWheel *wheelEvent = static_cast(&event); + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mousewheel); + eventDesc.setWheel(wheelEvent->Direction ? 1 : -1); + handled = R2::getEditor().handleEvent(eventDesc); + } + else if (event == EventMouseMoveId) + { + eventDesc.setEventTypeExtended(CEventDescriptorMouse::mousemove); + handled = R2::getEditor().handleEvent(eventDesc); + } + else + { + nlwarning("R2 unknown mouse event '%s'", event.toString().c_str()); + } + } } if (!handled) { // post to Action Manager - FilteredEventServer.postEvent( event.clone() ); + FilteredEventServer.postEvent(event.clone()); } } } @@ -355,7 +422,7 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) // *************************************************************************** -bool CInputHandlerManager::updateMousePos(NLMISC::CEventMouse &event, NLGUI::CEventDescriptorMouse &eventDesc) +bool CInputHandlerManager::updateMousePos(NLMISC::CEventMouse &event) { if (!IsMouseFreeLook()) return inputHandler.handleMouseMoveEvent( event ); diff --git a/ryzom/client/src/interface_v3/input_handler_manager.h b/ryzom/client/src/interface_v3/input_handler_manager.h index 7971ef9a8..4b078ee84 100644 --- a/ryzom/client/src/interface_v3/input_handler_manager.h +++ b/ryzom/client/src/interface_v3/input_handler_manager.h @@ -181,7 +181,7 @@ private: void parseKey(xmlNodePtr cur, std::vector &out); // return true if handled - bool updateMousePos(NLMISC::CEventMouse &event, NLGUI::CEventDescriptorMouse &eventDesc); + bool updateMousePos(NLMISC::CEventMouse &event); NLGUI::CInputHandler inputHandler;