diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 73ca64294d..b0b033d037 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -75,6 +75,9 @@ CAIRO_GAL::CAIRO_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, SetSize( aParent->GetSize() ); screenSize = VECTOR2I( aParent->GetSize() ); + + cursorPixels = NULL; + cursorPixelsSaved = NULL; initCursor(); // Grid color settings are different in Cairo and OpenGL @@ -808,6 +811,13 @@ void CAIRO_GAL::ClearTarget( RENDER_TARGET aTarget ) } +void CAIRO_GAL::SetCursorSize( unsigned int aCursorSize ) +{ + GAL::SetCursorSize( aCursorSize ); + initCursor(); +} + + void CAIRO_GAL::DrawCursor( const VECTOR2D& aCursorPosition ) { // Now we should only store the position of the mouse cursor @@ -890,6 +900,12 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent ) void CAIRO_GAL::initCursor() { + if( cursorPixels ) + delete cursorPixels; + + if( cursorPixelsSaved ) + delete cursorPixelsSaved; + cursorPixels = new wxBitmap( cursorSize, cursorSize ); cursorPixelsSaved = new wxBitmap( cursorSize, cursorSize ); diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index e0b1dba963..dca18acc05 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -229,6 +229,9 @@ public: // Cursor // ------- + /// @copydoc GAL::SetCursorSize() + virtual void SetCursorSize( unsigned int aCursorSize ); + /// @copydoc GAL::DrawCursor() virtual void DrawCursor( const VECTOR2D& aCursorPosition ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index f607e96975..3fef15d1fc 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -783,12 +783,22 @@ public: cursorColor = aCursorColor; } + /** + * @brief Returns the cursor size. + * + * @return The current cursor size (in pixels). + */ + inline unsigned int GetCursorSize() const + { + return cursorSize; + } + /** * @brief Set the cursor size. * * @param aCursorSize is the size of the cursor expressed in pixels. */ - inline void SetCursorSize( unsigned int aCursorSize ) + virtual inline void SetCursorSize( unsigned int aCursorSize ) { cursorSize = aCursorSize; } diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index c1b538ba04..3e2118eb84 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -29,13 +29,16 @@ // Selection tool actions TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection", - AS_GLOBAL, 0, "", "", AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere + AS_GLOBAL, 0, + "", "", AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere TOOL_ACTION COMMON_ACTIONS::selectionSingle( "pcbnew.InteractiveSelection.Single", - AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + AS_GLOBAL, 0, + "", "" ); // No description, it is not supposed to be shown anywhere TOOL_ACTION COMMON_ACTIONS::selectionClear( "pcbnew.InteractiveSelection.Clear", - AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + AS_GLOBAL, 0, + "", "" ); // No description, it is not supposed to be shown anywhere // Edit tool actions @@ -287,6 +290,10 @@ TOOL_ACTION COMMON_ACTIONS::resetCoords( "pcbnew.Control.resetCoords", AS_GLOBAL, ' ', "", "" ); +TOOL_ACTION COMMON_ACTIONS::switchCursor( "pcbnew.Control.switchCursor", + AS_GLOBAL, 0, + "", "" ); + TOOL_ACTION COMMON_ACTIONS::switchUnits( "pcbnew.Control.switchUnits", AS_GLOBAL, MD_CTRL + int( 'U' ), "", "" ); @@ -304,7 +311,8 @@ TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter", "Run push & shove router", "Run push & shove router", AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update", - AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere + AS_GLOBAL, 0, + "", "" ); // No description, it is not supposed to be shown anywhere // Placement tool @@ -420,6 +428,9 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE: return COMMON_ACTIONS::highContrastMode.MakeEvent(); + case ID_TB_OPTIONS_SELECT_CURSOR: + return COMMON_ACTIONS::switchCursor.MakeEvent(); + case ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH: case ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH: case ID_PCB_DELETE_ITEM_BUTT: @@ -427,7 +438,6 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) case ID_PCB_SHOW_1_RATSNEST_BUTT: case ID_PCB_PLACE_OFFSET_COORD_BUTT: case ID_TB_OPTIONS_SHOW_MODULE_RATSNEST: - case ID_TB_OPTIONS_SELECT_CURSOR: case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE: case ID_MENU_PCB_SHOW_HIDE_MUWAVE_TOOLBAR: case ID_MICROWAVE_V_TOOLBAR: diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 78bc6f50d1..a47513acd9 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -189,6 +189,7 @@ public: // Miscellaneous static TOOL_ACTION resetCoords; + static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; static TOOL_ACTION showHelp; static TOOL_ACTION toBeDone; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 0a75ce975e..2d92566530 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -541,6 +541,24 @@ int PCBNEW_CONTROL::ResetCoords( TOOL_EVENT& aEvent ) } +int PCBNEW_CONTROL::SwitchCursor( TOOL_EVENT& aEvent ) +{ + const unsigned int BIG_CURSOR = 4000; + const unsigned int SMALL_CURSOR = 80; + + KIGFX::GAL* gal = getEditFrame()->GetGalCanvas()->GetGAL(); + + if( gal->GetCursorSize() == BIG_CURSOR ) + gal->SetCursorSize( SMALL_CURSOR ); + else + gal->SetCursorSize( BIG_CURSOR ); + + setTransitions(); + + return 0; +} + + int PCBNEW_CONTROL::SwitchUnits( TOOL_EVENT& aEvent ) { // TODO should not it be refactored to pcb_frame member function? @@ -621,6 +639,7 @@ void PCBNEW_CONTROL::setTransitions() // Miscellaneous Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() ); + Go( &PCBNEW_CONTROL::SwitchCursor, COMMON_ACTIONS::switchCursor.MakeEvent() ); Go( &PCBNEW_CONTROL::SwitchUnits, COMMON_ACTIONS::switchUnits.MakeEvent() ); Go( &PCBNEW_CONTROL::ShowHelp, COMMON_ACTIONS::showHelp.MakeEvent() ); Go( &PCBNEW_CONTROL::ToBeDone, COMMON_ACTIONS::toBeDone.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 61f7d5d511..4c11b9777b 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -90,6 +90,7 @@ public: // Miscellaneous int ResetCoords( TOOL_EVENT& aEvent ); + int SwitchCursor( TOOL_EVENT& aEvent ); int SwitchUnits( TOOL_EVENT& aEvent ); int ShowHelp( TOOL_EVENT& aEvent ); int ToBeDone( TOOL_EVENT& aEvent );