KiCad PCB EDA Suite
painter.h
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) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2013 CERN
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef __CLASS_PAINTER_H
28 #define __CLASS_PAINTER_H
29 
30 #include <map>
31 #include <set>
32 
33 #include <gal/color4d.h>
36 #include <memory>
37 
38 class EDA_ITEM;
40 
41 namespace KIGFX
42 {
43 class GAL;
44 class VIEW_ITEM;
45 
57 {
58 public:
60  virtual ~RENDER_SETTINGS();
61 
67  virtual void ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings ) = 0;
68 
75  inline void SetActiveLayer( int aLayerId, bool aEnabled = true )
76  {
77  if( aEnabled )
78  m_activeLayers.insert( aLayerId );
79  else
80  m_activeLayers.erase( aLayerId );
81  }
82 
88  const std::set<unsigned int> GetActiveLayers()
89  {
90  return m_activeLayers;
91  }
92 
97  inline void ClearActiveLayers()
98  {
99  m_activeLayers.clear();
100  }
101 
107  inline bool IsActiveLayer( int aLayerId ) const
108  {
109  return ( m_activeLayers.count( aLayerId ) > 0 );
110  }
111 
117  inline bool IsHighlightEnabled() const
118  {
119  return m_highlightEnabled;
120  }
121 
127  inline int GetHighlightNetCode() const
128  {
129  return m_highlightNetcode;
130  }
131 
139  inline void SetHighlight( bool aEnabled, int aNetcode = -1 )
140  {
141  m_highlightEnabled = aEnabled;
142  m_highlightNetcode = aEnabled ? aNetcode : -1;
143  }
144 
150  inline void SetHighContrast( bool aEnabled )
151  {
152  m_hiContrastEnabled = aEnabled;
153  }
154 
160  inline bool GetHighContrast() const
161  {
162  return m_hiContrastEnabled;
163  }
164 
173  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
174 
175  float GetWorksheetLineWidth() const
176  {
177  return m_worksheetLineWidth;
178  }
179 
185  inline const COLOR4D& GetBackgroundColor() const
186  {
187  return m_backgroundColor;
188  }
189 
195  inline void SetBackgroundColor( const COLOR4D& aColor )
196  {
197  m_backgroundColor = aColor;
198  }
199 
205  inline const COLOR4D& GetLayerColor( int aLayer ) const
206  {
207  return m_layerColors[aLayer];
208  }
209 
216  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
217  {
218  m_layerColors[aLayer] = aColor;
219 
220  update(); // recompute other shades of the color
221  }
222 
223 protected:
229  virtual void update();
230 
231  std::set<unsigned int> m_activeLayers;
232 
235 
238 
241 
244 
249 
252  float m_highlightFactor;
255 
260 
262 };
263 
264 
277 class PAINTER
278 {
279 public:
280  /*
281  * Constructor PAINTER( GAL* )
282  * initializes this object for painting on any of the polymorphic
283  * GRAPHICS_ABSTRACTION_LAYER* derivatives.
284  *
285  * @param aGal is a pointer to a polymorphic GAL device on which
286  * to draw (i.e. Cairo, OpenGL, wxDC)
287  * No ownership is given to this PAINTER of aGal.
288  */
289  PAINTER( GAL* aGal );
290  virtual ~PAINTER();
291 
297  void SetGAL( GAL* aGal )
298  {
299  m_gal = aGal;
300  }
301 
307  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) = 0;
308 
314  virtual RENDER_SETTINGS* GetSettings() = 0;
315 
324  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0;
325 
326 protected:
330 
333 };
334 } // namespace KIGFX
335 
336 #endif /* __CLASS_PAINTER_H */
float m_worksheetLineWidth
Line width used when drawing worksheet.
Definition: painter.h:259
COLOR4D m_hiContrastColor
Color used for high contrast display mode.
Definition: painter.h:247
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:160
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:258
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
Definition: painter.h:56
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
Colors for all layers (highlighted)
Definition: painter.h:237
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:234
PAINTER(GAL *aGal)
Definition: painter.cpp:67
virtual ~PAINTER()
Definition: painter.cpp:73
bool m_highlightEnabled
Highlight display mode on/off.
Definition: painter.h:250
float m_highlightFactor
Factor used for computing hightlight color.
Definition: painter.h:254
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:82
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:205
virtual void ApplySettings(const RENDER_SETTINGS *aSettings)=0
Function ApplySettings Loads colors and display modes settings that are going to be used when drawing...
bool IsHighlightEnabled() const
Function IsHighlightEnabled Returns current highlight setting.
Definition: painter.h:117
void SetActiveLayer(int aLayerId, bool aEnabled=true)
Function SetActiveLayer Sets the specified layer as active - it means that it can be drawn in a speci...
Definition: painter.h:75
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg...
Definition: painter.h:329
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
int GetHighlightNetCode() const
Function GetHighlightNetCode Returns netcode of currently highlighted net.
Definition: painter.h:127
bool IsActiveLayer(int aLayerId) const
Function IsActiveLayer Returns information whether the queried layer is marked as active...
Definition: painter.h:107
std::set< unsigned int > m_activeLayers
Stores active layers number.
Definition: painter.h:231
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:277
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
Colors for all layers (darkened)
Definition: painter.h:243
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:97
bool m_hiContrastEnabled
Parameters for display modes.
Definition: painter.h:246
virtual void update()
Function update Precalculates extra colors for layers (e.g.
Definition: painter.cpp:52
COLOR4D m_brightenedColor
Color of brightened item frame.
Definition: painter.h:332
void SetHighContrast(bool aEnabled)
Function SetHighContrast Turns on/off high contrast display mode.
Definition: painter.h:150
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:216
float m_layerOpacity
Determines opacity of all layers.
Definition: painter.h:257
float GetWorksheetLineWidth() const
Definition: painter.h:175
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer)=0
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
virtual void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings)=0
Function ImportLegacyColors Loads a list of color settings for layers.
float m_hiContrastFactor
Factor used for computing high contrast color.
Definition: painter.h:248
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
COLOR4D m_backgroundColor
The background color.
Definition: painter.h:261
Board layer functions and definitions.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Eeschema, Pcbnew and GerbView...
void SetBackgroundColor(const COLOR4D &aColor)
Function SetBackgroundColor Sets new color for background.
Definition: painter.h:195
classes and function to generate graphics to plt or draw titles blocks and frame references ...
int m_highlightNetcode
Net number that is displayed in highlight -1 means that there is no specific net, and whole active la...
Definition: painter.h:251
virtual ~RENDER_SETTINGS()
Definition: painter.cpp:47
void SetGAL(GAL *aGal)
Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one...
Definition: painter.h:297
void SetHighlight(bool aEnabled, int aNetcode=-1)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
Definition: painter.h:139
float m_selectFactor
Specifies how color of selected items is changed.
Definition: painter.h:256
const COLOR4D & GetBackgroundColor() const
Function GetBackgroundColor Returns current background color settings.
Definition: painter.h:185
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
Colors for all layers (selected)
Definition: painter.h:240
Class GAL is the abstract interface for drawing on a 2D-surface.
const std::set< unsigned int > GetActiveLayers()
Function GetActiveLayers() Returns the set of currently active layers.
Definition: painter.h:88
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39