Commit 4b9db692 authored by Garth Corral's avatar Garth Corral
Browse files

- Changed mousewheel handling to pan more smoothly rather than in larger

  steps to better support devices with precise scrolling deltas (trackpads).
  Scrolling is done in the handler rather than creating and firing cmd events.
  This is intended to support two-finger scrolling on the Magic Trackpad.
- Added a preference, 'Use mousewheel to pan', to allow panning by default
  on mousewheel events.  This reverses the existing behavior where unmodified 
  mousewheel zooms and Shift/Cmd modified pans.  

  The old behavior was:
  - Unmodified scrollwheel performed zoom in/out
  - Shift modified scrollwheel performed pan up/down
  - Cmd modified scrollwheel performed pan left/right
  - Shift+Cmd modified scrollwheel performed zoom in/out
    with no cursor warp

  With the new preference checked, this changes to:

  - Unmodified scrollwheel performs pan up/down
  - Shift modified scrollwheel performs pan left/right
  - Cmd modified scrollwheel performs zoom in/out
  - Shift+Cmd modified scrollwheel performs zoom in/out
    with no cursor warp

  With the preference unchecked, this is now:
  - Unmodified scrollwheel performed zoom in/out
  - Shift modified scrollwheel performed pan left/right
  - Cmd modified scrollwheel performed pan up/down
  - Shift+Cmd modified scrollwheel performed zoom in/out
    with no cursor warp

  It should be noted that for the last case, the behavior has changed.
  This is not arbitrary.  This now matches expected behavior for an OS X
  application.  This also matches what wxWidgets expects on this platform
  as wxWidgets changes the axis of mousewheel events to horizontal when
  the event is shift-modified.

  The preference is added everwhere that mouse preferences previously
  existed, i.e., eeschema, pcbnew and gerbview.  The 3D Viewer does
  not yet honor this preference, but behaves as if it was checked.
  The pl_editor does not currently have any preferences to honor.

  As with the magnify event support, this covers canvases for all
  current tools, EDA_DRAW_PANEL, EDA_3D_CANVAS and EDA_DRAW_PANEL_GAL.

  This does NOT modify the behavior of mousewheel zooming, though it
  probably should.  This remains unsuitable for use with a trackpad,
  use pinch-to-zoom instead.
parent ae322dba
Loading
Loading
Loading
Loading
+9 −10
Original line number Original line Diff line number Diff line
@@ -250,19 +250,18 @@ void EDA_3D_CANVAS::SetView3D( int keycode )


void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
{
{
    if( event.ShiftDown() )
    double delta = 0.05 * GetPrm3DVisu().m_Zoom * event.GetWheelRotation();

    if( event.ShiftDown() || true )
    {
    {
        if( event.GetWheelRotation() < 0 )
        if( event.GetWheelAxis() == wxMOUSE_WHEEL_HORIZONTAL )
            SetView3D( WXK_UP );    // move up
            m_draw3dOffset.x -= delta;
        else
        else
            SetView3D( WXK_DOWN );  // move down
            m_draw3dOffset.y -= delta;
    }
    }
    else if( event.ControlDown() )
    else if( event.ControlDown() )
    {
    {
        if( event.GetWheelRotation() > 0 )
        m_draw3dOffset.y -= delta;
            SetView3D( WXK_RIGHT ); // move right
        else
            SetView3D( WXK_LEFT );  // move left
    }
    }
    else
    else
    {
    {
@@ -276,10 +275,10 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
        else
        else
            GetPrm3DVisu().m_Zoom *= 1.4;
            GetPrm3DVisu().m_Zoom *= 1.4;


        DisplayStatus();
        Refresh( false );
    }
    }


    DisplayStatus();
    Refresh( false );
    GetPrm3DVisu().m_Beginx = event.GetX();
    GetPrm3DVisu().m_Beginx = event.GetX();
    GetPrm3DVisu().m_Beginy = event.GetY();
    GetPrm3DVisu().m_Beginy = event.GetY();
}
}
+29 −32
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels


// keys to store options in config:
// keys to store options in config:
#define ENBL_ZOOM_NO_CENTER_KEY         wxT( "ZoomNoCenter" )
#define ENBL_ZOOM_NO_CENTER_KEY         wxT( "ZoomNoCenter" )
#define ENBL_MOUSEWHEEL_PAN_KEY         wxT( "MousewheelPAN" )
#define ENBL_MIDDLE_BUTT_PAN_KEY        wxT( "MiddleButtonPAN" )
#define ENBL_MIDDLE_BUTT_PAN_KEY        wxT( "MiddleButtonPAN" )
#define MIDDLE_BUTT_PAN_LIMITED_KEY     wxT( "MiddleBtnPANLimited" )
#define MIDDLE_BUTT_PAN_LIMITED_KEY     wxT( "MiddleBtnPANLimited" )
#define ENBL_AUTO_PAN_KEY               wxT( "AutoPAN" )
#define ENBL_AUTO_PAN_KEY               wxT( "AutoPAN" )
@@ -121,6 +122,7 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
    m_ClipBox.SetY( 0 );
    m_ClipBox.SetY( 0 );
    m_canStartBlock = -1;       // Command block can start if >= 0
    m_canStartBlock = -1;       // Command block can start if >= 0
    m_abortRequest = false;
    m_abortRequest = false;
    m_enableMousewheelPan = false;
    m_enableMiddleButtonPan = true;
    m_enableMiddleButtonPan = true;
    m_enableZoomNoCenter = false;
    m_enableZoomNoCenter = false;
    m_panScrollbarLimits = false;
    m_panScrollbarLimits = false;
