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 #include <ws_draw_item.h>
33 
34 // Forward declarations:
35 class EDA_RECT;
36 class TITLE_BLOCK;
37 
38 using KIGFX::COLOR4D;
39 
40 namespace KIGFX
41 {
42 
48 {
49 public:
50  friend class WS_PAINTER;
51 
53 
54  void LoadColors( const COLOR_SETTINGS* aSettings ) override;
55 
57  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
58 
59  inline bool IsBackgroundDark() const override
60  {
61  auto luma = m_backgroundColor.GetBrightness();
62  return luma < 0.5;
63  }
64 
65  const COLOR4D& GetBackgroundColor() override { return m_backgroundColor; }
66  void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; }
67 
68  void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; }
69  void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; }
70  void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; }
71  void SetPageBorderColor( const COLOR4D& aColor ) { m_pageBorderColor = aColor; }
72 
73  const COLOR4D& GetGridColor() override
74  {
76  return m_gridColor;
77  }
78 
79  const COLOR4D& GetCursorColor() override
80  {
82  return m_cursorColor;
83  }
84 
85 private:
89 
93 };
94 
95 
100 class WS_PAINTER : public PAINTER
101 {
102 public:
103  WS_PAINTER( GAL* aGal ) :
104  PAINTER( aGal )
105  { }
106 
108  virtual bool Draw( const VIEW_ITEM*, int ) override;
109 
110  void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const;
111 
113  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
114  {
115  m_renderSettings = *static_cast<const WS_RENDER_SETTINGS*>( aSettings );
116  }
117 
119  virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; }
120 
121 private:
122  void draw( const WS_DRAW_ITEM_LINE* aItem, int aLayer ) const;
123  void draw( const WS_DRAW_ITEM_RECT* aItem, int aLayer ) const;
124  void draw( const WS_DRAW_ITEM_POLYPOLYGONS* aItem, int aLayer ) const;
125  void draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const;
126  void draw( const WS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const;
127  void draw( const WS_DRAW_ITEM_PAGE* aItem, int aLayer ) const;
128 
129 private:
131 };
132 
133 } // namespace KIGFX
134 
135 
154 void PrintPageLayout( RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
155  const wxString& aFullSheetName, const wxString& aFileName,
156  const TITLE_BLOCK& aTitleBlock, int aSheetCount, int aSheetNumber,
157  double aScalar, const PROJECT* aProject,
158  const wxString& aSheetLayer = wxEmptyString );
159 
160 #endif // WS_PAINTER_H
WS_RENDER_SETTINGS Stores page-layout-specific render settings.
Definition: ws_painter.h:47
void SetNormalColor(const COLOR4D &aColor)
Definition: ws_painter.h:68
double GetBrightness() const
Function GetBrightness Returns the brightness value of the color ranged from 0.0 to 1....
Definition: color4d.h:329
PROJECT holds project specific data.
Definition: project.h:61
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:130
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
bool IsBackgroundDark() const override
Definition: ws_painter.h:59
void SetPageBorderColor(const COLOR4D &aColor)
Definition: ws_painter.h:71
WS_PAINTER(GAL *aGal)
Definition: ws_painter.h:103
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: ws_painter.cpp:57
Definition: color4d.h:44
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
void PrintPageLayout(RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, int aSheetNumber, double aScalar, const PROJECT *aProject, const wxString &aSheetLayer=wxEmptyString)
Function PrintPageLayout is a core function to print the page layout with the frame and the basic ins...
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:58
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
Definition: ws_painter.h:79
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:355
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
void SetBackgroundColor(const COLOR4D &aColor) override
Sets the background color.
Definition: ws_painter.h:66
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:237
WS_PAINTER Contains methods for drawing worksheet items.
Definition: ws_painter.h:100
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:113
Definition: color4d.h:48
const COLOR4D & GetBackgroundColor() override
Function GetBackgroundColor Returns current background color settings.
Definition: ws_painter.h:65
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:71
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:73
void SetSelectedColor(const COLOR4D &aColor)
Definition: ws_painter.h:69
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetBrightenedColor(const COLOR4D &aColor)
Definition: ws_painter.h:70
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:218
virtual RENDER_SETTINGS * GetSettings() override
Definition: ws_painter.h:119
Class GAL is the abstract interface for drawing on a 2D-surface.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99