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

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
...@@ -66,6 +66,9 @@ BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas ) ...@@ -66,6 +66,9 @@ BEGIN_EVENT_TABLE( EDA_3D_CANVAS, wxGLCanvas )
// mouse events // mouse events
EVT_RIGHT_DOWN( EDA_3D_CANVAS::OnRightClick ) EVT_RIGHT_DOWN( EDA_3D_CANVAS::OnRightClick )
EVT_MOUSEWHEEL( EDA_3D_CANVAS::OnMouseWheel ) EVT_MOUSEWHEEL( EDA_3D_CANVAS::OnMouseWheel )
#ifdef USE_OSX_MAGNIFY_EVENT
EVT_MAGNIFY( EDA_3D_CANVAS::OnMagnify )
#endif
EVT_MOTION( EDA_3D_CANVAS::OnMouseMove ) EVT_MOTION( EDA_3D_CANVAS::OnMouseMove )
// other events // other events
...@@ -281,6 +284,21 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event ) ...@@ -281,6 +284,21 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
GetPrm3DVisu().m_Beginy = event.GetY(); 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 ) void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event )
{ {
......
...@@ -115,6 +115,9 @@ public: ...@@ -115,6 +115,9 @@ public:
void OnEraseBackground( wxEraseEvent& event ); void OnEraseBackground( wxEraseEvent& event );
void OnChar( wxKeyEvent& event ); void OnChar( wxKeyEvent& event );
void OnMouseWheel( wxMouseEvent& event ); void OnMouseWheel( wxMouseEvent& event );
#ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event );
#endif
void OnMouseMove( wxMouseEvent& event ); void OnMouseMove( wxMouseEvent& event );
void OnRightClick( wxMouseEvent& event ); void OnRightClick( wxMouseEvent& event );
void OnPopUpMenu( wxCommandEvent& event ); void OnPopUpMenu( wxCommandEvent& event );
......
...@@ -268,6 +268,10 @@ if( USE_WX_GRAPHICS_CONTEXT ) ...@@ -268,6 +268,10 @@ if( USE_WX_GRAPHICS_CONTEXT )
add_definitions( -DUSE_WX_GRAPHICS_CONTEXT ) add_definitions( -DUSE_WX_GRAPHICS_CONTEXT )
endif() 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 # 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 # images in menu items are enabled on all platforms except OSX. This can be over ridden by
......
...@@ -70,6 +70,9 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels ...@@ -70,6 +70,9 @@ static const int CURSOR_SIZE = 12; ///< Cursor size in pixels
BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow ) BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving ) EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel ) 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_MOUSE_EVENTS( EDA_DRAW_PANEL::OnMouseEvent )
EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent ) EVT_CHAR( EDA_DRAW_PANEL::OnKeyEvent )
EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnCharHook ) EVT_CHAR_HOOK( EDA_DRAW_PANEL::OnCharHook )
...@@ -96,7 +99,11 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id, ...@@ -96,7 +99,11 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
wxASSERT( parent ); wxASSERT( parent );
#if wxCHECK_VERSION( 2, 9, 5 ) #if wxCHECK_VERSION( 2, 9, 5 )
#ifndef USE_OSX_MAGNIFY_EVENT
ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS ); ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
#else
ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
#endif
DisableKeyboardScrolling(); DisableKeyboardScrolling();
#endif #endif
...@@ -971,6 +978,32 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event ) ...@@ -971,6 +978,32 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
event.Skip(); 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 ) void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
{ {
......
...@@ -78,7 +78,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ...@@ -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_LEFT_UP, wxEVT_LEFT_DOWN, wxEVT_LEFT_DCLICK,
wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK, wxEVT_RIGHT_UP, wxEVT_RIGHT_DOWN, wxEVT_RIGHT_DCLICK,
wxEVT_MIDDLE_UP, wxEVT_MIDDLE_DOWN, wxEVT_MIDDLE_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 ) BOOST_FOREACH( wxEventType eventType, events )
......
...@@ -85,6 +85,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener, ...@@ -85,6 +85,9 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#ifdef USE_OSX_MAGNIFY_EVENT
Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#endif
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) ); Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
#endif #endif
......
...@@ -247,6 +247,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) ...@@ -247,6 +247,9 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
// Mouse handling // Mouse handling
if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL || if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL ||
#ifdef USE_OSX_MAGNIFY_EVENT
type == wxEVT_MAGNIFY ||
#endif
type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP ||
type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ||
......
...@@ -39,6 +39,10 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) : ...@@ -39,6 +39,10 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
{ {
m_parentPanel->Connect( wxEVT_MOTION, m_parentPanel->Connect( wxEVT_MOTION,
wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this ); wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
#ifdef USE_OSX_MAGNIFY_EVENT
m_parentPanel->Connect( wxEVT_MAGNIFY,
wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
#endif
m_parentPanel->Connect( wxEVT_MOUSEWHEEL, m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this ); wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
m_parentPanel->Connect( wxEVT_MIDDLE_UP, m_parentPanel->Connect( wxEVT_MIDDLE_UP,
...@@ -175,6 +179,16 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) ...@@ -175,6 +179,16 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
aEvent.Skip(); aEvent.Skip();
} }
#ifdef USE_OSX_MAGNIFY_EVENT
void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
{
// Scale based on the magnification from our underlying magnification event.
VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
setScale( m_view->GetScale() * (aEvent.GetMagnification() + 1.0f), anchor );
aEvent.Skip();
}
#endif
void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
{ {
......
...@@ -256,6 +256,9 @@ public: ...@@ -256,6 +256,9 @@ public:
*</p> *</p>
*/ */
void OnMouseWheel( wxMouseEvent& event ); void OnMouseWheel( wxMouseEvent& event );
#ifdef USE_OSX_MAGNIFY_EVENT
void OnMagnify( wxMouseEvent& event );
#endif
void OnMouseEvent( wxMouseEvent& event ); void OnMouseEvent( wxMouseEvent& event );
void OnMouseLeaving( wxMouseEvent& event ); void OnMouseLeaving( wxMouseEvent& event );
void OnKeyEvent( wxKeyEvent& event ); void OnKeyEvent( wxKeyEvent& event );
......
...@@ -54,6 +54,9 @@ public: ...@@ -54,6 +54,9 @@ public:
/// Handler functions /// Handler functions
void onWheel( wxMouseEvent& aEvent ); void onWheel( wxMouseEvent& aEvent );
void onMotion( wxMouseEvent& aEvent ); void onMotion( wxMouseEvent& aEvent );
#ifdef USE_OSX_MAGNIFY_EVENT
void onMagnify( wxMouseEvent& aEvent );
#endif
void onButton( wxMouseEvent& aEvent ); void onButton( wxMouseEvent& aEvent );
void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
void onTimer( wxTimerEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment