From cb5ec8bce1234aa36008ef15b7512cb4c7ead458 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 18 Nov 2020 15:23:05 +0000 Subject: [PATCH] Make Eeschema cursors update without waiting for mouse movement. --- common/draw_panel_gal.cpp | 12 ++++---- eeschema/sch_base_frame.cpp | 14 +++++++++ eeschema/tools/ee_selection_tool.cpp | 45 ++++++++++++++++++++-------- eeschema/tools/ee_selection_tool.h | 29 +++++++++++------- 4 files changed, 71 insertions(+), 29 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 6840f78818..e764913c93 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -124,12 +124,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin // Set up timer that prevents too frequent redraw commands m_refreshTimer.SetOwner( this ); Connect( m_refreshTimer.GetId(), wxEVT_TIMER, - wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); + wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); // Set up timer to execute OnShow() method when the window appears on the screen m_onShowTimer.SetOwner( this ); Connect( m_onShowTimer.GetId(), wxEVT_TIMER, - wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), NULL, this ); + wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), NULL, this ); m_onShowTimer.Start( 10 ); } @@ -464,7 +464,11 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) wxWindow* galWindow = dynamic_cast( new_gal ); if( galWindow ) - galWindow->Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, this ); + { + galWindow->Connect( wxEVT_SET_CURSOR, + wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, + this ); + } delete m_gal; m_gal = new_gal; @@ -581,9 +585,7 @@ void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent ) void EDA_DRAW_PANEL_GAL::SetCurrentCursor( KICURSOR cursor ) { if( m_currentKiCursor == cursor ) - { return; - } m_currentCursor = CURSOR_STORE::GetCursor( cursor ); m_currentKiCursor = cursor; diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 40e0c9be44..714c715e47 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -88,6 +88,20 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindo m_defaults( &m_base_frame_defaults ) { createCanvas(); + + Bind( wxEVT_IDLE, + [this]( wxIdleEvent& aEvent ) + { + // Handle cursor adjustments. While we can get motion and key events through + // wxWidgets, we can't get modifier-key-up events. + if( m_toolManager ) + { + EE_SELECTION_TOOL* selTool = m_toolManager->GetTool(); + + if( selTool ) + selTool->OnIdle( aEvent ); + } + } ); } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 24264c7368..1e22990f1c 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -557,28 +557,20 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { if( displayWireCursor ) { - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::LINE_WIRE_ADD ); + m_nonModifiedCursor = KICURSOR::LINE_WIRE_ADD; } else if( rolloverItem != niluuid ) { - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::HAND ); + m_nonModifiedCursor = KICURSOR::HAND; } - else if( !modifier_enabled && !m_selection.Empty() - && !m_frame->GetDragSelects() && evt->HasPosition() + else if( !m_selection.Empty() && !m_frame->GetDragSelects() && evt->HasPosition() && selectionContains( evt->Position() ) ) //move/drag option prediction { - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING ); + m_nonModifiedCursor = KICURSOR::MOVING; } else { - if( m_additive ) - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD ); - else if( m_subtractive ) - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT ); - else if( m_exclusive_or ) - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR ); - else - m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); + m_nonModifiedCursor = KICURSOR::ARROW; } } } @@ -590,6 +582,33 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } +void EE_SELECTION_TOOL::OnIdle( wxIdleEvent& aEvent ) +{ + if( m_frame->ToolStackIsEmpty() ) + { + wxMouseState keyboardState = wxGetMouseState(); + + m_subtractive = m_additive = m_exclusive_or = false; + + if( keyboardState.ShiftDown() && keyboardState.ControlDown() ) + m_subtractive = true; + else if( keyboardState.ShiftDown() ) + m_additive = true; + else if( keyboardState.ControlDown() ) + m_exclusive_or = true; + + if( m_additive ) + m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ADD ); + else if( m_subtractive ) + m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::SUBTRACT ); + else if( m_exclusive_or ) + m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::XOR ); + else + m_frame->GetCanvas()->SetCurrentCursor( m_nonModifiedCursor ); + } +} + + EE_SELECTION& EE_SELECTION_TOOL::GetSelection() { return m_selection; diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index b063dda2b1..8eed0e68d5 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -31,6 +31,7 @@ #include #include #include +#include class SCH_BASE_FRAME; class SCH_ITEM; @@ -71,6 +72,8 @@ public: */ int Main( const TOOL_EVENT& aEvent ); + void OnIdle( wxIdleEvent& aEvent ); + /** * Function GetSelection() * @@ -277,19 +280,23 @@ private: void setTransitions() override; private: - SCH_BASE_FRAME* m_frame; // Pointer to the parent frame - EE_SELECTION m_selection; // Current state of selection + SCH_BASE_FRAME* m_frame; // Pointer to the parent frame + EE_SELECTION m_selection; // Current state of selection - bool m_additive; // Items should be added to selection (instead of replacing) - bool m_subtractive; // Items should be removed from selection - bool m_exclusive_or; // Items' selection state should be toggled - bool m_multiple; // Multiple selection mode is active - bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor + bool m_additive; // Items should be added to sel (instead of replacing) + bool m_subtractive; // Items should be removed from sel + bool m_exclusive_or; // Items' selection state should be toggled + bool m_multiple; // Multiple selection mode is active + bool m_skip_heuristics; // Show disambuguation menu for all items under the + // cursor rather than trying to narrow them down first + // using heuristics - bool m_isSymbolEditor; // True when the symbol editor is the parent frame - bool m_isLibView; // True when libview is the parent frame - int m_unit; // Fixed unit filter (for symbol editor) - int m_convert; // Fixed DeMorgan filter (for symbol editor) + KICURSOR m_nonModifiedCursor; // Cursor in the absence of shift/ctrl/alt + + bool m_isSymbolEditor; // True when the symbol editor is the parent frame + bool m_isLibView; // True when libview is the parent frame + int m_unit; // Fixed unit filter (for symbol editor) + int m_convert; // Fixed DeMorgan filter (for symbol editor) }; #endif //KICAD_SCH_SELECTION_TOOL_H