diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index ff84d294a1..0b3309504b 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -1379,6 +1379,9 @@ CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) ); #endif + Bind( wxEVT_GESTURE_ZOOM, &CAIRO_GAL::skipGestureEvent, this ); + Bind( wxEVT_GESTURE_PAN, &CAIRO_GAL::skipGestureEvent, this ); + SetSize( aParent->GetClientSize() ); m_isInitialized = false; @@ -1665,6 +1668,14 @@ void CAIRO_GAL::skipMouseEvent( wxMouseEvent& aEvent ) } +void CAIRO_GAL::skipGestureEvent( wxGestureEvent& aEvent ) +{ + // Post the gesture event to the event listener registered in constructor, if any + if( m_mouseListener ) + wxPostEvent( m_mouseListener, aEvent ); +} + + bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) { bool refresh = false; diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 58779f37cc..c982958056 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -391,6 +391,9 @@ OPENGL_GAL::OPENGL_GAL( const KIGFX::VC_SETTINGS& aVcSettings, GAL_DISPLAY_OPTIO Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); #endif + Bind( wxEVT_GESTURE_ZOOM, &OPENGL_GAL::skipGestureEvent, this ); + Bind( wxEVT_GESTURE_PAN, &OPENGL_GAL::skipGestureEvent, this ); + SetSize( aParent->GetClientSize() ); m_screenSize = ToVECTOR2I( GetNativePixelSize() ); @@ -2620,6 +2623,14 @@ void OPENGL_GAL::skipMouseEvent( wxMouseEvent& aEvent ) } +void OPENGL_GAL::skipGestureEvent( wxGestureEvent& aEvent ) +{ + // Post the gesture event to the event listener registered in constructor, if any + if( m_mouseListener ) + wxPostEvent( m_mouseListener, aEvent ); +} + + void OPENGL_GAL::blitCursor() { if( !IsCursorEnabled() ) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index fca447c4c9..ae36361e97 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de * Copyright (C) 2013-2015 CERN - * Copyright (C) 2012-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2024 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @author Maciej Suminski @@ -82,7 +82,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPane #endif m_cursorPos( 0, 0 ), m_updateCursor( true ), - m_infinitePanWorks( false ) + m_infinitePanWorks( false ), + m_gestureLastZoomFactor( 1.0 ) { LoadSettings(); @@ -132,6 +133,18 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPane wxMouseEventHandler( WX_VIEW_CONTROLS::onCaptureLost ), nullptr, this ); #endif + if( m_parentPanel->EnableTouchEvents( wxTOUCH_ZOOM_GESTURE | wxTOUCH_PAN_GESTURES ) ) + { + wxLogDebug( "EnableTouchEvents Successful!!" ); + m_parentPanel->Connect( wxEVT_GESTURE_ZOOM, + wxZoomGestureEventHandler( WX_VIEW_CONTROLS::onZoomGesture ), + nullptr, this ); + + m_parentPanel->Connect( wxEVT_GESTURE_PAN, + wxPanGestureEventHandler( WX_VIEW_CONTROLS::onPanGesture ), nullptr, + this ); + } + m_cursorWarped = false; m_panTimer.SetOwner( this ); @@ -609,6 +622,39 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) } +void WX_VIEW_CONTROLS::onZoomGesture( wxZoomGestureEvent& aEvent ) +{ + if( aEvent.IsGestureStart() ) + { + m_gestureLastZoomFactor = 1.0; + m_gestureLastPos = VECTOR2D( aEvent.GetPosition().x, aEvent.GetPosition().y ); + } + + VECTOR2D evtPos( aEvent.GetPosition().x, aEvent.GetPosition().y ); + VECTOR2D deltaWorld = m_view->ToWorld( evtPos - m_gestureLastPos, false ); + + m_view->SetCenter( m_view->GetCenter() - deltaWorld ); + + m_view->SetScale( m_view->GetScale() * aEvent.GetZoomFactor() / m_gestureLastZoomFactor, + m_view->ToWorld( evtPos ) ); + + m_gestureLastZoomFactor = aEvent.GetZoomFactor(); + m_gestureLastPos = evtPos; + + m_parentPanel->Refresh(); +} + + +void WX_VIEW_CONTROLS::onPanGesture( wxPanGestureEvent& aEvent ) +{ + VECTOR2I screenDelta( aEvent.GetDelta().x, aEvent.GetDelta().y ); + VECTOR2D deltaWorld = m_view->ToWorld( screenDelta, false ); + + m_view->SetCenter( m_view->GetCenter() - deltaWorld ); + m_parentPanel->Refresh(); +} + + void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent ) { const double linePanDelta = 0.05; diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index 8afb3f7529..1736d8af42 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -487,6 +487,13 @@ protected: */ void skipMouseEvent( wxMouseEvent& aEvent ); + /** + * Skip the gesture event to the parent. + * + * @param aEvent is the gesture event. + */ + void skipGestureEvent( wxGestureEvent& aEvent ); + /** * Give the correct cursor image when the native widget asks for it. * diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index b46b0128f8..732d21908c 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2017 CERN * @author Maciej Suminski * @@ -544,6 +544,13 @@ private: */ void skipMouseEvent( wxMouseEvent& aEvent ); + /** + * Skip the gesture event to the parent. + * + * @param aEvent is the gesture event. + */ + void skipGestureEvent( wxGestureEvent& aEvent ); + /** * Give the correct cursor image when the native widget asks for it. * diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 25c91d7729..42910dd970 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Torsten Hueter, torstenhtr gmx.de * Copyright (C) 2013 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -62,6 +62,8 @@ public: void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); void onLeave( wxMouseEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) ); + void onZoomGesture( wxZoomGestureEvent& aEvent ); + void onPanGesture( wxPanGestureEvent& aEvent ); void onScroll( wxScrollWinEvent& aEvent ); void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) ); @@ -205,6 +207,10 @@ private: ///< A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific. std::unique_ptr m_zoomController; + + ///< Used to track gesture events. + double m_gestureLastZoomFactor; + VECTOR2D m_gestureLastPos; }; } // namespace KIGFX