← Back to team overview

kicad-developers team mailing list archive

Middle mouse button panning.

 

Would one of our esteemed OSX developers please test this patch on OSX.
 It fixes a bug introduced with the middle mouse button panning:

https://bugs.launchpad.net/kicad/+bug/1462067

It also fixes an unreported panning bug when the cursor leaves the
canvas while panning, the cross-hair count gets messed up and the cross
hair is no longer displayed.

Also, there are some serious redraw issues when the middle mouse button
panning is allowed to extend past the scrollbar limits when zoomed all
the way out (board is very small).  Does this even make sense to allow
panning past the scrollbar limits?  When the scrollbar limit option is
checked, the panning works as expected.  Any thoughts?

Thanks,

Wayne
=== modified file 'common/draw_panel.cpp'
--- common/draw_panel.cpp	2015-07-15 15:32:30 +0000
+++ common/draw_panel.cpp	2015-07-18 19:51:55 +0000
@@ -70,6 +70,7 @@
 // Events used by EDA_DRAW_PANEL
 BEGIN_EVENT_TABLE( EDA_DRAW_PANEL, wxScrolledWindow )
     EVT_LEAVE_WINDOW( EDA_DRAW_PANEL::OnMouseLeaving )
+    EVT_ENTER_WINDOW( EDA_DRAW_PANEL::OnMouseEntering )
     EVT_MOUSEWHEEL( EDA_DRAW_PANEL::OnMouseWheel )
 #ifdef USE_OSX_MAGNIFY_EVENT
     EVT_MAGNIFY( EDA_DRAW_PANEL::OnMagnify )
@@ -187,6 +188,7 @@
     return parentFrame->GetScreen();
 }
 
+
 wxPoint EDA_DRAW_PANEL::ToDeviceXY( const wxPoint& pos )
 {
     wxPoint ret;
@@ -196,6 +198,7 @@
     return ret;
 }
 
+
 wxPoint EDA_DRAW_PANEL::ToLogicalXY( const wxPoint& pos )
 {
     wxPoint ret;
@@ -205,6 +208,7 @@
     return ret;
 }
 
+
 void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, EDA_COLOR_T aColor )
 {
     if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair )
@@ -886,6 +890,17 @@
 }
 
 
+void EDA_DRAW_PANEL::OnMouseEntering( wxMouseEvent& aEvent )
+{
+    // This is an ugly hack that fixes some cross hair display bugs when the mouse leaves the
+    // canvas area during middle button mouse panning.
+    if( m_cursorLevel != 0 )
+        m_cursorLevel = 0;
+
+    aEvent.Skip();
+}
+
+
 void EDA_DRAW_PANEL::OnMouseLeaving( wxMouseEvent& event )
 {
     if( m_mouseCaptureCallback == NULL )          // No command in progress.
@@ -1151,6 +1166,7 @@
     if( event.MiddleIsDown() && m_enableMiddleButtonPan )
     {
         wxPoint currentPosition = event.GetPosition();
+
         if( m_panScrollbarLimits )
         {
             int x, y;
@@ -1201,7 +1217,7 @@
                 shouldMoveCursor = true;
             }
 
-            if ( shouldMoveCursor )
+            if( shouldMoveCursor )
                 WarpPointer( currentPosition.x, currentPosition.y );
 
             Scroll( x/ppux, y/ppuy );
@@ -1460,15 +1476,21 @@
     int ppux, ppuy;
     int unitsX, unitsY;
     int maxX, maxY;
+    int tmpX, tmpY;
 
     GetViewStart( &x, &y );
     GetScrollPixelsPerUnit( &ppux, &ppuy );
     GetVirtualSize( &unitsX, &unitsY );
+    tmpX = x;
+    tmpY = y;
     maxX = unitsX;
     maxY = unitsY;
     unitsX /= ppux;
     unitsY /= ppuy;
 
+    wxLogTrace( KICAD_TRACE_COORDS,
+                wxT( "Scroll center position before pan: (%d, %d)" ), tmpX, tmpY );
+
     switch( event.GetId() )
     {
     case ID_PAN_UP:
@@ -1491,17 +1513,45 @@
         wxLogDebug( wxT( "Unknown ID %d in EDA_DRAW_PANEL::OnPan()." ), event.GetId() );
     }
 
+    bool updateCenterScrollPos = true;
+
     if( x < 0 )
+    {
         x = 0;
+        updateCenterScrollPos = false;
+    }
 
     if( y < 0 )
+    {
         y = 0;
+        updateCenterScrollPos = false;
+    }
 
     if( x > maxX )
+    {
         x = maxX;
+        updateCenterScrollPos = false;
+    }
 
     if( y > maxY )
+    {
         y = maxY;
+        updateCenterScrollPos = false;
+    }
+
+    // Don't update the scroll position beyond the scroll limits.
+    if( updateCenterScrollPos )
+    {
+        double scale = GetParent()->GetScreen()->GetScalingFactor();
+
+        wxPoint center = GetParent()->GetScrollCenterPosition();
+        center.x += KiROUND( (double) ( x - tmpX ) / scale );
+        center.y += KiROUND( (double) ( y - tmpY ) / scale );
+        GetParent()->SetScrollCenterPosition( center );
+
+        wxLogTrace( KICAD_TRACE_COORDS,
+                    wxT( "Scroll center position after pan: (%d, %d)" ), center.x, center.y );
+    }
 
     Scroll( x/ppux, y/ppuy );
 }

=== modified file 'include/class_drawpanel.h'
--- include/class_drawpanel.h	2015-07-09 08:18:27 +0000
+++ include/class_drawpanel.h	2015-07-17 21:02:16 +0000
@@ -267,6 +267,7 @@
     void OnMagnify( wxMouseEvent& event );
 #endif
     void OnMouseEvent( wxMouseEvent& event );
+    void OnMouseEntering( wxMouseEvent& aEvent );
     void OnMouseLeaving( wxMouseEvent& event );
     void OnKeyEvent( wxKeyEvent& event );
     void OnCharHook( wxKeyEvent& event );


Follow ups