Handle touchscreen gesture events for zoom/pan.
This commit is contained in:
parent
8e90063258
commit
8f8a68229c
|
@ -1379,6 +1379,9 @@ CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
|
||||||
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
|
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( CAIRO_GAL::skipMouseEvent ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Bind( wxEVT_GESTURE_ZOOM, &CAIRO_GAL::skipGestureEvent, this );
|
||||||
|
Bind( wxEVT_GESTURE_PAN, &CAIRO_GAL::skipGestureEvent, this );
|
||||||
|
|
||||||
SetSize( aParent->GetClientSize() );
|
SetSize( aParent->GetClientSize() );
|
||||||
|
|
||||||
m_isInitialized = false;
|
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 CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
|
||||||
{
|
{
|
||||||
bool refresh = false;
|
bool refresh = false;
|
||||||
|
|
|
@ -391,6 +391,9 @@ OPENGL_GAL::OPENGL_GAL( const KIGFX::VC_SETTINGS& aVcSettings, GAL_DISPLAY_OPTIO
|
||||||
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
|
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Bind( wxEVT_GESTURE_ZOOM, &OPENGL_GAL::skipGestureEvent, this );
|
||||||
|
Bind( wxEVT_GESTURE_PAN, &OPENGL_GAL::skipGestureEvent, this );
|
||||||
|
|
||||||
SetSize( aParent->GetClientSize() );
|
SetSize( aParent->GetClientSize() );
|
||||||
m_screenSize = ToVECTOR2I( GetNativePixelSize() );
|
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()
|
void OPENGL_GAL::blitCursor()
|
||||||
{
|
{
|
||||||
if( !IsCursorEnabled() )
|
if( !IsCursorEnabled() )
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
||||||
* Copyright (C) 2013-2015 CERN
|
* 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 <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
|
@ -82,7 +82,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPane
|
||||||
#endif
|
#endif
|
||||||
m_cursorPos( 0, 0 ),
|
m_cursorPos( 0, 0 ),
|
||||||
m_updateCursor( true ),
|
m_updateCursor( true ),
|
||||||
m_infinitePanWorks( false )
|
m_infinitePanWorks( false ),
|
||||||
|
m_gestureLastZoomFactor( 1.0 )
|
||||||
{
|
{
|
||||||
LoadSettings();
|
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 );
|
wxMouseEventHandler( WX_VIEW_CONTROLS::onCaptureLost ), nullptr, this );
|
||||||
#endif
|
#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_cursorWarped = false;
|
||||||
|
|
||||||
m_panTimer.SetOwner( this );
|
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 )
|
void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent )
|
||||||
{
|
{
|
||||||
const double linePanDelta = 0.05;
|
const double linePanDelta = 0.05;
|
||||||
|
|
|
@ -487,6 +487,13 @@ protected:
|
||||||
*/
|
*/
|
||||||
void skipMouseEvent( wxMouseEvent& aEvent );
|
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.
|
* Give the correct cursor image when the native widget asks for it.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KICAD, a free EDA CAD application.
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> 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
|
* Copyright (C) 2013-2017 CERN
|
||||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
*
|
*
|
||||||
|
@ -544,6 +544,13 @@ private:
|
||||||
*/
|
*/
|
||||||
void skipMouseEvent( wxMouseEvent& aEvent );
|
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.
|
* Give the correct cursor image when the native widget asks for it.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
|
||||||
* Copyright (C) 2013 CERN
|
* 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 <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
*
|
*
|
||||||
|
@ -62,6 +62,8 @@ public:
|
||||||
void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
|
void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
|
||||||
void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
|
void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
|
||||||
void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
|
void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
|
||||||
|
void onZoomGesture( wxZoomGestureEvent& aEvent );
|
||||||
|
void onPanGesture( wxPanGestureEvent& aEvent );
|
||||||
void onScroll( wxScrollWinEvent& aEvent );
|
void onScroll( wxScrollWinEvent& aEvent );
|
||||||
void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );
|
void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );
|
||||||
|
|
||||||
|
@ -205,6 +207,10 @@ private:
|
||||||
|
|
||||||
///< A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
|
///< A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
|
||||||
std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
|
std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
|
||||||
|
|
||||||
|
///< Used to track gesture events.
|
||||||
|
double m_gestureLastZoomFactor;
|
||||||
|
VECTOR2D m_gestureLastPos;
|
||||||
};
|
};
|
||||||
} // namespace KIGFX
|
} // namespace KIGFX
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue