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 
30 using namespace KIGFX::PREVIEW;
31 
32 // Selection area colours
33 const COLOR4D SELECT_MODE_NORMAL( 0.3, 0.3, 0.7, 0.3 ); // Slight blue
34 const COLOR4D SELECT_MODE_ADDITIVE( 0.3, 0.7, 0.3, 0.3 ); // Slight green
35 const COLOR4D SELECT_MODE_SUBTRACT( 0.7, 0.3, 0.3, 0.3 ); // Slight red
36 
37 const COLOR4D SELECT_OUTLINE_L2R( 1.0, 1.0, 0.4, 1.0 );
38 const COLOR4D SELECT_OUTLINE_R2L( 0.4, 0.4, 1.0, 1.0 );
39 
41  m_additive( false ),
42  m_subtractive( false )
43 {
46 }
47 
48 
49 void SELECTION_AREA::SetAdditive( bool aAdditive )
50 {
51  m_additive = aAdditive;
52 
53  if( m_additive )
54  m_subtractive = false;
55 }
56 
57 
58 void SELECTION_AREA::SetSubtractive( bool aSubtractive )
59 {
60  m_subtractive = aSubtractive;
61 
62  if( m_subtractive )
63  m_additive = false;
64 }
65 
66 
68 {
69  BOX2I tmp;
70 
71  tmp.SetOrigin( m_origin );
72  tmp.SetEnd( m_end );
73  tmp.Normalize();
74  return tmp;
75 }
76 
77 
79 {
80  // Set the fill of the selection rectangle
81  // based on the selection mode
82  if( m_additive )
83  {
85  }
86  else if( m_subtractive )
87  {
89  }
90  else
91  {
93  }
94 
95  // Set the stroke color to indicate window or crossing selection
97 
98  aGal.DrawRectangle( m_origin, m_end );
99 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
void SetStrokeColor(const COLOR4D &aNewColor)
Set the stroke colour to set before drawing preview
BOX2< Vec > & Normalize()
Function Normalize ensures that the height ant width are positive.
Definition: box2.h:117
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
const COLOR4D SELECT_MODE_NORMAL(0.3, 0.3, 0.7, 0.3)
void drawPreviewShape(KIGFX::GAL &aGal) const override
Draw the selection rectangle onto the GAL.
const COLOR4D SELECT_MODE_SUBTRACT(0.7, 0.3, 0.3, 0.3)
void SetFillColor(const COLOR4D &aNewColor)
Set the fill colour to set before drawing preview
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:213
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
const COLOR4D SELECT_OUTLINE_L2R(1.0, 1.0, 0.4, 1.0)
void SetSubtractive(bool aSubtractive)
void SetOrigin(const Vec &pos)
Definition: box2.h:198
void SetAdditive(bool aAdditive)
Class GAL is the abstract interface for drawing on a 2D-surface.
const COLOR4D SELECT_OUTLINE_R2L(0.4, 0.4, 1.0, 1.0)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
const COLOR4D SELECT_MODE_ADDITIVE(0.3, 0.7, 0.3, 0.3)