KiCad PCB EDA Suite
gr_basic.cpp File Reference
#include <gr_basic.h>
#include <trigo.h>
#include <eda_item.h>
#include <math_for_graphics.h>
#include <wx/graphics.h>
#include <geometry/geometry_utils.h>
#include <math/util.h>
#include <algorithm>
#include <SutherlandHodgmanClipPoly.h>

Go to the source code of this file.

Macros

#define DEBUG_DUMP_CLIP_ERROR_COORDS   0
 
#define DEBUG_DUMP_CLIP_COORDS   0
 

Functions

static void ClipAndDrawPoly (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint *Points, int n)
 Used to clip a polygon and draw it as Filled Polygon. More...
 
static void GRSRect (EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor)
 
static void WinClipAndDrawLine (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width)
 
void GRResetPenAndBrush (wxDC *DC)
 
void GRSetColorPen (wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
 
void GRSetBrush (wxDC *DC, const COLOR4D &Color, bool fill)
 
void GRForceBlackPen (bool flagforce)
 
bool GetGRForceBlackPenState (void)
 
void GRLine (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
 
void GRLine (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, const COLOR4D &aColor, wxPenStyle aStyle)
 
void GRMoveTo (int x, int y)
 
void GRLineTo (EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, const COLOR4D &Color)
 
void GRCSegm (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, const COLOR4D &Color)
 
void GRCSegm (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color)
 
void GRCSegm (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, const COLOR4D &aColor)
 
void GRFillCSegm (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color)
 
void GRFilledSegment (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, const COLOR4D &aColor)
 
static bool IsGRSPolyDrawable (EDA_RECT *ClipBox, int n, const wxPoint *Points)
 
static void GRSPoly (EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 Draw a new polyline and fill it if Fill, in screen space. More...
 
static void GRSClosedPoly (EDA_RECT *aClipBox, wxDC *aDC, int aPointCount, const wxPoint *aPoints, bool aFill, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
 Draw a new closed polyline and fill it if Fill, in screen space. More...
 
void GRPoly (EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 Draw a new polyline and fill it if Fill, in drawing space. More...
 
void GRClosedPoly (EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, const COLOR4D &Color, const COLOR4D &BgColor)
 Draw a closed polyline and fill it if Fill, in object space. More...
 
void GRClosedPoly (EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 Draw a closed polygon onto the drawing context aDC and optionally fills and/or draws a border around it. More...
 
static bool clipCircle (EDA_RECT *aClipBox, int xc, int yc, int r, int aWidth)
 
void GRCircle (EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, const COLOR4D &Color)
 Draw a circle onto the drawing context aDC centered at the user coordinates (x,y). More...
 
void GRCircle (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, int aRadius, int aWidth, const COLOR4D &aColor)
 
void GRFilledCircle (EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 
void GRFilledCircle (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, int aRadius, const COLOR4D &aColor)
 
void GRArc1 (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int xc, int yc, int width, const COLOR4D &Color)
 
void GRArc1 (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &aCenter, int aWidth, const COLOR4D &aColor)
 
void GRFilledArc1 (EDA_RECT *ClipBox, wxDC *DC, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &aCenter, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 
void GRArc (EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, double StAngle, double EndAngle, int r, const COLOR4D &Color)
 
void GRArc (EDA_RECT *ClipBox, wxDC *DC, int x, int y, double StAngle, double EndAngle, int r, int width, const COLOR4D &Color)
 
void GRRect (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color)
 
void GRFilledRect (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, const COLOR4D &Color, const COLOR4D &BgColor)
 
void GRFilledRect (EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, const COLOR4D &BgColor)
 
void GRSFilledRect (EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
 

Variables

static const bool FILLED = true
 
static const bool NOT_FILLED = false
 
GR_DRAWMODE g_XorMode = GR_NXOR
 
static int GRLastMoveToX
 
static int GRLastMoveToY
 
static bool s_ForceBlackPen
 
static int xcliplo = 0
 
static int ycliplo = 0
 
static int xcliphi = 2000
 
static int ycliphi = 2000
 
static COLOR4D s_DC_lastbrushcolor (0, 0, 0, 0)
 
static bool s_DC_lastbrushfill = false
 
static wxDC * s_DC_lastDC = nullptr
 

Macro Definition Documentation

◆ DEBUG_DUMP_CLIP_COORDS

#define DEBUG_DUMP_CLIP_COORDS   0

Definition at line 59 of file gr_basic.cpp.

◆ DEBUG_DUMP_CLIP_ERROR_COORDS

#define DEBUG_DUMP_CLIP_ERROR_COORDS   0

Definition at line 58 of file gr_basic.cpp.

Function Documentation

◆ ClipAndDrawPoly()

void ClipAndDrawPoly ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint *  Points,
int  n 
)
static

Used to clip a polygon and draw it as Filled Polygon.

Uses the Sutherland and Hodgman algo to clip the given poly against a rectangle. This rectangle is the drawing area this is useful under Linux (2009) because filled polygons are incorrectly drawn if they have too large coordinates (seems due to integer overflows in calculations). Could be removed in some years, if become unnecessary.

Definition at line 775 of file gr_basic.cpp.

776 {
777  if( aClipBox == nullptr )
778  {
779  aDC->DrawPolygon( n, Points );
780  return;
781  }
782 
783  // A clip box exists: clip and draw the polygon.
784  static std::vector<wxPoint> clippedPolygon;
785  static pointVector inputPolygon, outputPolygon;
786 
787  inputPolygon.clear();
788  outputPolygon.clear();
789  clippedPolygon.clear();
790 
791  for( int ii = 0; ii < n; ii++ )
792  inputPolygon.push_back( PointF( (REAL) Points[ii].x, (REAL) Points[ii].y ) );
793 
794  RectF window( (REAL) aClipBox->GetX(), (REAL) aClipBox->GetY(),
795  (REAL) aClipBox->GetWidth(), (REAL) aClipBox->GetHeight() );
796 
797  SutherlandHodgman sh( window );
798  sh.Clip( inputPolygon, outputPolygon );
799 
800  for( cpointIterator cit = outputPolygon.begin(); cit != outputPolygon.end(); ++cit )
801  {
802  clippedPolygon.emplace_back( KiROUND( cit->X ), KiROUND( cit->Y ) );
803  }
804 
805  if( clippedPolygon.size() )
806  aDC->DrawPolygon( clippedPolygon.size(), &clippedPolygon[0] );
807 }
int GetX() const
Definition: eda_rect.h:107
int GetWidth() const
Definition: eda_rect.h:118
int GetHeight() const
Definition: eda_rect.h:119
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), and KiROUND().

Referenced by GRSClosedPoly(), GRSFilledRect(), and GRSPoly().

◆ clipCircle()

static bool clipCircle ( EDA_RECT aClipBox,
int  xc,
int  yc,
int  r,
int  aWidth 
)
static

Definition at line 477 of file gr_basic.cpp.

478 {
479  // Clip circles that are outside the ClipBox.
480  if( aClipBox )
481  {
482  int x0, y0, xm, ym;
483  x0 = aClipBox->GetX();
484  y0 = aClipBox->GetY();
485  xm = aClipBox->GetRight();
486  ym = aClipBox->GetBottom();
487 
488  r += aWidth;
489 
490  if( xc < ( x0 - r ) )
491  return true;
492 
493  if( yc < ( y0 - r ) )
494  return true;
495 
496  if( xc > ( r + xm ) )
497  return true;
498 
499  if( yc > ( r + ym ) )
500  return true;
501  }
502 
503  return false;
504 }
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
int GetRight() const
Definition: eda_rect.h:120
E_SERIE r
Definition: eserie.cpp:41
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), and r.

Referenced by GRCircle(), and GRFilledCircle().

◆ GetGRForceBlackPenState()

bool GetGRForceBlackPenState ( void  )
Returns
True if a black pen was forced or false if not forced.

Definition at line 191 of file gr_basic.cpp.

192 {
193  return s_ForceBlackPen;
194 }
static bool s_ForceBlackPen
Definition: gr_basic.cpp:78

References s_ForceBlackPen.

Referenced by BITMAP_BASE::DrawBitmap(), SCH_SHEET::Print(), and LIB_SYMBOL::Print().

◆ GRArc() [1/2]

void GRArc ( EDA_RECT ClipBox,
wxDC *  DC,
int  xc,
int  yc,
double  StAngle,
double  EndAngle,
int  r,
const COLOR4D Color 
)

Definition at line 620 of file gr_basic.cpp.

622 {
623  int x1, y1, x2, y2;
624 
625  /* Clip arcs off screen */
626  if( ClipBox )
627  {
628  int radius = r + 1;
629  int x0, y0, xm, ym, x, y;
630  x0 = ClipBox->GetX();
631  y0 = ClipBox->GetY();
632  xm = ClipBox->GetRight();
633  ym = ClipBox->GetBottom();
634  x = xc;
635  y = yc;
636 
637  if( x < ( x0 - radius ) )
638  return;
639 
640  if( y < ( y0 - radius ) )
641  return;
642 
643  if( x > ( xm + radius ) )
644  return;
645 
646  if( y > ( ym + radius ) )
647  return;
648  }
649 
650  x1 = r;
651  y1 = 0;
652  RotatePoint( &x1, &y1, EndAngle );
653 
654  x2 = r;
655  y2 = 0;
656  RotatePoint( &x2, &y2, StAngle );
657 
658  GRSetBrush( DC, Color, NOT_FILLED );
659  GRSetColorPen( DC, Color );
660  DC->DrawArc( xc + x1, yc - y1, xc + x2, yc - y2, xc, yc );
661 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
int GetX() const
Definition: eda_rect.h:107
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int GetBottom() const
Definition: eda_rect.h:123
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static const bool NOT_FILLED
Definition: gr_basic.cpp:33
int GetRight() const
Definition: eda_rect.h:120
E_SERIE r
Definition: eserie.cpp:41
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), GRSetBrush(), GRSetColorPen(), NOT_FILLED, r, and RotatePoint().

◆ GRArc() [2/2]

void GRArc ( EDA_RECT ClipBox,
wxDC *  DC,
int  x,
int  y,
double  StAngle,
double  EndAngle,
int  r,
int  width,
const COLOR4D Color 
)

Definition at line 664 of file gr_basic.cpp.

666 {
667  int x1, y1, x2, y2;
668 
669  /* Clip arcs off screen. */
670  if( ClipBox )
671  {
672  int x0, y0, xm, ym;
673  x0 = ClipBox->GetX();
674  y0 = ClipBox->GetY();
675  xm = ClipBox->GetRight();
676  ym = ClipBox->GetBottom();
677 
678  if( x < ( x0 - r - width ) )
679  return;
680 
681  if( y < ( y0 - r - width ) )
682  return;
683 
684  if( x > ( r + xm + width ) )
685  return;
686 
687  if( y > ( r + ym + width ) )
688  return;
689  }
690 
691  x1 = r;
692  y1 = 0;
693  RotatePoint( &x1, &y1, EndAngle );
694 
695  x2 = r;
696  y2 = 0;
697  RotatePoint( &x2, &y2, StAngle );
698 
699  GRSetBrush( DC, Color );
700  GRSetColorPen( DC, Color, width );
701  DC->DrawArc( x + x1, y - y1, x + x2, y - y2, x, y );
702 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
int GetX() const
Definition: eda_rect.h:107
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int GetBottom() const
Definition: eda_rect.h:123
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
int GetRight() const
Definition: eda_rect.h:120
E_SERIE r
Definition: eserie.cpp:41
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), GRSetBrush(), GRSetColorPen(), r, and RotatePoint().

◆ GRArc1() [1/2]

void GRArc1 ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  xc,
int  yc,
int  width,
const COLOR4D Color 
)

Definition at line 548 of file gr_basic.cpp.

550 {
551  /* Clip arcs off screen. */
552  if( ClipBox )
553  {
554  int x0, y0, xm, ym, r;
555  x0 = ClipBox->GetX();
556  y0 = ClipBox->GetY();
557  xm = ClipBox->GetRight();
558  ym = ClipBox->GetBottom();
559  r = KiROUND( Distance( x1, y1, xc, yc ) );
560 
561  if( xc < ( x0 - r ) )
562  return;
563 
564  if( yc < ( y0 - r ) )
565  return;
566 
567  if( xc > ( r + xm ) )
568  return;
569 
570  if( yc > ( r + ym ) )
571  return;
572  }
573 
574  GRSetBrush( DC, Color );
575  GRSetColorPen( DC, Color, width );
576  DC->DrawArc( x1, y1, x2, y2, xc, yc );
577 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
int GetRight() const
Definition: eda_rect.h:120
E_SERIE r
Definition: eserie.cpp:41
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), GRSetBrush(), GRSetColorPen(), KiROUND(), and r.

Referenced by GRArc1(), LIB_SHAPE::print(), and GERBER_DRAW_ITEM::Print().

◆ GRArc1() [2/2]

void GRArc1 ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aStart,
const wxPoint &  aEnd,
const wxPoint &  aCenter,
int  aWidth,
const COLOR4D aColor 
)

Definition at line 580 of file gr_basic.cpp.

582 {
583  GRArc1( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aCenter.x, aCenter.y,
584  aWidth, aColor );
585 }
void GRArc1(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int xc, int yc, int width, const COLOR4D &Color)
Definition: gr_basic.cpp:548

References GRArc1().

◆ GRCircle() [1/2]

void GRCircle ( EDA_RECT ClipBox,
wxDC *  DC,
int  x,
int  y,
int  r,
int  width,
const COLOR4D Color 
)

Draw a circle onto the drawing context aDC centered at the user coordinates (x,y).

Parameters
ClipBoxdefines a rectangular boundary outside of which no drawing will occur.
aDCthe device context into which drawing should occur.
xThe x coordinate in user space of the center of the circle.
yThe y coordinate in user space of the center of the circle.
aRadiusis the radius of the circle.
aColoris the color to draw.
See also
COLOR4D

Definition at line 507 of file gr_basic.cpp.

508 {
509  if( clipCircle( ClipBox, xc, yc, r, width ) || r <= 0 )
510  return;
511 
512  GRSetBrush( DC, Color, NOT_FILLED );
513  GRSetColorPen( DC, Color, width );
514 
515  // Draw two arcs here to make a circle. Unfortunately, the printerDC doesn't handle
516  // transparent brushes when used with circles. It does work for for arcs, however
517  DC->DrawArc(xc + r, yc, xc - r, yc, xc, yc);
518  DC->DrawArc(xc - r, yc, xc + r, yc, xc, yc);
519 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static bool clipCircle(EDA_RECT *aClipBox, int xc, int yc, int r, int aWidth)
Definition: gr_basic.cpp:477
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static const bool NOT_FILLED
Definition: gr_basic.cpp:33
E_SERIE r
Definition: eserie.cpp:41

References clipCircle(), GRSetBrush(), GRSetColorPen(), NOT_FILLED, and r.

Referenced by D_CODE::DrawFlashedShape(), GRCircle(), LIB_SHAPE::print(), LIB_PIN::print(), GERBER_DRAW_ITEM::Print(), and LIB_PIN::printPinSymbol().

◆ GRCircle() [2/2]

void GRCircle ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aPos,
int  aRadius,
int  aWidth,
const COLOR4D aColor 
)

Definition at line 522 of file gr_basic.cpp.

524 {
525  GRCircle( aClipBox, aDC, aPos.x, aPos.y, aRadius, aWidth, aColor );
526 }
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, const COLOR4D &Color)
Draw a circle onto the drawing context aDC centered at the user coordinates (x,y).
Definition: gr_basic.cpp:507

References GRCircle().

◆ GRClosedPoly() [1/2]

void GRClosedPoly ( EDA_RECT ClipBox,
wxDC *  DC,
int  n,
const wxPoint *  Points,
bool  Fill,
const COLOR4D Color,
const COLOR4D BgColor 
)

Draw a closed polyline and fill it if Fill, in object space.

Draw a closed polygon onto the drawing context aDC and optionally fills and/or draws a border around it.

Definition at line 463 of file gr_basic.cpp.

465 {
466  GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor );
467 }
void GRClosedPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, const COLOR4D &Color, const COLOR4D &BgColor)
Draw a closed polyline and fill it if Fill, in object space.
Definition: gr_basic.cpp:463

References GRClosedPoly().

Referenced by APERTURE_MACRO::DrawApertureMacroShape(), D_CODE::DrawFlashedPolygon(), GRClosedPoly(), GERBER_DRAW_ITEM::PrintGerberPoly(), and MARKER_BASE::PrintMarker().

◆ GRClosedPoly() [2/2]

void GRClosedPoly ( EDA_RECT ClipBox,
wxDC *  aDC,
int  aPointCount,
const wxPoint *  aPoints,
bool  doFill,
int  aPenWidth,
const COLOR4D aPenColor,
const COLOR4D aFillColor 
)

Draw a closed polygon onto the drawing context aDC and optionally fills and/or draws a border around it.

Parameters
ClipBoxdefines a rectangular boundary outside of which no drawing will occur.
aDCthe device context into which drawing should occur.
aPointCountthe number of points in the array aPointArray.
aPointsthe points to draw.
doFilltrue if polygon is to be filled, else false and only the boundary is drawn.
aPenWidthis the width of the pen to use on the perimeter, can be zero.
aPenColorthe color of the border.
aFillColorthe fill color of the polygon's interior.

Definition at line 470 of file gr_basic.cpp.

472 {
473  GRSClosedPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
474 }
static void GRSClosedPoly(EDA_RECT *aClipBox, wxDC *aDC, int aPointCount, const wxPoint *aPoints, bool aFill, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Draw a new closed polyline and fill it if Fill, in screen space.
Definition: gr_basic.cpp:415

References GRSClosedPoly().

◆ GRCSegm() [1/3]

void GRCSegm ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
int  aPenSize,
const COLOR4D Color 
)

Definition at line 227 of file gr_basic.cpp.

229 {
230  GRLastMoveToX = x2;
231  GRLastMoveToY = y2;
232 
233  if( ClipBox )
234  {
235  EDA_RECT clipbox( *ClipBox );
236  clipbox.Inflate( width / 2 );
237 
238  if( ClipLine( &clipbox, x1, y1, x2, y2 ) )
239  return;
240  }
241 
242  if( width <= 2 ) /* single line or 2 pixels */
243  {
244  GRSetColorPen( DC, Color, width );
245  DC->DrawLine( x1, y1, x2, y2 );
246  return;
247  }
248 
249  GRSetBrush( DC, Color, NOT_FILLED );
250  GRSetColorPen( DC, Color, aPenSize );
251 
252  int radius = ( width + 1 ) >> 1;
253  int dx = x2 - x1;
254  int dy = y2 - y1;
255  double angle = -ArcTangente( dy, dx );
256  wxPoint start;
257  wxPoint end;
258  wxPoint org( x1, y1 );
259  int len = (int) hypot( dx, dy );
260 
261  // We know if the DC is mirrored, to draw arcs
262  int slx = DC->DeviceToLogicalX( 1 ) - DC->DeviceToLogicalX( 0 );
263  int sly = DC->DeviceToLogicalY( 1 ) - DC->DeviceToLogicalY( 0 );
264  bool mirrored = ( slx > 0 && sly < 0 ) || ( slx < 0 && sly > 0 );
265 
266  // first edge
267  start.x = 0;
268  start.y = radius;
269  end.x = len;
270  end.y = radius;
271  RotatePoint( &start, angle );
272  RotatePoint( &end, angle );
273 
274  start += org;
275  end += org;
276 
277  DC->DrawLine( start, end );
278 
279  // first rounded end
280  end.x = 0;
281  end.y = -radius;
282  RotatePoint( &end, angle );
283  end += org;
284 
285  if( !mirrored )
286  DC->DrawArc( end, start, org );
287  else
288  DC->DrawArc( start, end, org );
289 
290  // second edge
291  start.x = len;
292  start.y = -radius;
293  RotatePoint( &start, angle );
294  start += org;
295 
296  DC->DrawLine( start, end );
297 
298  // second rounded end
299  end.x = len;
300  end.y = radius;
301  RotatePoint( &end, angle);
302  end += org;
303 
304  if( !mirrored )
305  DC->DrawArc( end.x, end.y, start.x, start.y, x2, y2 );
306  else
307  DC->DrawArc( start.x, start.y, end.x, end.y, x2, y2 );
308 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
static int GRLastMoveToX
Definition: gr_basic.cpp:77
bool ClipLine(const EDA_RECT *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static const bool NOT_FILLED
Definition: gr_basic.cpp:33
static int GRLastMoveToY
Definition: gr_basic.cpp:77
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
Handle the component boundary box.
Definition: eda_rect.h:42
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183

References PNS::angle(), ArcTangente(), ClipLine(), GRLastMoveToX, GRLastMoveToY, GRSetBrush(), GRSetColorPen(), EDA_RECT::Inflate(), NOT_FILLED, and RotatePoint().

Referenced by BASIC_GAL::doDrawPolyline(), D_CODE::DrawFlashedShape(), BASIC_GAL::DrawLine(), GRCSegm(), and GERBER_DRAW_ITEM::Print().

◆ GRCSegm() [2/3]

void GRCSegm ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
const COLOR4D Color 
)

Definition at line 311 of file gr_basic.cpp.

313 {
314  GRCSegm( ClipBox, DC, x1, y1, x2, y2, width, 0, Color );
315 }
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, const COLOR4D &Color)
Definition: gr_basic.cpp:227

References GRCSegm().

◆ GRCSegm() [3/3]

void GRCSegm ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aStart,
const wxPoint &  aEnd,
int  aWidth,
const COLOR4D aColor 
)

