Pinch to zoom for OS X.

This commit is contained in:
Garth Corral 2015-05-21 22:54:29 +02:00 committed by Maciej Suminski
parent 162ac38639
commit 6eaf029a0e
11 changed files with 209 additions and 1 deletions

View File

@ -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
@ -317,6 +320,22 @@ void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
} }
#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 )
{ {
wxSize size( GetClientSize() ); wxSize size( GetClientSize() );

View File

@ -134,6 +134,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 );

View File

@ -294,6 +294,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()
# By default images in menu items are enabled on all platforms except OSX. # By default images in menu items are enabled on all platforms except OSX.
if( NOT APPLE ) if( NOT APPLE )

View File

@ -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 )
@ -91,7 +94,11 @@ EDA_DRAW_PANEL::EDA_DRAW_PANEL( EDA_DRAW_FRAME* parent, int id,
{ {
wxASSERT( parent ); wxASSERT( parent );
#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();
m_scrollIncrementX = std::min( size.x / 8, 10 ); m_scrollIncrementX = std::min( size.x / 8, 10 );
@ -975,6 +982,34 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
} }
#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 )
{ {
int localrealbutt = 0, localbutt = 0; int localrealbutt = 0, localbutt = 0;

View File

@ -82,7 +82,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 )

View File

@ -89,6 +89,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

View File

@ -250,6 +250,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 ||

View File

@ -40,6 +40,10 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* 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,
@ -157,6 +161,18 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent )
} }
#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 )
{ {
switch( m_state ) switch( m_state )

View File

@ -263,6 +263,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 );

View File

@ -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 onLeave( wxMouseEvent& WXUNUSED( aEvent ) ); void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );

View File

@ -0,0 +1,115 @@
Index: include/wx/event.h
===================================================================
--- include/wx/event.h (revision 78078)
+++ include/wx/event.h (working copy)
@@ -716,6 +716,7 @@
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DOWN, wxMouseEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_UP, wxMouseEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DCLICK, wxMouseEvent);
+wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAGNIFY, wxMouseEvent);
// Character input event type
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR, wxKeyEvent);
@@ -1751,6 +1752,8 @@
bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_DCLICK); }
bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_DCLICK); }
+ bool Magnify() const { return (m_eventType == wxEVT_MAGNIFY); }
+
// True if a button is down and the mouse is moving
bool Dragging() const
{
@@ -1805,6 +1808,8 @@
// Is the system set to do page scrolling?
bool IsPageScroll() const { return ((unsigned int)m_linesPerAction == UINT_MAX); }
+ float GetMagnification() const { return m_magnification; }
+
virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
@@ -1824,6 +1829,8 @@
int m_linesPerAction;
int m_columnsPerAction;
+ float m_magnification;
+
protected:
void Assign(const wxMouseEvent& evt);
@@ -4218,6 +4225,7 @@
#define EVT_MOUSE_AUX2_DOWN(func) wx__DECLARE_EVT0(wxEVT_AUX2_DOWN, wxMouseEventHandler(func))
#define EVT_MOUSE_AUX2_UP(func) wx__DECLARE_EVT0(wxEVT_AUX2_UP, wxMouseEventHandler(func))
#define EVT_MOUSE_AUX2_DCLICK(func) wx__DECLARE_EVT0(wxEVT_AUX2_DCLICK, wxMouseEventHandler(func))
+#define EVT_MAGNIFY(func) wx__DECLARE_EVT0(wxEVT_MAGNIFY, wxMouseEventHandler(func))
// All mouse events
#define EVT_MOUSE_EVENTS(func) \
@@ -4239,7 +4247,8 @@
EVT_MOTION(func) \
EVT_LEAVE_WINDOW(func) \
EVT_ENTER_WINDOW(func) \
- EVT_MOUSEWHEEL(func)
+ EVT_MOUSEWHEEL(func) \
+ EVT_MAGNIFY(func)
// Scrolling from wxWindow (sent to wxScrolledWindow)
#define EVT_SCROLLWIN_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_TOP, wxScrollWinEventHandler(func))
Index: src/common/event.cpp
===================================================================
--- src/common/event.cpp (revision 78078)
+++ src/common/event.cpp (working copy)
@@ -207,6 +207,7 @@
wxDEFINE_EVENT( wxEVT_AUX2_DOWN, wxMouseEvent );
wxDEFINE_EVENT( wxEVT_AUX2_UP, wxMouseEvent );
wxDEFINE_EVENT( wxEVT_AUX2_DCLICK, wxMouseEvent );
+wxDEFINE_EVENT( wxEVT_MAGNIFY, wxMouseEvent );
// Character input event type
wxDEFINE_EVENT( wxEVT_CHAR, wxKeyEvent );
@@ -568,6 +569,8 @@
m_wheelDelta = 0;
m_linesPerAction = 0;
m_columnsPerAction = 0;
+
+ m_magnification = 0.0f;
}
void wxMouseEvent::Assign(const wxMouseEvent& event)
@@ -592,6 +595,8 @@
m_linesPerAction = event.m_linesPerAction;
m_columnsPerAction = event.m_columnsPerAction;
m_wheelAxis = event.m_wheelAxis;
+
+ m_magnification = event.m_magnification;
}
// return true if was a button dclick event
Index: src/osx/cocoa/window.mm
===================================================================
--- src/osx/cocoa/window.mm (revision 78078)
+++ src/osx/cocoa/window.mm (working copy)
@@ -728,6 +728,12 @@
case NSMouseMoved :
wxevent.SetEventType( wxEVT_MOTION ) ;
break;
+
+ case NSEventTypeMagnify:
+ wxevent.SetEventType( wxEVT_MAGNIFY );
+ wxevent.m_magnification = [nsEvent magnification];
+ break;
+
default :
break ;
}
@@ -1749,6 +1755,10 @@
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseEntered:), (IMP) wxOSX_mouseEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(mouseExited:), (IMP) wxOSX_mouseEvent, "v@:@" )
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+ wxOSX_CLASS_ADD_METHOD(c, @selector(magnifyWithEvent:), (IMP)wxOSX_mouseEvent, "v@:@")
+#endif
+
wxOSX_CLASS_ADD_METHOD(c, @selector(cursorUpdate:), (IMP) wxOSX_cursorUpdate, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )