kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #28507
[PATCH] Open polylines in OpenGL GAL
Hi,
Attached patch fixes polylines in GAL: they were drawn always closed
in OpenGL and always open in Cairo.
I think the code could stand a refactor in this area and try to move
the logic into GAL, rather thn duplicating in each implementaiton.
However, since CAIRO_GAL uses the same code for polyline and polygon,
it's not trivial, so I'm going to submit this first, separately.
Cheers,
John
From 4452895a9f014dfe4c4ad98070b5556ccfe81d68 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Tue, 7 Mar 2017 19:17:59 +0800
Subject: [PATCH] GAL: Respect SHAPE_LINE_CHAIN closed setting
When drawing polylines using SHAPE_LINE_CHAIN, the polyline is always
was drawn closed in GAL and open in Cairo, regardless of the state of
SHAPE_LINE_CHAIN.
---
common/gal/cairo/cairo_gal.cpp | 7 ++++++-
common/gal/opengl/opengl_gal.cpp | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp
index 953c76308..724e863d8 100644
--- a/common/gal/cairo/cairo_gal.cpp
+++ b/common/gal/cairo/cairo_gal.cpp
@@ -1081,10 +1081,15 @@ void CAIRO_GAL::drawPoly( const SHAPE_LINE_CHAIN& aLineChain )
if( aLineChain.PointCount() < 2 )
return;
+ auto numPoints = aLineChain.PointCount();
+
+ if( aLineChain.IsClosed() )
+ numPoints += 1;
+
const VECTOR2I start = aLineChain.CPoint( 0 );
cairo_move_to( currentContext, start.x, start.y );
- for( int i = 1; i < aLineChain.PointCount(); ++i )
+ for( int i = 1; i < numPoints; ++i )
{
const VECTOR2I& p = aLineChain.CPoint( i );
cairo_line_to( currentContext, p.x, p.y );
diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp
index a2480411b..8a6ddf054 100644
--- a/common/gal/opengl/opengl_gal.cpp
+++ b/common/gal/opengl/opengl_gal.cpp
@@ -640,7 +640,12 @@ void OPENGL_GAL::DrawPolyline( const VECTOR2D aPointList[], int aListSize )
void OPENGL_GAL::DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain )
{
- drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, aLineChain.PointCount() + 1 );
+ auto numPoints = aLineChain.PointCount();
+
+ if( aLineChain.IsClosed() )
+ numPoints += 1;
+
+ drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints );
}
--
2.12.0
Follow ups