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;
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 ) { }
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 
141  inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aHighlightItems = false )
142  {
143  m_highlightEnabled = aEnabled;
144  m_highlightNetcode = aEnabled ? aNetcode : -1;
145  m_highlightItems = aEnabled ? aHighlightItems : false;
146  }
147 
153  inline void SetHighContrast( bool aEnabled )
154  {
155  m_hiContrastEnabled = aEnabled;
156  }
157 
163  inline bool GetHighContrast() const
164  {
165  return m_hiContrastEnabled;
166  }
167 
176  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
177 
178  float GetWorksheetLineWidth() const
179  {
180  return m_worksheetLineWidth;
181  }
182 
183  inline bool GetShowPageLimits() const
184  {
185  return m_showPageLimits;
186  }
187 
188  inline void SetShowPageLimits( bool aDraw )
189  {
190  m_showPageLimits = aDraw;
191  }
192 
197  virtual const COLOR4D& GetBackgroundColor() = 0;
198 
202  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
203 
208  virtual const COLOR4D& GetGridColor() = 0;
209 
214  virtual const COLOR4D& GetCursorColor() = 0;
215 
221  inline const COLOR4D& GetLayerColor( int aLayer ) const
222  {
223  return m_layerColors[aLayer];
224  }
225 
232  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
233  {
234  m_layerColors[aLayer] = aColor;
235 
236  update(); // recompute other shades of the color
237  }
238 
239  virtual bool IsBackgroundDark() const
240  {
241  return false;
242  }
243 
249  void SetOutlineWidth( float aWidth )
250  {
251  m_outlineWidth = aWidth;
252  }
253 
254 protected:
260  virtual void update();
261 
262  std::set<unsigned int> m_activeLayers;
263 
266 
269 
272 
275 
278 
282 
285  bool m_highlightItems;
289 
294 
296 
298 };
299 
300 
313 class PAINTER
314 {
315 public:
325  PAINTER( GAL* aGal );
326  virtual ~PAINTER();
327 
333  void SetGAL( GAL* aGal )
334  {
335  m_gal = aGal;
336  }
337 
343  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) = 0;
344 
350  virtual RENDER_SETTINGS* GetSettings() = 0;
351 
360  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0;
361 
362 protected:
366 
369 };
370 } // namespace KIGFX
371 
372 #endif /* __CLASS_PAINTER_H */
float m_worksheetLineWidth
Line width used when drawing worksheet.
Definition: painter.h:293
bool m_highlightItems
Highlight items with their HIGHLIGHT flags set.
Definition: painter.h:287
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:57
float m_outlineWidth
Line width used when drawing outlines.
Definition: painter.h:292
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:268
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:265
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:67
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
Definition: painter.h:221
bool GetShowPageLimits() const
Definition: painter.h:183
virtual ~PAINTER()
Definition: painter.cpp:74
bool IsActiveLayer(int aLayerId) const
Function IsActiveLayer Returns information whether the queried layer is marked as active.
Definition: painter.h:108
bool m_highlightEnabled
Highlight display mode on/off.
Definition: painter.h:283
float m_highlightFactor
Factor used for computing highlight color.
Definition: painter.h:288
bool IsHighlightEnabled() const
Function IsHighlightEnabled Returns current highlight setting.
Definition: painter.h:118
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:249
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:239
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:365
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:277
std::set< unsigned int > m_activeLayers
Stores active layers number.
Definition: painter.h:262
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:313
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
Colors for all layers (darkened)
Definition: painter.h:274
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
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:141
bool m_hiContrastEnabled
Parameters for display modes.
Definition: painter.h:280
virtual void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings)
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: painter.h:67
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:368
void SetHighContrast(bool aEnabled)
Function SetHighContrast Turns on/off high contrast display mode.
Definition: painter.h:153
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
Definition: painter.h:232
float m_layerOpacity
Determines opacity of all layers.
Definition: painter.h:291
#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:281
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:163
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:297
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Sets the background color.
Board layer functions and definitions.
float GetWorksheetLineWidth() const
Definition: painter.h:178
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
int GetHighlightNetCode() const
Function GetHighlightNetCode Returns netcode of currently highlighted net.
Definition: painter.h:128
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:284
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:333
float m_selectFactor
Specifies how color of selected items is changed.
Definition: painter.h:290
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
Colors for all layers (selected)
Definition: painter.h:271
void SetShowPageLimits(bool aDraw)
Definition: painter.h:188
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