Definition at line 318 of file gr_basic.cpp.

320 {
321  GRCSegm( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, 0, aColor );
322 }
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, const COLOR4D &Color)
Definition: gr_basic.cpp:227

References GRCSegm().

◆ GRFillCSegm()

void GRFillCSegm ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
const COLOR4D Color 
)

Definition at line 325 of file gr_basic.cpp.

327 {
328  GRSetColorPen( DC, Color, width );
329  WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width );
330 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static void WinClipAndDrawLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width)
Definition: gr_basic.cpp:89

References GRSetColorPen(), and WinClipAndDrawLine().

Referenced by D_CODE::DrawFlashedShape().

◆ GRFilledArc1()

void GRFilledArc1 ( EDA_RECT ClipBox,
wxDC *  DC,
const wxPoint &  aStart,
const wxPoint &  aEnd,
const wxPoint &  aCenter,
int  width,
const COLOR4D Color,
const COLOR4D BgColor 
)

Definition at line 588 of file gr_basic.cpp.

590 {
591  /* Clip arcs off screen. */
592  if( ClipBox )
593  {
594  int x0, y0, xm, ym, r;
595  x0 = ClipBox->GetX();
596  y0 = ClipBox->GetY();
597  xm = ClipBox->GetRight();
598  ym = ClipBox->GetBottom();
599  r = KiROUND( Distance( aStart.x, aStart.y, aCenter.x, aCenter.y ) );
600 
601  if( aCenter.x < ( x0 - r ) )
602  return;
603 
604  if( aCenter.y < ( y0 - r ) )
605  return;
606 
607  if( aCenter.x > ( r + xm ) )
608  return;
609 
610  if( aCenter.y > ( r + ym ) )
611  return;
612  }
613 
614  GRSetBrush( DC, BgColor, FILLED );
615  GRSetColorPen( DC, Color, width );
616  DC->DrawArc( aStart.x, aStart.y, aEnd.x, aEnd.y, aCenter.x, aCenter.y );
617 }
static const bool FILLED
Definition: gr_basic.cpp:32
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
int GetX() const
Definition: eda_rect.h:107
int GetBottom() const
Definition: eda_rect.h:123
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
int GetRight() const
Definition: eda_rect.h:120
E_SERIE r
Definition: eserie.cpp:41
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
int GetY() const
Definition: eda_rect.h:108

