KiCad PCB EDA Suite
Loading...
Searching...
No Matches
draw_context.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <view/view.h>
27
28using namespace KIGFX::PREVIEW;
29
30using KIGFX::COLOR4D;
31
32
33static constexpr double ANGLE_EPSILON = 1e-9;
34
35static bool angleIsSpecial( EDA_ANGLE aAngle )
36{
37 return std::fabs( std::remainder( aAngle.AsRadians(), M_PI_4 ) ) < ANGLE_EPSILON;
38}
39
40
41static COLOR4D deemphasise( const COLOR4D& aColor, bool aDeEmphasised )
42{
43 return aColor.WithAlpha( PreviewOverlayDeemphAlpha( aDeEmphasised ) );
44}
45
46
48 : m_gal( *aView.GetGAL() ),
49 m_render_settings( *aView.GetPainter()->GetSettings() ),
50 m_currLayer( LAYER_AUX_ITEMS ),
51 m_lineWidth( 1.0f )
52{
53}
54
55
56void DRAW_CONTEXT::DrawCircle( const VECTOR2I& aOrigin, double aRad, bool aDeEmphasised )
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}
66
67
68void DRAW_CONTEXT::DrawLine( const VECTOR2I& aStart, const VECTOR2I& aEnd, bool aDeEmphasised )
69{
71
73 m_gal.SetIsStroke( true );
74 m_gal.SetStrokeColor( deemphasise( strokeColor, aDeEmphasised ) );
75 m_gal.DrawLine( aStart, aEnd );
76}
77
78
80 bool aDeEmphasised )
81{
82 const VECTOR2I vec = aEnd - aStart;
84
85 if( angleIsSpecial( EDA_ANGLE( vec ) ) )
86 strokeColor = getSpecialAngleColour();
87
89 m_gal.SetIsStroke( true );
90 m_gal.SetStrokeColor( deemphasise( strokeColor, aDeEmphasised ) );
91 m_gal.DrawLine( aStart, aEnd );
92}
93
94
96{
97 return m_render_settings.IsBackgroundDark() ? COLOR4D( 0.5, 1.0, 0.5, 1.0 ) :
98 COLOR4D( 0.0, 0.7, 0.0, 1.0 );
99}
int color
Definition: DXF_plotter.cpp:57
double AsRadians() const
Definition: eda_angle.h:153
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:310
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
float m_lineWidth
The line width to use for items.
Definition: draw_context.h:107
const KIGFX::RENDER_SETTINGS & m_render_settings
The current layer to draw onto.
Definition: draw_context.h:101
DRAW_CONTEXT(KIGFX::VIEW &aView)
void DrawLine(const VECTOR2I &aStart, const VECTOR2I &aEnd, bool aDeEmphasised)
Draw a simple line on the current layer.
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...
COLOR4D getSpecialAngleColour() const
The GAL to draw into.
void DrawCircle(const VECTOR2I &aOrigin, double aRad, bool aDeEmphasised)
Draw a preview circle on the current layer.
virtual bool IsBackgroundDark() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
static COLOR4D deemphasise(const COLOR4D &aColor, bool aDeEmphasised)
static constexpr double ANGLE_EPSILON
static bool angleIsSpecial(EDA_ANGLE aAngle)
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc)
Definition: layer_ids.h:222
double PreviewOverlayDeemphAlpha(bool aDeemph=true)
Default alpha of "de-emphasised" features (like previously locked-in lines.