KiCad PCB EDA Suite
KIGFX::PREVIEW::DRAW_CONTEXT Class Reference

A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy to draw preview items consistently. More...

#include <draw_context.h>

Public Member Functions

 DRAW_CONTEXT (KIGFX::VIEW &aView)
 
void DrawCircle (const VECTOR2I &aOrigin, double aRad, bool aDeEmphasised)
 Draw a preview circle on the current layer. More...
 
void DrawLine (const VECTOR2I &aStart, const VECTOR2I &aEnd, bool aDeEmphasised)
 Draw a simple line on the current layer. More...
 
void DrawLineWithAngleHighlight (const VECTOR2I &aStart, const VECTOR2I &aEnd, bool aDeEmphasised)
 Draw a straight line on the current layer, with a special highlight when the line angle is a multiple of 45 degrees. More...
 
void DrawArcWithAngleHighlight (const VECTOR2I &aOrigin, double aRad, double aStartAngle, double aEndAngle)
 Draw an arc on the current layer, with a special highlight when the line angle is a multiple of 45 degrees. More...
 

Private Member Functions

COLOR4D getSpecialAngleColour () const
 The GAL to draw into. More...
 

Private Attributes

KIGFX::GALm_gal
 
const KIGFX::RENDER_SETTINGSm_render_settings
 The current layer to draw onto. More...
 
GAL_LAYER_ID m_currLayer
 
float m_lineWidth
 The line width to use for items. More...
 

Detailed Description

A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other settings that makes it easy to draw preview items consistently.

This class provides some graphical items that are often used by preview items. Complex items can be composed from these.

Definition at line 43 of file draw_context.h.

Constructor & Destructor Documentation

◆ DRAW_CONTEXT()

DRAW_CONTEXT::DRAW_CONTEXT ( KIGFX::VIEW aView)

Definition at line 47 of file draw_context.cpp.