References FILLED, EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), GRSetBrush(), GRSetColorPen(), KiROUND(), and r.

Referenced by LIB_SHAPE::print().

◆ GRFilledCircle() [1/2]

void GRFilledCircle ( EDA_RECT ClipBox,
wxDC *  DC,
int  x,
int  y,
int  r,
int  width,
const COLOR4D Color,
const COLOR4D BgColor 
)

Definition at line 529 of file gr_basic.cpp.

531 {
532  if( clipCircle( ClipBox, x, y, r, width ) || r <= 0 )
533  return;
534 
535  GRSetBrush( DC, BgColor, FILLED );
536  GRSetColorPen( DC, Color, width );
537  DC->DrawEllipse( x - r, y - r, r + r, r + r );
538 }
static const bool FILLED
Definition: gr_basic.cpp:32
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static bool clipCircle(EDA_RECT *aClipBox, int xc, int yc, int r, int aWidth)
Definition: gr_basic.cpp:477
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
E_SERIE r
Definition: eserie.cpp:41

References clipCircle(), FILLED, GRSetBrush(), GRSetColorPen(), and r.

Referenced by D_CODE::DrawFlashedShape(), GRFilledCircle(), SCH_JUNCTION::Print(), and LIB_SHAPE::print().

◆ GRFilledCircle() [2/2]

