From f9cc91496012fad42214afba56c81053d5a7b0e8 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 10:26:08 +0200 Subject: [PATCH] Mouse movement events are sent during autopanning, as the cursor position changes in the world coordinates (even if it stays still in the screen coordinates). It allows tools to update their state, as if the mouse was moved. --- common/drawpanel_gal.cpp | 9 ++++++--- common/tool/tool_dispatcher.cpp | 7 +++++-- common/view/wx_view_controls.cpp | 5 ++++- include/tool/tool_dispatcher.h | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index fa0b004e49..2d169b37db 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -87,10 +87,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); -// Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); + Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); -// Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( TOOL_DISPATCHER::EVT_REFRESH_MOUSE, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), + NULL, this ); m_refreshTimer.SetOwner( this ); Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); @@ -243,8 +245,9 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) } -void EDA_DRAW_PANEL_GAL::onEnter ( wxEvent& aEvent ) +void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent ) { + // Getting focus is necessary in order to receive key events properly SetFocus(); } diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index eb3b777b20..03ff9ef9b3 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -41,6 +41,8 @@ using boost::optional; +const wxEventType TOOL_DISPATCHER::EVT_REFRESH_MOUSE = wxNewEventType(); + struct TOOL_DISPATCHER::ButtonState { ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent, @@ -215,10 +217,11 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL || type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || - type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) + type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || + type == EVT_REFRESH_MOUSE ) { pos = getView()->ToWorld ( getCurrentMousePos() ); - if( pos != m_lastMousePos ) + if( pos != m_lastMousePos || type == EVT_REFRESH_MOUSE ) { motion = true; m_lastMousePos = pos; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 838f5b82a0..1349948501 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace KiGfx; @@ -197,7 +198,9 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) dir = m_view->ToWorld( dir, false ); m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); - m_parentPanel->Refresh(); + // Notify tools that the cursor position has changed in the world coordinates + wxCommandEvent moveEvent( TOOL_DISPATCHER::EVT_REFRESH_MOUSE ); + wxPostEvent( m_parentPanel, moveEvent ); } break; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index ae1db0c4d2..f5b7bacae0 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -65,6 +65,9 @@ public: virtual void DispatchWxEvent( wxEvent& aEvent ); virtual void DispatchWxCommand( wxCommandEvent& aEvent ); + /// Event that forces mouse move event in the dispatcher + static const wxEventType EVT_REFRESH_MOUSE; + private: static const int MouseButtonCount = 3; static const int DragTimeThreshold = 300;