kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #29761
[GAL] Added fixed-width line rendering
This patch adds zoom-independent fixed-width line rendering to GAL.
GAL drawing tools can call SetFixedLineWidth( width ) to draw a line that
is the same width on screen (pixels) independent of the zoom level.
I have implemented this in two locations:
a) PCB_BRIGHTBOX - the selection clarification bright-box is very thin at
wide zoom, and very wide at narrow zoom. Now it is 3 pixels thick at all
zoom
b) RATS_NEST - Increased this to 2 pixels wide, it is much easier to see!
From 966c089b99ef77ecace7d340dfc274fc15fb23e5 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@xxxxxxxxx>
Date: Thu, 22 Jun 2017 23:41:00 +1000
Subject: [PATCH] Added fixed-width line rendering to GAL
Updated rendering for:
- BRIGHT_BOX
- RATSNEST
---
common/preview_items/bright_box.cpp | 4 ++--
include/gal/graphics_abstraction_layer.h | 10 ++++++++++
pcbnew/ratsnest_viewitem.cpp | 2 +-
pcbnew/tools/pcb_bright_box.cpp | 6 +-----
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/common/preview_items/bright_box.cpp b/common/preview_items/bright_box.cpp
index cc55dfa..8709ede 100644
--- a/common/preview_items/bright_box.cpp
+++ b/common/preview_items/bright_box.cpp
@@ -28,7 +28,7 @@
using namespace KIGFX;
-const double BRIGHT_BOX::LINE_WIDTH = 10000.0;
+const double BRIGHT_BOX::LINE_WIDTH = 3.0;
const COLOR4D BRIGHT_BOX::BOX_COLOR = KIGFX::COLOR4D( 0.0, 1.0, 0.0, 1.0 );
BRIGHT_BOX::BRIGHT_BOX() :
@@ -49,7 +49,7 @@ void BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal->SetIsStroke( true );
gal->SetIsFill( false );
- gal->SetLineWidth( m_lineWidth );
+ gal->SetFixedLineWidth( m_lineWidth );
gal->SetStrokeColor( m_color );
BOX2I box = m_item->ViewBBox();
diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h
index 1cac4e9..11d6047 100644
--- a/include/gal/graphics_abstraction_layer.h
+++ b/include/gal/graphics_abstraction_layer.h
@@ -259,6 +259,16 @@ public:
}
/**
+ * @brief Set a fixed line width which appears the same independent of zoom
+ *
+ * @param aLineWidth is the line width (in view pixels)
+ */
+ virtual void SetFixedLineWidth( double aLineWidth )
+ {
+ SetLineWidth( aLineWidth / GetWorldScale() );
+ }
+
+ /**
* @brief Set the line width.
*
* @param aLineWidth is the line width.
diff --git a/pcbnew/ratsnest_viewitem.cpp b/pcbnew/ratsnest_viewitem.cpp
index 2d8fff6..17f2bf2 100644
--- a/pcbnew/ratsnest_viewitem.cpp
+++ b/pcbnew/ratsnest_viewitem.cpp
@@ -58,7 +58,7 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
auto gal = aView->GetGAL();
gal->SetIsStroke( true );
gal->SetIsFill( false );
- gal->SetLineWidth( 1.0 );
+ gal->SetFixedLineWidth( 2.0 );
auto rs = aView->GetPainter()->GetSettings();
auto color = rs->GetColor( NULL, LAYER_RATSNEST );
int highlightedNet = rs->GetHighlightNetCode();
diff --git a/pcbnew/tools/pcb_bright_box.cpp b/pcbnew/tools/pcb_bright_box.cpp
index aee6462..e2b0abd 100644
--- a/pcbnew/tools/pcb_bright_box.cpp
+++ b/pcbnew/tools/pcb_bright_box.cpp
@@ -27,13 +27,9 @@
using namespace KIGFX;
-const double PCB_BRIGHT_BOX::PCB_LINE_WIDTH = 100000.0;
-
-
PCB_BRIGHT_BOX::PCB_BRIGHT_BOX() :
BRIGHT_BOX()
{
- SetLineWidth( PCB_LINE_WIDTH );
}
@@ -50,7 +46,7 @@ void PCB_BRIGHT_BOX::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal->SetIsStroke( true );
gal->SetIsFill( false );
- gal->SetLineWidth( m_lineWidth );
+ gal->SetFixedLineWidth( m_lineWidth );
gal->SetStrokeColor( m_color );
gal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() );
--
2.7.4
Follow ups