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 
76  inline void SetActiveLayer( int aLayerId, bool aEnabled = true )
77  {
78  if( aEnabled )
79  m_activeLayers.insert( aLayerId );
80  else
81  m_activeLayers.erase( aLayerId );
82  }
83 
89  const std::set<unsigned int> GetActiveLayers()
90  {
91  return m_activeLayers;
92  }
93 
98  inline void ClearActiveLayers()
99  {
100  m_activeLayers.clear();
101  }
102 
108  inline bool IsActiveLayer( int aLayerId ) const
109  {
110  return ( m_activeLayers.count( aLayerId ) > 0 );
111  }
112 
118  inline bool IsHighlightEnabled() const
119  {
120  return m_highlightEnabled;
121  }
122 
128  inline int GetHighlightNetCode() const
129  {
130  return m_highlightNetcode;
131  }
132 
140  inline void SetHighlight( bool aEnabled, int aNetcode = -1 )
141  {
142  m_highlightEnabled = aEnabled;
143  m_highlightNetcode = aEnabled ? aNetcode : -1;
144  }
145 
151  inline void SetHighContrast( bool aEnabled )
152  {
153  m_hiContrastEnabled = aEnabled;
154  }
155 
161  inline bool GetHighContrast() const
162  {
163  return m_hiContrastEnabled;
164  }
165 
174  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
175 
176  float GetWorksheetLineWidth() const
177  {
178  return m_worksheetLineWidth;
179  }
180 
186  inline const COLOR4D& GetBackgroundColor() const
187  {
188  return m_backgroundColor;
189  }
190 
196  inline void SetBackgroundColor( const COLOR4D& aColor )
197  {
198  m_backgroundColor = aColor;
199  }
200 
206  inline const COLOR4D& GetLayerColor( int aLayer ) const
207  {
208  return m_layerColors[aLayer];
209  }
210 
217  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
218  {
219  m_layerColors[aLayer] = aColor;
220 
221  update(); // recompute other shades of the color
222  }
223 
224 protected:
230  virtual void update();
231 
232  std::set<unsigned int> m_activeLayers;
233 
236 
239 
242 
245 
250 
253  float m_highlightFactor;
256 
261 
263 };
264 
265 
278 class PAINTER
279 {
280 public:
281  /*
282  * Constructor PAINTER( GAL* )
283  * initializes this object for painting on any of the polymorphic
284  * GRAPHICS_ABSTRACTION_LAYER* derivatives.
285  *
286  * @param aGal is a pointer to a polymorphic GAL device on which
287  * to draw (i.e. Cairo, OpenGL, wxDC)
288  * No ownership is given to this PAINTER of aGal.
289  */
290  PAINTER( GAL* aGal );
291  virtual ~PAINTER();
292 
298  void SetGAL( GAL* aGal )
299  {
300  m_gal = aGal;
301  }
302 
308  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) = 0;
309 
315  virtual RENDER_SETTINGS* GetSettings() = 0;
316 
325  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0;
326 
327 protected:
331 
334 };
335 } // namespace KIGFX
336 
337 #endif /* __CLASS_PAINTER_H */
float m_worksheetLineWidth
Line width used when drawing worksheet.
Definition: painter.h:260
COLOR4D m_hiContrastColor
Color used for high contrast display mode.
Definition: painter.h:248
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:161
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:259
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:238
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:235
PAINTER(GAL *aGal)
Definition: painter.cpp:67
virtual ~PAINTER()
Definition: painter.cpp:73
bool m_highlightEnabled
Highlight display mode on/off.
Definition: painter.h:251
float m_highlightFactor
Factor used for computing hightlight color.
Definition: painter.h:255
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:206
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:118
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:76
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg...
Definition: painter.h:330
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:128
bool IsActiveLayer(int aLayerId) const
Function IsActiveLayer Returns information whether the queried layer is marked as active...
Definition: painter.h:108
std::set< unsigned int > m_activeLayers
Stores active layers number.
Definition: painter.h:232
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:278
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
Colors for all layers (darkened)
Definition: painter.h:244
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
bool m_hiContrastEnabled
Parameters for display modes.
Definition: painter.h:247
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:333
void SetHighContrast(bool aEnabled)
Function SetHighContrast Turns on/off high contrast display mode.
Definition: painter.h:151
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:217
float m_layerOpacity
Determines opacity of all layers.
Definition: painter.h:258
float GetWorksheetLineWidth() const
Definition: painter.h:176
#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:249
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:262
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:196
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:252
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:298
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:140
float m_selectFactor
Specifies how color of selected items is changed.
Definition: painter.h:257
const COLOR4D & GetBackgroundColor() const
Function GetBackgroundColor Returns current background color settings.
Definition: painter.h:186
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
Colors for all layers (selected)
Definition: painter.h:241
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:89
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39