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>
34 #include <ws_draw_item.h>
36 #include <memory>
37 
38 class EDA_ITEM;
39 class COLOR_SETTINGS;
40 
41 namespace KIGFX
42 {
43 class GAL;
44 class VIEW_ITEM;
45 
57 {
58 public:
60  virtual ~RENDER_SETTINGS();
61 
62  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
63 
71  inline void SetActiveLayer( int aLayerId, bool aEnabled = true )
72  {
73  if( aEnabled )
74  m_activeLayers.insert( aLayerId );
75  else
76  m_activeLayers.erase( aLayerId );
77  }
78 
84  const std::set<unsigned int> GetActiveLayers()
85  {
86  return m_activeLayers;
87  }
88 
93  inline void ClearActiveLayers()
94  {
95  m_activeLayers.clear();
96  }
97 
103  inline bool IsActiveLayer( int aLayerId ) const
104  {
105  return ( m_activeLayers.count( aLayerId ) > 0 );
106  }
107 
113  inline bool IsHighlightEnabled() const
114  {
115  return m_highlightEnabled;
116  }
117 
123  inline int GetHighlightNetCode() const
124  {
125  return m_highlightNetcode;
126  }
127 
136  inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aHighlightItems = false )
137  {
138  m_highlightEnabled = aEnabled;
139  m_highlightNetcode = aEnabled ? aNetcode : -1;
140  m_highlightItems = aEnabled ? aHighlightItems : false;
141  }
142 
148  inline void SetHighContrast( bool aEnabled )
149  {
150  m_hiContrastEnabled = aEnabled;
151  }
152 
158  inline bool GetHighContrast() const
159  {
160  return m_hiContrastEnabled;
161  }
162 
171  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
172 
173  float GetWorksheetLineWidth() const
174  {
175  return m_worksheetLineWidth;
176  }
177 
178  inline bool GetShowPageLimits() const
179  {
180  return m_showPageLimits;
181  }
182 
183  inline void SetShowPageLimits( bool aDraw )
184  {
185  m_showPageLimits = aDraw;
186  }
187 
192  virtual const COLOR4D& GetBackgroundColor() = 0;
193 
197  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
198 
203  virtual const COLOR4D& GetGridColor() = 0;
204 
209  virtual const COLOR4D& GetCursorColor() = 0;
210 
216  inline const COLOR4D& GetLayerColor( int aLayer ) const
217  {
218  return m_layerColors[aLayer];
219  }
220 
227  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
228  {
229  m_layerColors[aLayer] = aColor;
230 
231  update(); // recompute other shades of the color
232  }
233 
234  virtual bool IsBackgroundDark() const
235  {
236  return false;
237  }
238 
244  void SetOutlineWidth( float aWidth )
245  {
246  m_outlineWidth = aWidth;
247  }
248 
249 protected:
255  virtual void update();
256 
257  std::set<unsigned int> m_activeLayers;
258 
261 
264 
267 
270 
273 
277 
280  bool m_highlightItems;
284 
289 
291 
293 };
294 
295 
308 class PAINTER
309 {
310 public:
320  PAINTER( GAL* aGal );
321  virtual ~PAINTER();
322 
328  void SetGAL( GAL* aGal )
329  {
330  m_gal = aGal;
331  }
332 
338  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) = 0;
339 
345  virtual RENDER_SETTINGS* GetSettings() = 0;
346 
355  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0;
356 
357 protected:
361 
364 };
365 } // namespace KIGFX
366 
367 #endif /* __CLASS_PAINTER_H */
float m_worksheetLineWidth
Line width used when drawing worksheet.
Definition: painter.h:288
bool m_highlightItems
Highlight items with their HIGHLIGHT flags set.
Definition: painter.h:282
virtual const COLOR4D & GetGridColor()=0
Function GetGridColor Returns current grid color settings.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:131
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:287
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Definition: painter.h:56
virtual const COLOR4D & GetCursorColor()=0
Function GetCursorColor Returns current cursor color settings.
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
Colors for all layers (highlighted)
Definition: painter.h:263
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:260
virtual const COLOR4D & GetBackgroundColor()=0
Function GetBackgroundColor Returns current background color settings.
PAINTER(GAL *aGal)
Constructor PAINTER( GAL* ) initializes this object for painting on any of the polymorphic GRAPHICS_A...
Definition: painter.cpp:68
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:216
bool GetShowPageLimits() const
Definition: painter.h:178
virtual ~PAINTER()
Definition: painter.cpp:75
bool IsActiveLayer(int aLayerId) const
Function IsActiveLayer Returns information whether the queried layer is marked as active.
Definition: painter.h:103
bool m_highlightEnabled
Highlight display mode on/off.
Definition: painter.h:278
float m_highlightFactor
Factor used for computing highlight color.
Definition: painter.h:283
bool IsHighlightEnabled() const
Function IsHighlightEnabled Returns current highlight setting.
Definition: painter.h:113
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
void SetOutlineWidth(float aWidth)
Set line width used for drawing outlines.
Definition: painter.h:244
virtual void ApplySettings(const RENDER_SETTINGS *aSettings)=0
Function ApplySettings Loads colors and display modes settings that are going to be used when drawing...
virtual bool IsBackgroundDark() const
Definition: painter.h:234
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:71
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:360
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...
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]
Definition: painter.h:272
std::set< unsigned int > m_activeLayers
Stores active layers number.
Definition: painter.h:257
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:308
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
Colors for all layers (darkened)
Definition: painter.h:269
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:93
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aHighlightItems=false)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer,...
Definition: painter.h:136
bool m_hiContrastEnabled
Parameters for display modes.
Definition: painter.h:275
virtual void update()
Function update Precalculates extra colors for layers (e.g.
Definition: painter.cpp:54
COLOR4D m_brightenedColor
Color of brightened item frame.
Definition: painter.h:363
void SetHighContrast(bool aEnabled)
Function SetHighContrast Turns on/off high contrast display mode.
Definition: painter.h:148
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:227
float m_layerOpacity
Determines opacity of all layers.
Definition: painter.h:286
#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...
float m_hiContrastFactor
Factor used for computing high contrast color.
Definition: painter.h:276
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:158
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:292
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Sets the background color.
Board layer functions and definitions.
float GetWorksheetLineWidth() const
Definition: painter.h:173
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
int GetHighlightNetCode() const
Function GetHighlightNetCode Returns netcode of currently highlighted net.
Definition: painter.h:123
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:279
virtual ~RENDER_SETTINGS()
Definition: painter.cpp:49
void SetGAL(GAL *aGal)
Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one.
Definition: painter.h:328
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
Definition: painter.h:62
float m_selectFactor
Specifies how color of selected items is changed.
Definition: painter.h:285
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
Colors for all layers (selected)
Definition: painter.h:266
void SetShowPageLimits(bool aDraw)
Definition: painter.h:183
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:84
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40