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-2020 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>
33 
34 // Forward declarations:
35 class EDA_RECT;
36 class TITLE_BLOCK;
37 
38 using KIGFX::COLOR4D;
39 
40 namespace KIGFX
41 {
42 
47 {
48 public:
49  friend class WS_PAINTER;
50 
52 
53  void LoadColors( const COLOR_SETTINGS* aSettings ) override;
54 
56  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
57 
58  inline bool IsBackgroundDark() const override
59  {
60  auto luma = m_backgroundColor.GetBrightness();
61  return luma < 0.5;
62  }
63 
64  const COLOR4D& GetBackgroundColor() override { return m_backgroundColor; }
65  void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; }
66 
67  void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; }
68  void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; }
69  void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; }
70  void SetPageBorderColor( const COLOR4D& aColor ) { m_pageBorderColor = aColor; }
71 
72  const COLOR4D& GetGridColor() override
73  {
75  return m_gridColor;
76  }
77 
78  const COLOR4D& GetCursorColor() override
79  {
81  return m_cursorColor;
82  }
83 
84 private:
88 
92 };
93 
94 
98 class WS_PAINTER : public PAINTER
99 {
100 public:
101  WS_PAINTER( GAL* aGal ) :
102  PAINTER( aGal )
103  { }
104 
106  virtual bool Draw( const VIEW_ITEM*, int ) override;
107 
108  void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const;
109 
111  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
112  {
113  m_renderSettings = *static_cast<const WS_RENDER_SETTINGS*>( aSettings );
114  }
115 
117  virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; }
118 
119 private:
120  void draw( const WS_DRAW_ITEM_LINE* aItem, int aLayer ) const;
121  void draw( const WS_DRAW_ITEM_RECT* aItem, int aLayer ) const;
122  void draw( const WS_DRAW_ITEM_POLYPOLYGONS* aItem, int aLayer ) const;
123  void draw( const WS_DRAW_ITEM_TEXT* aItem, int aLayer ) const;
124  void draw( const WS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const;
125  void draw( const WS_DRAW_ITEM_PAGE* aItem, int aLayer ) const;
126 
127 private:
129 };
130 
131 } // namespace KIGFX
132 
133 
153 void PrintPageLayout( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
154  const wxString& aFullSheetName, const wxString& aFileName,
155  const TITLE_BLOCK& aTitleBlock, int aSheetCount, const wxString& aPageNumber,
156  double aScalar, const PROJECT* aProject,
157  const wxString& aSheetLayer = wxEmptyString, bool aIsFirstPage = true );
158 
159 #endif // WS_PAINTER_H
Store page-layout-specific render settings.
Definition: ws_painter.h:46
A rectangle with thick segment showing the page limits and a marker showing the coordinate origin.
Definition: ws_draw_item.h:252
void SetNormalColor(const COLOR4D &aColor)
Definition: ws_painter.h:67
void PrintPageLayout(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, const wxString &aPageNumber, double aScalar, const PROJECT *aProject, const wxString &aSheetLayer=wxEmptyString, bool aIsFirstPage=true)
Print the border and title block.
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:322
Container for project specific data.
Definition: project.h:62
WS_RENDER_SETTINGS m_renderSettings
Definition: ws_painter.h:128
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool IsBackgroundDark() const override
Definition: ws_painter.h:58
void SetPageBorderColor(const COLOR4D &aColor)
Definition: ws_painter.h:70
WS_PAINTER(GAL *aGal)
Definition: ws_painter.h:101
Non filled rectangle with thick segment.
Definition: ws_draw_item.h:205
void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: ws_painter.cpp:56
Definition: color4d.h:44
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
Definition: ws_painter.h:78
void DrawBorder(const PAGE_INFO *aPageInfo, int aScaleFactor) const
Definition: ws_painter.cpp:325
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
Definition: ws_painter.h:65
void draw(const WS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ws_painter.cpp:207
Methods for drawing worksheet items.
Definition: ws_painter.h:98
virtual void ApplySettings(const RENDER_SETTINGS *aSettings) override
Loads colors and display modes settings that are going to be used when drawing items.
Definition: ws_painter.h:111
Definition: color4d.h:48
const COLOR4D & GetBackgroundColor() override
Return current background color settings.
Definition: ws_painter.h:64
Handle the component boundary box.
Definition: eda_rect.h:42
const COLOR4D & GetGridColor() override
Return current grid color settings.
Definition: ws_painter.h:72
void SetSelectedColor(const COLOR4D &aColor)
Definition: ws_painter.h:68
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
Definition: ws_painter.cpp:70
Color settings are a bit different than most of the settings objects in that there can be more than o...
A graphic text.
Definition: ws_draw_item.h:297
void SetBrightenedColor(const COLOR4D &aColor)
Definition: ws_painter.h:69
virtual bool Draw(const VIEW_ITEM *, int) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
Definition: ws_painter.cpp:185
virtual RENDER_SETTINGS * GetSettings() override
Definition: ws_painter.h:117
Abstract interface for drawing on a 2D-surface.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98