KiCad PCB EDA Suite
Loading...
Searching...
No Matches
selection_area.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) 2013 CERN
5 * @author Tomasz Wlostowski <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26
28#include <gal/painter.h>
29#include <view/view.h>
30
31using namespace KIGFX::PREVIEW;
32using KIGFX::COLOR4D;
33
35{
42};
43
45 { // dark background
46 COLOR4D( 0.3, 0.3, 0.7, 0.3 ), // Slight blue
47 COLOR4D( 0.3, 0.7, 0.3, 0.3 ), // Slight green
48 COLOR4D( 0.7, 0.3, 0.3, 0.3 ), // Slight red
49 COLOR4D( 0.7, 0.3, 0.3, 0.3 ), // Slight red
50
51 COLOR4D( 1.0, 1.0, 0.4, 1.0 ), // yellow
52 COLOR4D( 0.4, 0.4, 1.0, 1.0 ) // blue
53 },
54 { // bright background
55 COLOR4D( 0.5, 0.3, 1.0, 0.5 ), // Slight blue
56 COLOR4D( 0.5, 1.0, 0.5, 0.5 ), // Slight green
57 COLOR4D( 1.0, 0.5, 0.5, 0.5 ), // Slight red
58 COLOR4D( 1.0, 0.5, 0.5, 0.5 ), // Slight red
59
60 COLOR4D( 0.7, 0.7, 0.0, 1.0 ), // yellow
61 COLOR4D( 0.1, 0.1, 1.0, 1.0 ) // blue
62 }
63};
64
65
67 m_additive( false ),
68 m_subtractive( false ),
69 m_exclusiveOr( false ),
71{
72
73}
74
75
77{
78 BOX2I tmp;
79
80 switch( m_mode )
81 {
82 default:
83 case SELECTION_MODE::INSIDE_RECTANGLE:
84 case SELECTION_MODE::TOUCHING_RECTANGLE:
85 tmp.SetOrigin( m_origin );
86 tmp.SetEnd( m_end );
87 break;
88 case SELECTION_MODE::INSIDE_LASSO:
89 case SELECTION_MODE::TOUCHING_LASSO:
90 tmp = m_shape_poly.BBox();
91 break;
92 }
93
94 tmp.Normalize();
95
96 return tmp;
97}
98
99
100void SELECTION_AREA::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
101{
102 KIGFX::GAL& gal = *aView->GetGAL();
103 RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
104
105 const SELECTION_COLORS& scheme = settings->IsBackgroundDark() ? selectionColorScheme[0]
107
108 // Set the colors of the selection shape based on the selection mode
109 if( m_additive )
110 gal.SetFillColor( scheme.additive );
111 else if( m_subtractive )
112 gal.SetFillColor( scheme.subtract );
113 else if( m_exclusiveOr )
114 gal.SetFillColor( scheme.exclusiveOr );
115 else
116 gal.SetFillColor( scheme.normal );
117
118 if( m_mode == SELECTION_MODE::INSIDE_RECTANGLE || m_mode == SELECTION_MODE::INSIDE_LASSO )
119 gal.SetStrokeColor( scheme.outline_l2r );
120 else
121 gal.SetStrokeColor( scheme.outline_r2l );
122
123 auto drawSelectionShape =
124 [&]()
125 {
126 switch( m_mode )
127 {
128 default:
129 case SELECTION_MODE::INSIDE_RECTANGLE:
130 case SELECTION_MODE::TOUCHING_RECTANGLE:
132 break;
133 case SELECTION_MODE::INSIDE_LASSO:
134 case SELECTION_MODE::TOUCHING_LASSO:
135 if( m_shape_poly.PointCount() > 1 )
137 break;
138 }
139 };
140
141 gal.SetIsStroke( true );
142 gal.SetIsFill( false );
143 // force 1-pixel-wide line
144 gal.SetLineWidth( 0.0 );
145 drawSelectionShape();
146
147 // draw the fill as the second object so that Z test will not clamp
148 // the single-pixel-wide rectangle sides
149 gal.SetIsFill( true );
150 drawSelectionShape();
151}
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr void SetEnd(coord_type x, coord_type y)
Definition: box2.h:297
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
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 RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override final
Draw the parts of the object belonging to layer aLayer.
const BOX2I ViewBBox() const override
Set the origin of the rectangle (the fixed corner)
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
virtual bool IsBackgroundDark() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:202
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:220
int PointCount() const
Return the number of points (vertices) in this line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
static const SELECTION_COLORS selectionColorScheme[2]
SELECTION_MODE