@@ -135,6 +137,7 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,


    if( cfg )
    if( cfg )
    {
    {
        cfg->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
        cfg->Read( ENBL_MIDDLE_BUTT_PAN_KEY, &m_enableMiddleButtonPan, true );
        cfg->Read( ENBL_MIDDLE_BUTT_PAN_KEY, &m_enableMiddleButtonPan, true );
        cfg->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
        cfg->Read( ENBL_ZOOM_NO_CENTER_KEY, &m_enableZoomNoCenter, false );
        cfg->Read( MIDDLE_BUTT_PAN_LIMITED_KEY, &m_panScrollbarLimits, false );
        cfg->Read( MIDDLE_BUTT_PAN_LIMITED_KEY, &m_panScrollbarLimits, false );
@@ -164,6 +167,7 @@ EDA_DRAW_PANEL::~EDA_DRAW_PANEL()


    if( cfg )
    if( cfg )
    {
    {
        cfg->Write( ENBL_MOUSEWHEEL_PAN_KEY, m_enableMousewheelPan );
        cfg->Write( ENBL_MIDDLE_BUTT_PAN_KEY, m_enableMiddleButtonPan );
        cfg->Write( ENBL_MIDDLE_BUTT_PAN_KEY, m_enableMiddleButtonPan );
        cfg->Write( ENBL_ZOOM_NO_CENTER_KEY, m_enableZoomNoCenter );
        cfg->Write( ENBL_ZOOM_NO_CENTER_KEY, m_enableZoomNoCenter );
        cfg->Write( MIDDLE_BUTT_PAN_LIMITED_KEY, m_panScrollbarLimits );
        cfg->Write( MIDDLE_BUTT_PAN_LIMITED_KEY, m_panScrollbarLimits );
@@ -424,7 +428,7 @@ void EDA_DRAW_PANEL::OnScroll( wxScrollWinEvent& event )
    // so we skip these events.
    // so we skip these events.
    // Note they are here just in case, because they are not actually used
    // Note they are here just in case, because they are not actually used
    // in Kicad
    // in Kicad
#if wxCHECK_VERSION( 3, 1, 0 ) || !wxCHECK_VERSION( 2, 9, 5 ) || !defined (__WINDOWS__)
#if wxCHECK_VERSION( 3, 1, 0 ) || !wxCHECK_VERSION( 2, 9, 5 ) || ( !defined (__WINDOWS__) && !defined (__WXMAC__) )
    int maxX = unitsX - csizeX;
    int maxX = unitsX - csizeX;
    int maxY = unitsY - csizeY;
    int maxY = unitsY - csizeY;


@@ -934,47 +938,40 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
    bool offCenterReq = event.ControlDown() && event.ShiftDown();
    bool offCenterReq = event.ControlDown() && event.ShiftDown();
    offCenterReq = offCenterReq || m_enableZoomNoCenter;
    offCenterReq = offCenterReq || m_enableZoomNoCenter;


#if wxMAJOR_VERSION >= 2 && wxMINOR_VERSION >= 9
#if wxCHECK_VERSION(2, 9, 0)
    int axis = event.GetWheelAxis();
    int axis = event.GetWheelAxis();
#else
#else
    const int axis = 0;
    const int axis = 0;
#endif
#endif


    // This is a zoom in or out command
    wxPoint delta;
    if( event.GetWheelRotation() > 0 )
    wxPoint start = GetViewStart();
    {

        if( event.ShiftDown() && !event.ControlDown() )
    if( ( m_enableMousewheelPan || event.ShiftDown() ) && !event.ControlDown() )
    {
    {
            if( axis == 0 )
        if( axis == wxMOUSE_WHEEL_HORIZONTAL )
                cmd.SetId( ID_PAN_UP );
            delta.x = -event.GetWheelRotation();
        else
        else
                cmd.SetId( ID_PAN_RIGHT );
            delta.y = event.GetWheelRotation();
    }
    }
        else if( event.ControlDown() && !event.ShiftDown() )
    else if( event.ControlDown() && !event.ShiftDown() && !m_enableMousewheelPan )
            cmd.SetId( ID_PAN_LEFT );
        delta.y = event.GetWheelRotation();
    else if( offCenterReq )
    else if( offCenterReq )
            cmd.SetId( ID_OFFCENTER_ZOOM_IN );
        cmd.SetId( event.GetWheelRotation() > 0 ? ID_OFFCENTER_ZOOM_IN : ID_OFFCENTER_ZOOM_OUT );
    else
    else
            cmd.SetId( ID_POPUP_ZOOM_IN );
        cmd.SetId( event.GetWheelRotation() > 0 ? ID_POPUP_ZOOM_IN : ID_POPUP_ZOOM_OUT );
    }

    else if( event.GetWheelRotation() < 0 )
    if( cmd.GetId() )
    {
        if( event.ShiftDown() && !event.ControlDown() )
    {
    {
            if( axis == 0 )
        GetEventHandler()->ProcessEvent( cmd );
                cmd.SetId( ID_PAN_DOWN );
            else
                cmd.SetId( ID_PAN_LEFT );
    }
    }
        else if( event.ControlDown() && !event.ShiftDown() )
            cmd.SetId( ID_PAN_RIGHT );
        else if( offCenterReq )
            cmd.SetId( ID_OFFCENTER_ZOOM_OUT );
    else
    else
            cmd.SetId( ID_POPUP_ZOOM_OUT );
    {
        wxPoint newStart = start - delta;
        wxPoint center = GetScreenCenterLogicalPosition();
        GetParent()->SetScrollCenterPosition(center);
        Scroll(newStart);
    }
    }

    GetEventHandler()->ProcessEvent( cmd );
    event.Skip();
    event.Skip();
}
}


+13 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@
#include <wx/colour.h>
#include <wx/colour.h>
#include <wx/filename.h>
#include <wx/filename.h>


#include <kiface_i.h>
#include <class_draw_panel_gal.h>
#include <class_draw_panel_gal.h>
#include <view/view.h>
#include <view/view.h>
#include <view/wx_view_controls.h>
#include <view/wx_view_controls.h>
@@ -47,6 +48,9 @@
#include <profile.h>
#include <profile.h>
#endif /* __WXDEBUG__ */
#endif /* __WXDEBUG__ */


// keys to retrieve options in config:
#define ENBL_MOUSEWHEEL_PAN_KEY         wxT( "MousewheelPAN" )

EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
                                        const wxPoint& aPosition, const wxSize& aSize,
                                        const wxPoint& aPosition, const wxSize& aSize,
                                        GalType aGalType ) :
                                        GalType aGalType ) :
@@ -91,11 +95,20 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
                 NULL, m_eventDispatcher );
                 NULL, m_eventDispatcher );
    }
    }


    m_enableMousewheelPan = false;

    // Set up timer that prevents too frequent redraw commands
    // Set up timer that prevents too frequent redraw commands
    m_refreshTimer.SetOwner( this );
    m_refreshTimer.SetOwner( this );
    m_pendingRefresh = false;
    m_pendingRefresh = false;
    m_drawing = false;
    m_drawing = false;
    Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
    Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );

    wxConfigBase* cfg = Kiface().KifaceSettings();

    if( cfg )
    {
        cfg->Read( ENBL_MOUSEWHEEL_PAN_KEY, &m_enableMousewheelPan, false );
    }
}
}




+13 −12
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@


#include <wx/wx.h>
#include <wx/wx.h>


#include <class_draw_panel_gal.h>
#include <view/view.h>
#include <view/view.h>
#include <view/wx_view_controls.h>
#include <view/wx_view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <gal/graphics_abstraction_layer.h>
@@ -134,24 +135,24 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
{
{
    const double wheelPanSpeed = 0.001;
    const double wheelPanSpeed = 0.001;

    if( aEvent.ControlDown() || aEvent.ShiftDown() )
    {
        // Scrolling
    VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
    VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
                                          ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
                                          ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
        double   scrollSpeed;


        if( abs( scrollVec.x ) > abs( scrollVec.y ) )
            scrollSpeed = scrollVec.x;
        else
            scrollSpeed = scrollVec.y;


        VECTOR2D delta( aEvent.ControlDown() ? -scrollSpeed : 0.0,
    if( !aEvent.ControlDown() && ( aEvent.ShiftDown() || ((EDA_DRAW_PANEL_GAL *)m_parentPanel)->GetEnableMousewheelPan() ) )
                        aEvent.ShiftDown() ? -scrollSpeed : 0.0 );
    {
        // Scrolling
        int axis = aEvent.GetWheelAxis();
        VECTOR2D delta( axis == wxMOUSE_WHEEL_HORIZONTAL ? scrollVec.x : 0.0,
                        axis == wxMOUSE_WHEEL_VERTICAL ? -scrollVec.y : 0.0 );


        setCenter( m_view->GetCenter() + delta );
        setCenter( m_view->GetCenter() + delta );
    }
    }
    else if( aEvent.ControlDown() && !aEvent.ShiftDown() && !((EDA_DRAW_PANEL_GAL *)m_parentPanel)->GetEnableMousewheelPan() )
    {
        VECTOR2D delta( 0.0, -scrollVec.y );
        setCenter( m_view->GetCenter() + delta );
    }
    else
    else
    {
    {
        // Zooming
        // Zooming
+14 −0
Original line number Original line Diff line number Diff line
@@ -372,6 +372,20 @@ public:
        return m_checkMiddleButtonPanLimited->GetValue();
        return m_checkMiddleButtonPanLimited->GetValue();
    }
    }


    /**
     * Function SetEnableMousewheelPan
     * Sets the MousewheelPan setting in the dialog
     *
     * @param enable The boolean value to set the AutoPan value in the dialog
     */
    void SetEnableMousewheelPan( bool enable ) { m_checkEnableMousewheelPan->SetValue( enable ); }

    /**
     * Function GetEnableMousewheelPan
     * Return the MousewheelPan setting from the dialog
     */
    bool GetEnableMousewheelPan( void ) { return m_checkEnableMousewheelPan->GetValue(); }

    /**
    /**
     * Function SetEnableAutoPan
     * Function SetEnableAutoPan
     * Sets the AutoPan setting in the dialog
     * Sets the AutoPan setting in the dialog
Loading