KiCad PCB EDA Suite
ws_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) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 // For page and paper size, values are in 1/1000 inch
25 
26 #ifndef WS_PAINTER_H
27 #define WS_PAINTER_H
28 
29 #include <gal/color4d.h>
30 #include <painter.h>
31 #include <page_info.h>
32 
33 // Forward declarations:
34 class EDA_RECT;
35 class TITLE_BLOCK;
36 
37 using KIGFX::COLOR4D;
38 
39 namespace KIGFX
40 {
41 
47 {
48 public:
49  friend class WS_PAINTER;
50 
52 
54  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
55 
56  inline bool IsBackgroundDark() const override
57  {
58  auto luma = m_backgroundColor.GetBrightness();
59  return luma < 0.5;
60  }
61 
62  const COLOR4D& GetBackgroundColor() override { return m_backgroundColor; }
63  void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; }
64 
65  void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; }
66  void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; }
67  void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; }
68 
69  const COLOR4D& GetGridColor() override
70  {
72  return m_gridColor;
73  }
74 
75  const COLOR4D& GetCursorColor() override
76  {
78  return m_cursorColor;
79  }
80 
81 private:
85 
88 };
89 
90 
95 class WS_PAINTER : public PAINTER
96 {
97 public:
98  WS_PAINTER( GAL* aGal ) :
99  PAINTER( aGal )
100  { }
101 
103  virtual bool Draw( const VIEW_ITEM*, int ) override;
104 
105  void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const;
106 
108  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
109  {
110  m_renderSettings = *static_cast<const WS_RENDER_SETTINGS*>( aSettings );
111  }
112 
114  virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; }
115 
116 private:
117  void draw( const WS_DRAW_ITEM_LINE* aItem, int aLayer ) const;
118  void draw( const WS_DRAW_ITEM_RECT* aItem, int aLayer ) const;
119  void draw( const WS_DRAW_ITEM_POLYPOLYGONS* aItem, int aLayer ) const;
120  void draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const;
121  void draw( const WS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const;
122  void draw( const WS_DRAW_ITEM_PAGE* aItem, int aLayer ) const;
123 
124 private:
126 };
127 
128 } // namespace KIGFX
129 
130 
151 void PrintPageLayout( wxDC* aDC, const PAGE_INFO& aPageInfo, const wxString& aFullSheetName,
152  const wxString& aFileName, const TITLE_BLOCK& aTitleBlock, int aSheetCount,
153  int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor,
154  const wxString& aSheetLayer = wxEmptyString );
155 
156 #endif // WS_PAINTER_H
Class WS_RENDER_SETTINGS Stores page-layout-specific render settings.
Definition: ws_painter.h:46
void SetNormalColor(const COLOR4D &aColor)
Definition: ws_painter.h:65
double GetBrightness() const
Function GetBrightness Returns the brightness value of the color ranged from 0.0 to 1....
Definition: color4d.h:269
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:125
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
Definition: painter.h:56
bool IsBackgroundDark() const override
Definition: ws_painter.h:56
WS_PAINTER(GAL *aGal)
Definition: ws_painter.h:98
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:313
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
Definition: ws_painter.h:75
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:363
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
void SetBackgroundColor(const COLOR4D &aColor) override
Sets the background color.
Definition: ws_painter.h:63
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:263
Class WS_PAINTER Contains methods for drawing worksheet items.
Definition: ws_painter.h:95
virtual void ApplySettings(const RENDER_SETTINGS *aSettings) override
Function ApplySettings Loads colors and display modes settings that are going to be used when drawing...
Definition: ws_painter.h:108
COLOR4D m_backgroundColor
The background color.
Definition: painter.h:297
const COLOR4D & GetBackgroundColor() override
Function GetBackgroundColor Returns current background color settings.
Definition: ws_painter.h:62
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
Definition: ws_painter.cpp:55
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const COLOR4D & GetGridColor() override
Function GetGridColor Returns current grid color settings.
Definition: ws_painter.h:69
Definition: colors.h:49
void SetSelectedColor(const COLOR4D &aColor)
Definition: ws_painter.h:66
Definition: colors.h:45
void SetBrightenedColor(const COLOR4D &aColor)
Definition: ws_painter.h:67
virtual bool Draw(const VIEW_ITEM *, int) override
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
Definition: ws_painter.cpp:244
virtual RENDER_SETTINGS * GetSettings() override
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Definition: ws_painter.h:114
Class GAL is the abstract interface for drawing on a 2D-surface.
void PrintPageLayout(wxDC *aDC, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, int aPenWidth, double aScalar, COLOR4D aColor, const wxString &aSheetLayer=wxEmptyString)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39