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 
181  inline bool GetShowPageLimits() const
182  {
183  return m_showPageLimits;
184  }
185 
186  inline void SetShowPageLimits( bool aDraw )
187  {
188  m_showPageLimits = aDraw;
189  }
190 
195  virtual const COLOR4D& GetBackgroundColor() = 0;
196 
200  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
201 
206  virtual const COLOR4D& GetGridColor() = 0;
207 
212  virtual const COLOR4D& GetCursorColor() = 0;
213 
219  inline const COLOR4D& GetLayerColor( int aLayer ) const
220  {
221  return m_layerColors[aLayer];
222  }
223 
230  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
231  {
232  m_layerColors[aLayer] = aColor;
233 
234  update(); // recompute other shades of the color
235  }
236 
237  virtual bool IsBackgroundDark() const
238  {
239  return false;
240  }
241 
247  void SetOutlineWidth( float aWidth )
248  {
249  m_outlineWidth = aWidth;
250  }
251 
252 protected:
258  virtual void update();
259 
260  std::set<unsigned int> m_activeLayers;
261 
264 
267 
270 
273 
278 
281  float m_highlightFactor;
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
COLOR4D m_hiContrastColor
Color used for high contrast display mode.
Definition: painter.h:276
bool GetShowPageLimits() const
Definition: painter.h:181
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:161
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: class_module.h:58
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:287
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
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:266
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:263
virtual const COLOR4D & GetBackgroundColor()=0
Function GetBackgroundColor Returns current background color settings.
bool m_highlightEnabled
Highlight display mode on/off.
Definition: painter.h:279
float m_highlightFactor
Factor used for computing hightlight color.
Definition: painter.h:283
Class 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:247
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:219
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: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...
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:260
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:308
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
Colors for all layers (darkened)
Definition: painter.h:272
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
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:53
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:151
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:230
float m_layerOpacity
Determines opacity of all layers.
Definition: painter.h:286
float GetWorksheetLineWidth() const
Definition: painter.h:176
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
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:277
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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
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:280
virtual ~RENDER_SETTINGS()
Definition: painter.cpp:48
void SetGAL(GAL *aGal)
Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one...
Definition: painter.h:328
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:285
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
Colors for all layers (selected)
Definition: painter.h:269
void SetShowPageLimits(bool aDraw)
Definition: painter.h:186
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
virtual bool IsBackgroundDark() const
Definition: painter.h:237