diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 26e09004ff..b3960396f7 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -33,6 +33,7 @@ set( GAL_SRCS newstroke_font.cpp painter.cpp gal/color4d.cpp + gal/cursors.cpp gal/dpi_scaling.cpp gal/gal_display_options.cpp gal/graphics_abstraction_layer.cpp @@ -321,7 +322,6 @@ set( COMMON_SRCS common.cpp config_params.cpp confirm.cpp - cursors.cpp dialog_shim.cpp gr_text.cpp dsnlexer.cpp diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 948afcf4bc..5679875d3d 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -71,8 +71,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_stealsFocus( true ) { m_parent = aParentWindow; - m_currentKiCursor = KICURSOR::DEFAULT; - SetCurrentCursor( KICURSOR::ARROW ); SetLayoutDirection( wxLayout_LeftToRight ); @@ -99,8 +97,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), NULL, this ); - Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, - this ); const wxEventType events[] = { // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events, @@ -450,15 +446,6 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) // trigger update of the gal options in case they differ from the defaults m_options.NotifyChanged(); - wxWindow* galWindow = dynamic_cast( new_gal ); - - if( galWindow ) - { - galWindow->Connect( wxEVT_SET_CURSOR, - wxSetCursorEventHandler( EDA_DRAW_PANEL_GAL::onSetCursor ), NULL, - this ); - } - delete m_gal; m_gal = new_gal; @@ -472,6 +459,9 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) m_gal->SetGridVisibility( grid_visibility ); + // Make sure the cursor is set on the new canvas + SetCurrentCursor( KICURSOR::ARROW ); + if( m_painter ) m_painter->SetGAL( m_gal ); @@ -565,21 +555,10 @@ void EDA_DRAW_PANEL_GAL::onShowTimer( wxTimerEvent& aEvent ) } -void EDA_DRAW_PANEL_GAL::SetCurrentCursor( KICURSOR cursor ) +void EDA_DRAW_PANEL_GAL::SetCurrentCursor( KICURSOR aCursor ) { - if( m_currentKiCursor == cursor ) - return; - - m_currentCursor = CURSOR_STORE::GetCursor( cursor ); - m_currentKiCursor = cursor; - - SetCursor( m_currentCursor ); -} - - -void EDA_DRAW_PANEL_GAL::onSetCursor( wxSetCursorEvent& event ) -{ - event.SetCursor( m_currentCursor ); + if( m_gal ) + m_gal->SetNativeCursorStyle( aCursor ); } diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index a241a17b4e..8d37576d07 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -1230,6 +1230,10 @@ CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, m_mouseListener = aMouseListener; m_paintListener = aPaintListener; + // Connect the native cursor handler + Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( CAIRO_GAL::onSetNativeCursor ), NULL, + this ); + // Connecting the event handlers Connect( wxEVT_PAINT, wxPaintEventHandler( CAIRO_GAL::onPaint ) ); @@ -1534,6 +1538,27 @@ bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) } +bool CAIRO_GAL::SetNativeCursorStyle( KICURSOR aCursor ) +{ + // Store the current cursor type and get the wxCursor for it + if( !GAL::SetNativeCursorStyle( aCursor ) ) + return false; + + m_currentwxCursor = CURSOR_STORE::GetCursor( m_currentNativeCursor ); + + // Update the cursor in the wx control + wxWindow::SetCursor( m_currentwxCursor ); + + return true; +} + + +void CAIRO_GAL::onSetNativeCursor( wxSetCursorEvent& aEvent ) +{ + aEvent.SetCursor( m_currentwxCursor ); +} + + void CAIRO_GAL_BASE::DrawGrid() { SetTarget( TARGET_NONCACHED ); diff --git a/common/cursors.cpp b/common/gal/cursors.cpp similarity index 99% rename from common/cursors.cpp rename to common/gal/cursors.cpp index debcb02371..5a58134ae0 100644 --- a/common/cursors.cpp +++ b/common/gal/cursors.cpp @@ -23,8 +23,10 @@ #include -#include +#include #include + +// Cursor files #include #include #include diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 5faf555aee..a12c622c3a 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -74,6 +74,9 @@ GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : m_forceDisplayCursor = false; SetCursorEnabled( false ); + // Initialize the native widget to an arrow cursor + SetNativeCursorStyle( KICURSOR::ARROW ); + // Initialize text properties ResetTextAttributes(); @@ -250,3 +253,14 @@ COLOR4D GAL::getCursorColor() const return color; } + + +bool GAL::SetNativeCursorStyle( KICURSOR aCursor ) +{ + if( m_currentNativeCursor == aCursor ) + return false; + + m_currentNativeCursor = aCursor; + + return true; +} diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 1cc3cc39a4..1873330056 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -236,6 +236,10 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, m_isGrouping = false; m_groupCounter = 0; + // Connect the native cursor handler + Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), NULL, + this ); + // Connecting the event handlers Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); @@ -1718,6 +1722,27 @@ bool OPENGL_GAL::HasTarget( RENDER_TARGET aTarget ) } +bool OPENGL_GAL::SetNativeCursorStyle( KICURSOR aCursor ) +{ + // Store the current cursor type and get the wxCursor for it + if( !GAL::SetNativeCursorStyle( aCursor ) ) + return false; + + m_currentwxCursor = CURSOR_STORE::GetCursor( m_currentNativeCursor ); + + // Update the cursor in the wx control + HIDPI_GL_CANVAS::SetCursor( m_currentwxCursor ); + + return true; +} + + +void OPENGL_GAL::onSetNativeCursor( wxSetCursorEvent& aEvent ) +{ + aEvent.SetCursor( m_currentwxCursor ); +} + + void OPENGL_GAL::DrawCursor( const VECTOR2D& aCursorPosition ) { // Now we should only store the position of the mouse cursor diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 5edd43a85e..b78c0a6cbe 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -56,7 +56,6 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ) { - m_currentCursor = wxCURSOR_ARROW; m_view = new KIGFX::SCH_VIEW( true, dynamic_cast( GetParentEDAFrame() ) ); m_view->SetGAL( m_gal ); diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index c29c4a5ae5..e4d25d0b66 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include class SCH_BASE_FRAME; class SCH_ITEM; diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 80356a7549..43d07df573 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -35,7 +35,8 @@ #include #include #include -#include + +#include class BOARD; class EDA_DRAW_FRAME; @@ -190,7 +191,7 @@ public: /** * Set the current cursor shape for this panel. */ - void SetCurrentCursor( KICURSOR cursor ); + void SetCurrentCursor( KICURSOR aCursor ); /** * Return the bounding box of the view that should be used if model is not valid. @@ -232,13 +233,9 @@ protected: void onLostFocus( wxFocusEvent& aEvent ); void onRefreshTimer( wxTimerEvent& aEvent ); void onShowTimer( wxTimerEvent& aEvent ); - void onSetCursor( wxSetCursorEvent& event ); static const int MinRefreshPeriod = 17; ///< 60 FPS. - wxCursor m_currentCursor; ///< Current mouse cursor shape id. - KICURSOR m_currentKiCursor; - wxWindow* m_parent; ///< Pointer to the parent window EDA_DRAW_FRAME* m_edaFrame; ///< Parent EDA_DRAW_FRAME (if available) diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 77c0f3dd7a..8bf94cf234 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -407,6 +407,9 @@ public: m_paintListener = aPaintListener; } + /// @copydoc GAL::SetNativeCursorStyle() + bool SetNativeCursorStyle( KICURSOR aCursor ) override; + /// @copydoc GAL::BeginDrawing() void beginDrawing() override; @@ -443,6 +446,13 @@ public: */ void skipMouseEvent( wxMouseEvent& aEvent ); + /** + * Give the correct cursor image when the native widget asks for it. + * + * @param aEvent is the cursor event to plac the cursor into. + */ + void onSetNativeCursor( wxSetCursorEvent& aEvent ); + ///< Cairo-specific update handlers bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override; @@ -467,6 +477,7 @@ protected: int m_wxBufferWidth; bool m_isInitialized; ///< Are Cairo image & surface ready to use COLOR4D m_backgroundColor; ///< Background color + wxCursor m_currentwxCursor; ///< wxCursor showing the current native cursor }; } // namespace KIGFX diff --git a/include/cursors.h b/include/gal/cursors.h similarity index 100% rename from include/cursors.h rename to include/gal/cursors.h diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index c5cf4d228f..2231ea5038 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -965,6 +966,14 @@ public: return VECTOR2D( m_worldScreenMatrix * aPoint ); } + /** + * Set the cursor in the native panel. + * + * @param aCursor is the cursor to use in the native panel + * @return true if the cursor was updated, false if the cursor given was already set + */ + virtual bool SetNativeCursorStyle( KICURSOR aCursor ); + /** * Enable/disable cursor. * @@ -1158,6 +1167,7 @@ protected: STROKE_FONT m_strokeFont; ///< Instance of object that stores information ///< about how to draw texts + KICURSOR m_currentNativeCursor; ///< Current cursor private: struct TEXT_PROPERTIES { diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 03716b0350..4a8fd6bafd 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -43,6 +43,7 @@ #include #include #include +#include #ifndef CALLBACK #define CALLBACK @@ -246,6 +247,9 @@ public: // Cursor // ------- + /// @copydoc GAL::SetNativeCursorStyle() + bool SetNativeCursorStyle( KICURSOR aCursor ) override; + /// @copydoc GAL::DrawCursor() void DrawCursor( const VECTOR2D& aCursorPosition ) override; @@ -333,6 +337,8 @@ private: GLint ufm_screenPixelSize; GLint ufm_pixelSizeMultiplier; + wxCursor m_currentwxCursor; ///< wxCursor showing the current native cursor + std::unique_ptr m_bitmapCache; // Polygon tesselation @@ -468,6 +474,13 @@ private: */ void skipMouseEvent( wxMouseEvent& aEvent ); + /** + * Give the correct cursor image when the native widget asks for it. + * + * @param aEvent is the cursor event to plac the cursor into. + */ + void onSetNativeCursor( wxSetCursorEvent& aEvent ); + /** * Blit cursor into the current screen. */ diff --git a/include/tool/picker_tool.h b/include/tool/picker_tool.h index d2863783e6..70032748b4 100644 --- a/include/tool/picker_tool.h +++ b/include/tool/picker_tool.h @@ -25,10 +25,10 @@ #ifndef PICKER_TOOL_H #define PICKER_TOOL_H -#include +#include +#include #include #include -#include class EDA_DRAW_FRAME;