void GRFilledCircle ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aPos,
int  aRadius,
const COLOR4D aColor 
)

Definition at line 541 of file gr_basic.cpp.

543 {
544  GRFilledCircle( aClipBox, aDC, aPos.x, aPos.y, aRadius, 0, aColor, aColor );
545 }
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, const COLOR4D &Color, const COLOR4D &BgColor)
Definition: gr_basic.cpp:529

References GRFilledCircle().

◆ GRFilledRect() [1/2]

void GRFilledRect ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
const COLOR4D Color,
const COLOR4D BgColor 
)

Definition at line 712 of file gr_basic.cpp.

714 {
715  GRSFilledRect( ClipBox, DC, x1, y1, x2, y2, 0, Color, BgColor );
716 }
void GRSFilledRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition: gr_basic.cpp:739

References GRSFilledRect().

Referenced by D_CODE::DrawFlashedShape(), LIB_SHAPE::print(), SCH_SHEET::Print(), and DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample().

◆ GRFilledRect() [2/2]

void GRFilledRect ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
const COLOR4D Color,
const COLOR4D BgColor 
)

Definition at line 719 of file gr_basic.cpp.

721 {
722  GRSFilledRect( ClipBox, DC, x1, y1, x2, y2, width, Color, BgColor );
723 }
void GRSFilledRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Definition: gr_basic.cpp:739