48  : m_gal( *aView.GetGAL() ),
51  m_lineWidth( 1.0f )
52 {
53 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
Auxiliary items (guides, rule, etc)
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:106

Member Function Documentation

◆ DrawArcWithAngleHighlight()

void DRAW_CONTEXT::DrawArcWithAngleHighlight ( const VECTOR2I aOrigin,
double  aRad,
double  aStartAngle,
double  aEndAngle 
)

Draw an arc on the current layer, with a special highlight when the line angle is a multiple of 45 degrees.

Parameters
aOriginthe arc centre
aRadthe arc radius
aStartAnglethe arc start angle
aEndAnglethe arc end angle

Definition at line 68 of file draw_context.cpp.

70 {
72 
73  if( angleIsSpecial( aStartAngle - aEndAngle ) )
75 
77  m_gal.SetIsStroke( true );
78  m_gal.SetIsFill( true );
80  m_gal.SetFillColor( color.WithAlpha( 0.2 ) );
81 
82  // draw the angle reference arc
83  m_gal.DrawArc( aOrigin, aRad, -aStartAngle, -aEndAngle );
84 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
int color
Definition: DXF_plotter.cpp:62
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
virtual void SetLineWidth(float aLineWidth)
Set the line width.
COLOR4D getSpecialAngleColour() const
The GAL to draw into.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
static bool angleIsSpecial(double aRadians)
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:106
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References angleIsSpecial(), color, KIGFX::GAL::DrawArc(), KIGFX::RENDER_SETTINGS::GetLayerColor(), getSpecialAngleColour(), m_currLayer, m_gal, m_lineWidth, m_render_settings, KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ DrawCircle()

void DRAW_CONTEXT::DrawCircle ( const VECTOR2I aOrigin,
double  aRad,
bool  aDeEmphasised 
)

Draw a preview circle on the current layer.

Parameters
aOrigincircle origin
aRadcircle radius
aDeEmphasiseddraw the circle de-emphasised

Definition at line 56 of file draw_context.cpp.

57 {
59 
61  m_gal.SetStrokeColor( deemphasise( color, aDeEmphasised ) );
62  m_gal.SetIsStroke( true );
63  m_gal.SetIsFill( false );
64  m_gal.DrawCircle( aOrigin, aRad );
65 }
int color
Definition: DXF_plotter.cpp:62
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
static COLOR4D deemphasise(const COLOR4D &aColor, bool aDeEmphasised)
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:106
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References color, deemphasise(), KIGFX::GAL::DrawCircle(), KIGFX::RENDER_SETTINGS::GetLayerColor(), m_currLayer, m_gal, m_lineWidth, m_render_settings, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ DrawLine()

void DRAW_CONTEXT::DrawLine ( const VECTOR2I aStart,
const VECTOR2I aEnd,
bool  aDeEmphasised 
)

Draw a simple line on the current layer.

Parameters
aStartline start point
aEndline end point
aDeEmphasiseddraw the line de-emphasised

Definition at line 87 of file draw_context.cpp.

88 {
90 
92  m_gal.SetIsStroke( true );
93  m_gal.SetStrokeColor( deemphasise( strokeColor, aDeEmphasised ) );
94  m_gal.DrawLine( aStart, aEnd );
95 }
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
static COLOR4D deemphasise(const COLOR4D &aColor, bool aDeEmphasised)
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:106
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References deemphasise(), KIGFX::GAL::DrawLine(), KIGFX::RENDER_SETTINGS::GetLayerColor(), m_currLayer, m_gal, m_lineWidth, m_render_settings, KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ DrawLineWithAngleHighlight()

void DRAW_CONTEXT::DrawLineWithAngleHighlight ( const VECTOR2I aStart,
const VECTOR2I aEnd,
bool  aDeEmphasised 
)

Draw a straight line on the current layer, with a special highlight when the line angle is a multiple of 45 degrees.

Parameters
aStartline start point
aEndline end point
aDeEmphasiseddraw the line de-emphasised

Definition at line 98 of file draw_context.cpp.

100 {
101  const VECTOR2I vec = aEnd - aStart;
103 
104  if( angleIsSpecial( vec.Angle() ) )
105  strokeColor = getSpecialAngleColour();
106 
108  m_gal.SetIsStroke( true );
109  m_gal.SetStrokeColor( deemphasise( strokeColor, aDeEmphasised ) );
110  m_gal.DrawLine( aStart, aEnd );
111 }
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
COLOR4D getSpecialAngleColour() const
The GAL to draw into.
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:306
static COLOR4D deemphasise(const COLOR4D &aColor, bool aDeEmphasised)
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
static bool angleIsSpecial(double aRadians)
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:106
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References VECTOR2< T >::Angle(), angleIsSpecial(), deemphasise(), KIGFX::GAL::DrawLine(), KIGFX::RENDER_SETTINGS::GetLayerColor(), getSpecialAngleColour(), m_currLayer, m_gal, m_lineWidth, m_render_settings, KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ getSpecialAngleColour()

COLOR4D DRAW_CONTEXT::getSpecialAngleColour ( ) const
private

The GAL to draw into.

Returns
the colour to use for "special" angles

Definition at line 114 of file draw_context.cpp.

115 {
116  return m_render_settings.IsBackgroundDark() ? COLOR4D( 0.5, 1.0, 0.5, 1.0 ) :
117  COLOR4D( 0.0, 0.7, 0.0, 1.0 );
118 }
virtual bool IsBackgroundDark() const
Definition: painter.h:237
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:100
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

References KIGFX::RENDER_SETTINGS::IsBackgroundDark(), and m_render_settings.

Referenced by DrawArcWithAngleHighlight(), and DrawLineWithAngleHighlight().

Member Data Documentation

◆ m_currLayer

GAL_LAYER_ID KIGFX::PREVIEW::DRAW_CONTEXT::m_currLayer
private

◆ m_gal

KIGFX::GAL& KIGFX::PREVIEW::DRAW_CONTEXT::m_gal
private

◆ m_lineWidth

float KIGFX::PREVIEW::DRAW_CONTEXT::m_lineWidth
private

The line width to use for items.

Definition at line 106 of file draw_context.h.

Referenced by DrawArcWithAngleHighlight(), DrawCircle(), DrawLine(), and DrawLineWithAngleHighlight().

◆ m_render_settings

const KIGFX::RENDER_SETTINGS& KIGFX::PREVIEW::DRAW_CONTEXT::m_render_settings
private

The current layer to draw onto.

Definition at line 100 of file draw_context.h.

Referenced by DrawArcWithAngleHighlight(), DrawCircle(), DrawLine(), DrawLineWithAngleHighlight(), and getSpecialAngleColour().


The documentation for this class was generated from the following files: