← Back to team overview

kicad-developers team mailing list archive

[PATCH] Add support for panning with left and right mouse buttons

 

Hi all,

This patch extends the VIEW_CONTROLS to allow optional panning with left or
right buttons in addition to middle.  I plan to make use of this in
GerbView for an easy panning mode that works well on laptops and 2-button
mice, and this might also be useful in other applications -- drag-to-pan
with the right button is a handy thing to enable in editing tools to make
them usable when you don't have a middle button.

-Jon
From a8b785ab4657061ca9b0ab3ac29cda82e9530601 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Tue, 5 Sep 2017 21:28:01 -0400
Subject: [PATCH] Add support for panning with left and right mouse buttons

---
 common/view/view_controls.cpp    |  2 ++
 common/view/wx_view_controls.cpp | 10 ++++++++--
 include/view/view_controls.h     | 12 ++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/common/view/view_controls.cpp b/common/view/view_controls.cpp
index eedfd766e..46be59469 100644
--- a/common/view/view_controls.cpp
+++ b/common/view/view_controls.cpp
@@ -66,6 +66,8 @@ void VC_SETTINGS::Reset()
     m_autoPanSpeed = 0.15;
     m_warpCursor = false;
     m_enableMousewheelPan = false;
+    m_panWithRightButton = false;
+    m_panWithLeftButton = false;
 }
 
 
diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp
index 9f9dcdc8b..e16b15a1b 100644
--- a/common/view/wx_view_controls.cpp
+++ b/common/view/wx_view_controls.cpp
@@ -55,6 +55,10 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel
                             wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
     m_parentPanel->Connect( wxEVT_LEFT_DOWN,
                             wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
+    m_parentPanel->Connect( wxEVT_RIGHT_UP,
+                            wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
+    m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
+                            wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
 #if defined _WIN32 || defined _WIN64
     m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
                             wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
@@ -213,7 +217,9 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
     {
     case IDLE:
     case AUTO_PANNING:
-        if( aEvent.MiddleDown() )
+        if( aEvent.MiddleDown() ||
+            ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
+            ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
         {
             m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
             m_lookStartPoint = m_view->GetCenter();
@@ -226,7 +232,7 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent )
         break;
 
     case DRAG_PANNING:
-        if( aEvent.MiddleUp() )
+        if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
             m_state = IDLE;
 
         break;
diff --git a/include/view/view_controls.h b/include/view/view_controls.h
index acc2df395..bc01d0f31 100644
--- a/include/view/view_controls.h
+++ b/include/view/view_controls.h
@@ -83,6 +83,12 @@ struct VC_SETTINGS
 
     ///> Mousewheel (2-finger touchpad) panning
     bool m_enableMousewheelPan;
+
+    ///> Allow panning with the right button in addition to middle
+    bool m_panWithRightButton;
+
+    ///> Allow panning with the left button in addition to middle
+    bool m_panWithLeftButton;
 };
 
 
@@ -309,6 +315,12 @@ public:
      */
     virtual void CenterOnCursor() const = 0;
 
+    void SetAdditionalPanButtons( bool aLeft = false, bool aRight = false )
+    {
+        m_settings.m_panWithLeftButton = aLeft;
+        m_settings.m_panWithRightButton = aRight;
+    }
+
     /**
      * Function Reset()
      * Restores the default VIEW_CONTROLS settings.
-- 
2.11.0


Follow ups