References GRSFilledRect().

◆ GRFilledSegment()

void GRFilledSegment ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aStart,
const wxPoint &  aEnd,
int  aWidth,
const COLOR4D aColor 
)

Definition at line 333 of file gr_basic.cpp.

335 {
336  GRSetColorPen( aDC, aColor, aWidth );
337  WinClipAndDrawLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth );
338 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static void WinClipAndDrawLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width)
Definition: gr_basic.cpp:89

References GRSetColorPen(), and WinClipAndDrawLine().

Referenced by GERBER_DRAW_ITEM::Print().

◆ GRForceBlackPen()

void GRForceBlackPen ( bool  flagforce)
Parameters
flagforceTrue to force a black pen whenever the asked color.

Definition at line 185 of file gr_basic.cpp.

186 {
187  s_ForceBlackPen = flagforce;
188 }
static bool s_ForceBlackPen
Definition: gr_basic.cpp:78

References s_ForceBlackPen.

Referenced by SCH_EDIT_FRAME::DrawCurrentSheetToClipboard(), PLEDITOR_PRINTOUT::PrintPage(), and SCH_PRINTOUT::PrintPage().

◆ GRLine() [1/2]

void GRLine ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
const COLOR4D Color,
wxPenStyle  aStyle 
)

Definition at line 197 of file gr_basic.cpp.

199 {
200  GRSetColorPen( DC, Color, width, aStyle );
201  WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width );
202  GRLastMoveToX = x2;
203  GRLastMoveToY = y2;
204 }
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static int GRLastMoveToX
Definition: gr_basic.cpp:77
static int GRLastMoveToY
Definition: gr_basic.cpp:77
static void WinClipAndDrawLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width)
Definition: gr_basic.cpp:89

References GRLastMoveToX, GRLastMoveToY, GRSetColorPen(), and WinClipAndDrawLine().

Referenced by BASIC_GAL::DrawLine(), GRLine(), GRLineTo(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), SCH_NO_CONNECT::Print(), SCH_BUS_ENTRY_BASE::Print(), SCH_LINE::Print(), LIB_PIN::printPinSymbol(), and DS_DRAW_ITEM_LINE::PrintWsItem().

◆ GRLine() [2/2]

void GRLine ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aStart,
const wxPoint &  aEnd,
int  aWidth,
const COLOR4D aColor,
wxPenStyle  aStyle 
)

Definition at line 207 of file gr_basic.cpp.

209 {
210  GRLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, aColor, aStyle );
211 }
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:197

References GRLine().

◆ GRLineTo()

void GRLineTo ( EDA_RECT ClipBox,
wxDC *  DC,
int  x,
int  y,
int  width,
const COLOR4D Color 
)

Definition at line 221 of file gr_basic.cpp.

222 {
223  GRLine( ClipBox, DC, GRLastMoveToX, GRLastMoveToY, x, y, width, Color );
224 }
static int GRLastMoveToX
Definition: gr_basic.cpp:77
static int GRLastMoveToY
Definition: gr_basic.cpp:77
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:197

References GRLastMoveToX, GRLastMoveToY, and GRLine().

Referenced by GRSClosedPoly(), GRSPoly(), and LIB_PIN::printPinSymbol().

◆ GRMoveTo()

void GRMoveTo ( int  x,
int  y 
)

Definition at line 214 of file gr_basic.cpp.

215 {
216  GRLastMoveToX = x;
217  GRLastMoveToY = y;
218 }
static int GRLastMoveToX
Definition: gr_basic.cpp:77
static int GRLastMoveToY
Definition: gr_basic.cpp:77

References GRLastMoveToX, and GRLastMoveToY.

Referenced by GRSClosedPoly(), GRSPoly(), and LIB_PIN::printPinSymbol().

◆ GRPoly()

void GRPoly ( EDA_RECT ClipBox,
wxDC *  DC,
int  n,
const wxPoint *  Points,
bool  Fill,
int  width,
const COLOR4D Color,
const COLOR4D BgColor 
)

Draw a new polyline and fill it if Fill, in drawing space.

Definition at line 453 of file gr_basic.cpp.

455 {
456  GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor );
457 }
static void GRSPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
Draw a new polyline and fill it if Fill, in screen space.
Definition: gr_basic.cpp:382

References GRSPoly().

