KiCad PCB EDA Suite
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 <tomasz.wlostowski@cern.ch>
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 <view/view.h>
29 #include <pcb_painter.h>
30 
31 using namespace KIGFX::PREVIEW;
32 
34 {
40 };
41 
43  { // dark background
44  COLOR4D( 0.3, 0.3, 0.7, 0.3 ), // Slight blue
45  COLOR4D( 0.3, 0.7, 0.3, 0.3 ), // Slight green
46  COLOR4D( 0.7, 0.3, 0.3, 0.3 ), // Slight red
47 
48  COLOR4D( 1.0, 1.0, 0.4, 1.0 ), // yellow
49  COLOR4D( 0.4, 0.4, 1.0, 1.0 ) // blue
50  },
51  { // bright background
52  COLOR4D( 0.5, 0.3, 1.0, 0.5 ), // Slight blue
53  COLOR4D( 0.5, 1.0, 0.5, 0.5 ), // Slight green
54  COLOR4D( 1.0, 0.5, 0.5, 0.5 ), // Slight red
55 
56  COLOR4D( 0.7, 0.7, 0.0, 1.0 ), // yellow
57  COLOR4D( 0.1, 0.1, 1.0, 1.0 ) // blue
58  }
59 };
60 
61 
63  m_additive( false ),
64  m_subtractive( false )
65 {
66 
67 }
68 
69 
70 void SELECTION_AREA::SetAdditive( bool aAdditive )
71 {
72  m_additive = aAdditive;
73 
74  if( m_additive )
75  m_subtractive = false;
76 }
77 
78 
79 void SELECTION_AREA::SetSubtractive( bool aSubtractive )
80 {
81  m_subtractive = aSubtractive;
82 
83  if( m_subtractive )
84  m_additive = false;
85 }
86 
87 
89 {
90  BOX2I tmp;
91 
92  tmp.SetOrigin( m_origin );
93  tmp.SetEnd( m_end );
94  tmp.Normalize();
95  return tmp;
96 }
97 
98 
99 void SELECTION_AREA::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
100 {
101  auto& gal = *aView->GetGAL();
102  auto rs = aView->GetPainter()->GetSettings();
103 
104  const auto& scheme = rs->IsBackgroundDark() ? selectionColorScheme[0] : selectionColorScheme[1];
105 
106  // Set the fill of the selection rectangle
107  // based on the selection mode
108  if( m_additive )
109  {
110  gal.SetFillColor( scheme.additive );
111  }
112  else if( m_subtractive )
113  {
114  gal.SetFillColor( scheme.subtract );
115  }
116  else
117  {
118  gal.SetFillColor( scheme.normal );
119  }
120 
121  gal.SetIsStroke( true );
122  gal.SetIsFill( true );
123 
124  gal.SetLineWidth( 1.0 / gal.GetWorldScale() );
125 
126  // Set the stroke color to indicate window or crossing selection
127  bool windowSelection = ( m_origin.x <= m_end.x ) ? true : false;
128 
129  if( aView->IsMirroredX() )
130  windowSelection = !windowSelection;
131 
132  gal.SetStrokeColor( windowSelection ? scheme.outline_l2r : scheme.outline_r2l );
133  gal.DrawRectangle( m_origin, m_end );
134 }
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
static const SELECTION_COLORS selectionColorScheme[2]
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const overridefinal
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:127
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:223
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void SetSubtractive(bool aSubtractive)
void SetOrigin(const Vec &pos)
Definition: box2.h:208
Class VIEW.
Definition: view.h:61
void SetAdditive(bool aAdditive)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
virtual bool IsBackgroundDark() const
Definition: painter.h:237