Commit 6c137ac7 authored by Garth Corral's avatar Garth Corral
Browse files

Added support for wxWidgets magnify events from the Magic Trackpad on OS X

  Committing this separately from the rest to ease making a patch for just this
  functionality in case that it might make it into the trunk.
  
  This can function standalone, though it is less useful without the rest.
  It requires that wxwidgets-3.0.0_macosx_magnify_event.patch be applied to wxWidgets
  It is completely optional; everything is guarded by the USE_OSX_MAGNIFY_EVENT macro.
  
  - Added OnMagnify event handler to EDA_DRAW_PANEL, EDA_3D_CANVAS and the helper for
    EDA_DRAW_PANEL_GAL, WX_VIEW_CONTROLS. This should cover canvases all current tools.
  - Guarded all with USE_OSX_MAGNIFY EVENT feature macro and added support in CMakeLists.txt
parent 83667d4d
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas )
    // mouse events
    EVT_RIGHT_DOWN( EDA_3D_CANVAS::OnRightClick )
    EVT_MOUSEWHEEL( EDA_3D_CANVAS::OnMouseWheel )
#ifdef USE_OSX_MAGNIFY_EVENT
    EVT_MAGNIFY( EDA_3D_CANVAS::OnMagnify )    
#endif
    EVT_MOTION( EDA_3D_CANVAS::OnMouseMove )

    // other events
@@ -281,6 +284,21 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
    GetPrm3DVisu().m_Beginy = event.GetY();
}

#ifdef USE_OSX_MAGNIFY_EVENT
void EDA_3D_CANVAS::OnMagnify( wxMouseEvent& event )
{
    double magnification = (event.GetMagnification() + 1.0f);

    GetPrm3DVisu().m_Zoom /= magnification;

    if( GetPrm3DVisu().m_Zoom <= 0.01 ) {
        GetPrm3DVisu().m_Zoom = 0.01;
    }

    DisplayStatus();
    Refresh( false );
}
#endif

void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event )
{
+3 −0
Original line number Diff line number Diff line
@@ -115,6 +115,9 @@ public:
    void   OnEraseBackground( wxEraseEvent& event );
    void   OnChar( wxKeyEvent& event );
    void   OnMouseWheel( wxMouseEvent& event );
#ifdef USE_OSX_MAGNIFY_EVENT
    void   OnMagnify( wxMouseEvent& event );
#endif
    void   OnMouseMove( wxMouseEvent& event );
    void   OnRightClick( wxMouseEvent& event );
    void   OnPopUpMenu( wxCommandEvent& event );
+4 −0
Original line number Diff line number Diff line
@@ -268,6 +268,10 @@ if( USE_WX_GRAPHICS_CONTEXT )
    add_definitions( -DUSE_WX_GRAPHICS_CONTEXT )
endif()

if( USE_OSX_MAGNIFY_EVENT )
    add_definitions( -DUSE_OSX_MAGNIFY_EVENT )
endif()


# Allow user to override the default settings for adding images to menu items.  By default
# images in menu items are enabled on all platforms except OSX.  This can be over ridden by
+33 −0
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels
BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
    EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
    EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel )
#ifdef USE_OSX_MAGNIFY_EVENT
    EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify )
#endif
    EVT_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent )
    EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent )
    EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnCharHook )
@@ -96,7 +99,11 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
    wxASSERT( parent );

#if wxCHECK_VERSION( 2, 9, 5 )
#ifndef USE_OSX_MAGNIFY_EVENT
    ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
#else
    ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
#endif
    DisableKeyboardScrolling();
#endif

@@ -971,6 +978,32 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
    event.Skip();
}

#ifdef USE_OSX_MAGNIFY_EVENT
void EDA_DRAW_PANEL::OnMagnify( wxMouseEvent& event )
{
    // Scale the panel around our cursor position.
    bool warpCursor = false;

    wxPoint cursorPosition = GetParent()->GetCursorPosition(false);
    wxPoint centerPosition =  GetParent()->GetScrollCenterPosition();
    wxPoint vector = centerPosition - cursorPosition;

    double magnification = (event.GetMagnification() + 1.0f);
    double scaleFactor = GetZoom() / magnification;

    // Scale the vector between the cursor and center point
    vector.x /= magnification;
    vector.y /= magnification;

    SetZoom(scaleFactor);

    // Recenter the window along our scaled vector such that the
    // cursor becomes our scale axis, remaining fixed on screen
    GetParent()->RedrawScreen(cursorPosition + vector, warpCursor);

    event.Skip();
}
#endif

void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
{
+5 −1
Original line number Diff line number Diff line
@@ -78,7 +78,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
        wxEVT_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
        wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
        wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_DCLICK,
        wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR, KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE
        wxEVT_MOTION, wxEVT_MOUSEWHEEL, wxEVT_CHAR,
#ifdef USE_OSX_MAGNIFY_EVENT
        wxEVT_MAGNIFY,
#endif        
        KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE
    };

    BOOST_FOREACH( wxEventType eventType, events )
Loading