Referenced by BASIC_GAL::doDrawPolyline(), LIB_SHAPE::print(), SCH_GLOBALLABEL::Print(), SCH_HIERLABEL::Print(), and DS_DRAW_ITEM_POLYPOLYGONS::PrintWsItem().

◆ GRRect()

void GRRect ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width,
const COLOR4D Color 
)

Definition at line 705 of file gr_basic.cpp.

707 {
708  GRSRect( ClipBox, DC, x1, y1, x2, y2, width, Color );
709 }
static void GRSRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, int aWidth, const COLOR4D &aColor)
Definition: gr_basic.cpp:726

References GRSRect().

Referenced by D_CODE::DrawFlashedShape(), LIB_SHAPE::print(), SCH_SHEET::Print(), and DS_DRAW_ITEM_RECT::PrintWsItem().

◆ GRResetPenAndBrush()

void GRResetPenAndBrush ( wxDC *  DC)

Definition at line 107 of file gr_basic.cpp.

108 {
109  GRSetBrush( DC, BLACK ); // Force no fill
110  s_DC_lastbrushcolor = COLOR4D::UNSPECIFIED;
111  s_DC_lastDC = nullptr;
112 }
Definition: color4d.h:44
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static wxDC * s_DC_lastDC
Definition: gr_basic.cpp:87
static COLOR4D s_DC_lastbrushcolor(0, 0, 0, 0)

References BLACK, GRSetBrush(), s_DC_lastbrushcolor, and s_DC_lastDC.

Referenced by SCH_EDIT_FRAME::DrawCurrentSheetToClipboard(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), DIALOG_PIN_PROPERTIES::OnPaintShowPanel(), PLEDITOR_PRINTOUT::PrintPage(), SCH_PRINTOUT::PrintPage(), and DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample().

◆ GRSClosedPoly()

static void GRSClosedPoly ( EDA_RECT aClipBox,
wxDC *  aDC,
int  aPointCount,
const wxPoint *  aPoints,
bool  aFill,
int  aWidth,
const COLOR4D aColor,
const COLOR4D aBgColor 
)
static

Draw a new closed polyline and fill it if Fill, in screen space.

Definition at line 415 of file gr_basic.cpp.

417 {
418  if( !IsGRSPolyDrawable( aClipBox, aPointCount, aPoints ) )
419  return;
420 
421  if( aFill && ( aPointCount > 2 ) )
422  {
423  GRLastMoveToX = aPoints[aPointCount - 1].x;
424  GRLastMoveToY = aPoints[aPointCount - 1].y;
425  GRSetBrush( aDC, aBgColor, FILLED );
426  GRSetColorPen( aDC, aColor, aWidth );
427  ClipAndDrawPoly( aClipBox, aDC, aPoints, aPointCount );
428  }
429  else
430  {
431 
432  GRMoveTo( aPoints[0].x, aPoints[0].y );
433 
434  for( int i = 1; i < aPointCount; ++i )
435  {
436  GRLineTo( aClipBox, aDC, aPoints[i].x, aPoints[i].y, aWidth, aColor );
437  }
438 
439  int lastpt = aPointCount - 1;
440 
441  // Close the polygon
442  if( aPoints[lastpt] != aPoints[0] )
443  {
444  GRLineTo( aClipBox, aDC, aPoints[0].x, aPoints[0].y, aWidth, aColor );
445  }
446  }
447 }
static const bool FILLED
Definition: gr_basic.cpp:32
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
static int GRLastMoveToX
Definition: gr_basic.cpp:77
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static int GRLastMoveToY
Definition: gr_basic.cpp:77
static bool IsGRSPolyDrawable(EDA_RECT *ClipBox, int n, const wxPoint *Points)
Definition: gr_basic.cpp:340
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, const COLOR4D &Color)
Definition: gr_basic.cpp:221
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:214
static void ClipAndDrawPoly(EDA_RECT *ClipBox, wxDC *DC, const wxPoint *Points, int n)
Used to clip a polygon and draw it as Filled Polygon.
Definition: gr_basic.cpp:775

References ClipAndDrawPoly(), FILLED, GRLastMoveToX, GRLastMoveToY, GRLineTo(), GRMoveTo(), GRSetBrush(), GRSetColorPen(), and IsGRSPolyDrawable().

Referenced by GRClosedPoly(), and GRSRect().

◆ GRSetBrush()

void GRSetBrush ( wxDC *  DC,
const COLOR4D Color,
bool  fill 
)

Definition at line 158 of file gr_basic.cpp.

159 {
160  COLOR4D color = Color;
161 
162  if( s_ForceBlackPen )
164 
165  if( s_DC_lastbrushcolor != color || s_DC_lastbrushfill != fill || s_DC_lastDC != DC )
166  {
167  wxBrush brush;
168 
169  brush.SetColour( color.ToColour() );
170 
171  if( fill )
172  brush.SetStyle( wxBRUSHSTYLE_SOLID );
173  else
174  brush.SetStyle( wxBRUSHSTYLE_TRANSPARENT );
175 
176  DC->SetBrush( brush );
177 
179  s_DC_lastbrushfill = fill;
180  s_DC_lastDC = DC;
181  }
182 }
int color
Definition: DXF_plotter.cpp:57
Definition: color4d.h:44
static wxDC * s_DC_lastDC
Definition: gr_basic.cpp:87
static COLOR4D s_DC_lastbrushcolor(0, 0, 0, 0)
static bool s_DC_lastbrushfill
Definition: gr_basic.cpp:86
static bool s_ForceBlackPen
Definition: gr_basic.cpp:78
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References BLACK, color, s_DC_lastbrushcolor, s_DC_lastbrushfill, s_DC_lastDC, and s_ForceBlackPen.

Referenced by GRArc(), GRArc1(), GRCircle(), GRCSegm(), GRFilledArc1(), GRFilledCircle(), GRResetPenAndBrush(), GRSClosedPoly(), GRSFilledRect(), and GRSPoly().

◆ GRSetColorPen()

void GRSetColorPen ( wxDC *  DC,
const COLOR4D Color,
int  width,
wxPenStyle  style 
)

Definition at line 115 of file gr_basic.cpp.

116 {
117  COLOR4D color = Color;
118 
119  wxDash dots[2] = { 1, 3 };
120 
121  // Under OSX and while printing when wxPen is set to 0, renderer follows the request drawing
122  // nothing & in the bitmap world the minimum is enough to light a pixel, in vectorial one not
123  if( width <= 1 )
124  width = DC->DeviceToLogicalXRel( 1 );
125 
126  if( s_ForceBlackPen )
128 
129  const wxPen& curr_pen = DC->GetPen();
130 
131  if( !curr_pen.IsOk() || curr_pen.GetColour() != color.ToColour()
132  || curr_pen.GetWidth() != width || curr_pen.GetStyle() != style )
133  {
134  wxPen pen;
135  pen.SetColour( color.ToColour() );
136 
137  if( style == wxPENSTYLE_DOT )
138  {
139  style = wxPENSTYLE_USER_DASH;
140  pen.SetDashes( 2, dots );
141  }
142 
143  pen.SetWidth( width );
144  pen.SetStyle( style );
145  DC->SetPen( pen );
146  }
147  else
148  {
149  // Should be not needed, but on Linux, in printing process
150  // the curr pen settings needs to be sometimes re-initialized
151  // Clearly, this is due to a bug, related to SetBrush(),
152  // but we have to live with it, at least on wxWidgets 3.0
153  DC->SetPen( curr_pen );
154  }
155 }
int color
Definition: DXF_plotter.cpp:57
Definition: color4d.h:44
static bool s_ForceBlackPen
Definition: gr_basic.cpp:78
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References BLACK, color, and s_ForceBlackPen.

Referenced by GRArc(), GRArc1(), GRCircle(), GRCSegm(), GRFillCSegm(), GRFilledArc1(), GRFilledCircle(), GRFilledSegment(), GRLine(), GRSClosedPoly(), GRSFilledRect(), and GRSPoly().

◆ GRSFilledRect()

void GRSFilledRect ( EDA_RECT aClipBox,
wxDC *  aDC,
int  x1,
int  y1,
int  x2,
int  y2,
int  aWidth,
const COLOR4D aColor,
const COLOR4D aBgColor 
)

Definition at line 739 of file gr_basic.cpp.

741 {
742  wxPoint points[5];
743  points[0] = wxPoint( x1, y1 );
744  points[1] = wxPoint( x1, y2 );
745  points[2] = wxPoint( x2, y2 );
746  points[3] = wxPoint( x2, y1 );
747  points[4] = points[0];
748 
749  GRSetBrush( aDC, aBgColor, FILLED );
750  GRSetColorPen( aDC, aBgColor, aWidth );
751 
752  if( aClipBox && ( aWidth > 0 ) )
753  {
754  EDA_RECT clipbox( *aClipBox );
755  clipbox.Inflate( aWidth );
756  ClipAndDrawPoly( &clipbox, aDC, points, 5 ); // polygon approach is more accurate
757  }
758  else
759  {
760  ClipAndDrawPoly(aClipBox, aDC, points, 5 );
761  }
762 }
static const bool FILLED
Definition: gr_basic.cpp:32
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static void ClipAndDrawPoly(EDA_RECT *ClipBox, wxDC *DC, const wxPoint *Points, int n)
Used to clip a polygon and draw it as Filled Polygon.
Definition: gr_basic.cpp:775
Handle the component boundary box.
Definition: eda_rect.h:42

References ClipAndDrawPoly(), FILLED, GRSetBrush(), GRSetColorPen(), and EDA_RECT::Inflate().

Referenced by GRFilledRect(), and SCH_PRINTOUT::PrintPage().

◆ GRSPoly()

static void GRSPoly ( EDA_RECT ClipBox,
wxDC *  DC,
int  n,
const wxPoint *  Points,
bool  Fill,
int  width,
const COLOR4D Color,
const COLOR4D BgColor 
)
static

Draw a new polyline and fill it if Fill, in screen space.

Definition at line 382 of file gr_basic.cpp.

384 {
385  if( !IsGRSPolyDrawable( ClipBox, n, Points ) )
386  return;
387 
388  if( Fill && ( n > 2 ) )
389  {
390  GRSetBrush( DC, BgColor, FILLED );
391  GRSetColorPen( DC, Color, width );
392 
393  /* clip before send the filled polygon to wxDC, because under linux
394  * (GTK?) polygons having large coordinates are incorrectly drawn
395  * (integer overflow in coordinates, I am guessing)
396  */
397  ClipAndDrawPoly( ClipBox, DC, Points, n );
398  }
399  else
400  {
401 
402  GRMoveTo( Points[0].x, Points[0].y );
403 
404  for( int i = 1; i < n; ++i )
405  {
406  GRLineTo( ClipBox, DC, Points[i].x, Points[i].y, width, Color );
407  }
408  }
409 }
static const bool FILLED
Definition: gr_basic.cpp:32
void GRSetColorPen(wxDC *DC, const COLOR4D &Color, int width, wxPenStyle style)
Definition: gr_basic.cpp:115
void GRSetBrush(wxDC *DC, const COLOR4D &Color, bool fill)
Definition: gr_basic.cpp:158
static bool IsGRSPolyDrawable(EDA_RECT *ClipBox, int n, const wxPoint *Points)
Definition: gr_basic.cpp:340
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, const COLOR4D &Color)
Definition: gr_basic.cpp:221
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:214
static void ClipAndDrawPoly(EDA_RECT *ClipBox, wxDC *DC, const wxPoint *Points, int n)
Used to clip a polygon and draw it as Filled Polygon.
Definition: gr_basic.cpp:775

References ClipAndDrawPoly(), FILLED, GRLineTo(), GRMoveTo(), GRSetBrush(), GRSetColorPen(), and IsGRSPolyDrawable().

Referenced by GRPoly().

◆ GRSRect()

void GRSRect ( EDA_RECT aClipBox,
wxDC *  aDC,
int  x1,
int  y1,
int  x2,
int  y2,
int  aWidth,
const COLOR4D aColor 
)
static

Definition at line 726 of file gr_basic.cpp.

