← Back to team overview

kicad-developers team mailing list archive

[PATCH] BRIGHT_BOX line width is zoom independent

 

During my work on the Partial Selection feature (
https://lists.launchpad.net/kicad-developers/msg29329.html) I noticed the
BRIGHT_BOX tool (used in selection clarification) for the first time.

I also noticed that the line width for the BRIGHT_BOX changed with zoom
level, which seems like the incorrect behaviour to me (it's not an actual
item on the board and the width becomes very large at high zoom levels).

Attached is a simple patch that allows line widths to be specified as
zoom-independent (for Cairo and OpenGL GAL).

BRIGHT_BOX line is now 2 pixels wide no matter the zoom.

Cheers,
Oliver
From 08211aef3d619034f62bf096ed65375259051816 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@xxxxxxxxx>
Date: Tue, 9 May 2017 22:29:20 +1000
Subject: [PATCH] Zoom-independent stroke width for CAIRO_GAL

- SetLineWidth now has extra parameter aIgnoreZoom
- Default value is false (thus does not change existing code)
- Brightbox line width is fixed independent of zoom
---
 common/gal/cairo/cairo_gal.cpp           |  7 ++++++-
 common/preview_items/bright_box.cpp      |  2 +-
 include/gal/cairo/cairo_gal.h            |  2 +-
 include/gal/graphics_abstraction_layer.h |  7 ++++++-
 pcbnew/tools/pcb_bright_box.cpp          | 35 +++++++++++++++++++++-----------
 5 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp
index 1324811..f77e69d 100644
--- a/common/gal/cairo/cairo_gal.cpp
+++ b/common/gal/cairo/cairo_gal.cpp
@@ -456,10 +456,15 @@ void CAIRO_GAL::SetFillColor( const COLOR4D& aColor )
 }
 
 
-void CAIRO_GAL::SetLineWidth( double aLineWidth )
+void CAIRO_GAL::SetLineWidth( double aLineWidth, bool aIgnoresScale )
 {
     storePath();
 
+    if( aIgnoresScale )
+    {
+        aLineWidth /= GetWorldScale();
+    }
+
     lineWidth = aLineWidth;
 
     if( isGrouping )
diff --git a/common/preview_items/bright_box.cpp b/common/preview_items/bright_box.cpp
index cc55dfa..4bfb453 100644
--- a/common/preview_items/bright_box.cpp
+++ b/common/preview_items/bright_box.cpp
@@ -29,7 +29,7 @@
 using namespace KIGFX;
 
 const double BRIGHT_BOX::LINE_WIDTH = 10000.0;
-const COLOR4D BRIGHT_BOX::BOX_COLOR = KIGFX::COLOR4D( 0.0, 1.0, 0.0, 1.0 );
+const COLOR4D BRIGHT_BOX::BOX_COLOR = KIGFX::COLOR4D( 0.0, 1.0, 0.0, 0.9 );
 
 BRIGHT_BOX::BRIGHT_BOX() :
     EDA_ITEM( NOT_USED ),    // this item is never added to a BOARD so it needs no type
diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h
index f86b5bf..2089ffc 100644
--- a/include/gal/cairo/cairo_gal.h
+++ b/include/gal/cairo/cairo_gal.h
@@ -169,7 +169,7 @@ public:
     virtual void SetFillColor( const COLOR4D& aColor ) override;
 
     /// @copydoc GAL::SetLineWidth()
-    virtual void SetLineWidth( double aLineWidth ) override;
+    virtual void SetLineWidth( double aLineWidth, bool aIgnoresScale = false ) override;
 
     /// @copydoc GAL::SetLayerDepth()
     virtual void SetLayerDepth( double aLayerDepth ) override;
diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h
index 00e5bc9..a052ef2 100644
--- a/include/gal/graphics_abstraction_layer.h
+++ b/include/gal/graphics_abstraction_layer.h
@@ -262,8 +262,13 @@ public:
      *
      * @param aLineWidth is the line width.
      */
-    virtual void SetLineWidth( double aLineWidth )
+    virtual void SetLineWidth( double aLineWidth, bool aIgnoresScale = false )
     {
+        if( aIgnoresScale )
+        {
+            aLineWidth /= GetWorldScale();
+        }
+
         lineWidth = aLineWidth;
     }
 
diff --git a/pcbnew/tools/pcb_bright_box.cpp b/pcbnew/tools/pcb_bright_box.cpp
index aee6462..53dfd66 100644
--- a/pcbnew/tools/pcb_bright_box.cpp
+++ b/pcbnew/tools/pcb_bright_box.cpp
@@ -27,7 +27,7 @@
 
 using namespace KIGFX;
 
-const double PCB_BRIGHT_BOX::PCB_LINE_WIDTH = 100000.0;
+const double PCB_BRIGHT_BOX::PCB_LINE_WIDTH = 2.0;
 
 
 PCB_BRIGHT_BOX::PCB_BRIGHT_BOX() :
@@ -42,21 +42,32 @@ void PCB_BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
     if( !m_item )
         return;
 
-    if( m_item->Type() == PCB_TRACE_T )
+    auto gal = aView->GetGAL();
+
+    gal->SetIsStroke( true );
+    gal->SetIsFill( false );
+    gal->SetLineWidth( m_lineWidth, true );
+    gal->SetStrokeColor( m_color );
+
+    switch( m_item->Type() )
     {
-        const TRACK* track = static_cast<const TRACK*>( m_item );
+    default:
+        // Default implementation draws item bounding box
+        {
+        BOX2I box = m_item->ViewBBox();
 
-        auto gal = aView->GetGAL();
+        gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
+        }
+        break;
 
-        gal->SetIsStroke( true );
-        gal->SetIsFill( false );
-        gal->SetLineWidth( m_lineWidth );
-        gal->SetStrokeColor( m_color );
+    // PCB Segment
+    case PCB_TRACE_T:
+        {
+        const TRACK* track = static_cast<const TRACK*>( m_item );
 
         gal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() );
-    }
-    else
-    {
-        BRIGHT_BOX::ViewDraw( aLayer, aView );
+        }
+        break;
+
     }
 }
-- 
2.7.4