728 {
729  wxPoint points[5];
730  points[0] = wxPoint( x1, y1 );
731  points[1] = wxPoint( x1, y2 );
732  points[2] = wxPoint( x2, y2 );
733  points[3] = wxPoint( x2, y1 );
734  points[4] = points[0];
735  GRSClosedPoly( aClipBox, aDC, 5, points, NOT_FILLED, aWidth, aColor, aColor );
736 }
static void GRSClosedPoly(EDA_RECT *aClipBox, wxDC *aDC, int aPointCount, const wxPoint *aPoints, bool aFill, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
Draw a new closed polyline and fill it if Fill, in screen space.
Definition: gr_basic.cpp:415
static const bool NOT_FILLED
Definition: gr_basic.cpp:33

References GRSClosedPoly(), and NOT_FILLED.

Referenced by GRRect().

◆ IsGRSPolyDrawable()

static bool IsGRSPolyDrawable ( EDA_RECT ClipBox,
int  n,
const wxPoint *  Points 
)
static

Definition at line 340 of file gr_basic.cpp.

341 {
342  if( !ClipBox )
343  return true;
344 
345  if( n <= 0 )
346  return false;
347 
348  int Xmin, Xmax, Ymin, Ymax;
349 
350  Xmin = Xmax = Points[0].x;
351  Ymin = Ymax = Points[0].y;
352 
353  for( int ii = 1; ii < n; ii++ ) // calculate rectangle
354  {
355  Xmin = std::min( Xmin, Points[ii].x );
356  Xmax = std::max( Xmax, Points[ii].x );
357  Ymin = std::min( Ymin, Points[ii].y );
358  Ymax = std::max( Ymax, Points[ii].y );
359  }
360 
361  xcliplo = ClipBox->GetX();
362  ycliplo = ClipBox->GetY();
363  xcliphi = ClipBox->GetRight();
364  ycliphi = ClipBox->GetBottom();
365 
366  if( Xmax < xcliplo )
367  return false;
368  if( Xmin > xcliphi )
369  return false;
370  if( Ymax < ycliplo )
371  return false;
372  if( Ymin > ycliphi )
373  return false;
374 
375  return true;
376 }
static int ycliplo
Definition: gr_basic.cpp:81
static int ycliphi
Definition: gr_basic.cpp:83
int GetX() const
Definition: eda_rect.h:107
static int xcliphi
Definition: gr_basic.cpp:82
int GetBottom() const
Definition: eda_rect.h:123
static int xcliplo
Definition: gr_basic.cpp:80
int GetRight() const
Definition: eda_rect.h:120
int GetY() const
Definition: eda_rect.h:108

References EDA_RECT::GetBottom(), EDA_RECT::GetRight(), EDA_RECT::GetX(), EDA_RECT::GetY(), xcliphi, xcliplo, ycliphi, and ycliplo.

Referenced by GRSClosedPoly(), and GRSPoly().

◆ WinClipAndDrawLine()

static void WinClipAndDrawLine ( EDA_RECT ClipBox,
wxDC *  DC,
int  x1,
int  y1,
int  x2,
int  y2,
int  width 
)
static

Definition at line 89 of file gr_basic.cpp.

91 {
92  GRLastMoveToX = x2;
93  GRLastMoveToY = y2;
94 
95  if( ClipBox )
96  {
97  EDA_RECT clipbox(*ClipBox);
98  clipbox.Inflate(width/2);
99  if( ClipLine( &clipbox, x1, y1, x2, y2 ) )
100  return;
101  }
102 
103  DC->DrawLine( x1, y1, x2, y2 );
104 }
static int GRLastMoveToX
Definition: gr_basic.cpp:77
bool ClipLine(const EDA_RECT *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
static int GRLastMoveToY
Definition: gr_basic.cpp:77
Handle the component boundary box.
Definition: eda_rect.h:42

References ClipLine(), GRLastMoveToX, GRLastMoveToY, and EDA_RECT::Inflate().

Referenced by GRFillCSegm(), GRFilledSegment(), and GRLine().

Variable Documentation

◆ FILLED

const bool FILLED = true
static

Definition at line 32 of file gr_basic.cpp.

Referenced by GRFilledArc1(), GRFilledCircle(), GRSClosedPoly(), GRSFilledRect(), and GRSPoly().

◆ g_XorMode

GR_DRAWMODE g_XorMode = GR_NXOR

Definition at line 63 of file gr_basic.cpp.

◆ GRLastMoveToX

int GRLastMoveToX
static

Definition at line 77 of file gr_basic.cpp.

Referenced by GRCSegm(), GRLine(), GRLineTo(), GRMoveTo(), GRSClosedPoly(), and WinClipAndDrawLine().

◆ GRLastMoveToY

int GRLastMoveToY
static

Definition at line 77 of file gr_basic.cpp.

Referenced by GRCSegm(), GRLine(), GRLineTo(), GRMoveTo(), GRSClosedPoly(), and WinClipAndDrawLine().

◆ NOT_FILLED

const bool NOT_FILLED = false
static

Definition at line 33 of file gr_basic.cpp.

Referenced by GRArc(), GRCircle(), GRCSegm(), and GRSRect().

◆ s_DC_lastbrushcolor

COLOR4D s_DC_lastbrushcolor(0, 0, 0, 0)
static

Referenced by GRResetPenAndBrush(), and GRSetBrush().

◆ s_DC_lastbrushfill

bool s_DC_lastbrushfill = false
static

Definition at line 86 of file gr_basic.cpp.

Referenced by GRSetBrush().

◆ s_DC_lastDC

wxDC* s_DC_lastDC = nullptr
static

Definition at line 87 of file gr_basic.cpp.

Referenced by GRResetPenAndBrush(), and GRSetBrush().

◆ s_ForceBlackPen

bool s_ForceBlackPen
static

Definition at line 78 of file gr_basic.cpp.

Referenced by GetGRForceBlackPenState(), GRForceBlackPen(), GRSetBrush(), and GRSetColorPen().

◆ xcliphi

int xcliphi = 2000
static

Definition at line 82 of file gr_basic.cpp.

Referenced by IsGRSPolyDrawable().

◆ xcliplo

int xcliplo = 0
static

Definition at line 80 of file gr_basic.cpp.

Referenced by IsGRSPolyDrawable().

◆ ycliphi

int ycliphi = 2000
static

Definition at line 83 of file gr_basic.cpp.

Referenced by IsGRSPolyDrawable().

◆ ycliplo

int ycliplo = 0
static

Definition at line 81 of file gr_basic.cpp.

Referenced by IsGRSPolyDrawable().