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 DS_PAINTER_H 27 #define DS_PAINTER_H 28 29 #include <gal/color4d.h> 30 #include <painter.h> 31 #include <page_info.h> 32 #include <drawing_sheet/ds_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 43 /** 44 * Store page-layout-specific render settings. 45 */ 46 class DS_RENDER_SETTINGS : public RENDER_SETTINGS 47 { 48 public: 49 friend class DS_PAINTER; 50 51 DS_RENDER_SETTINGS(); 52 53 void LoadColors( const COLOR_SETTINGS* aSettings ) override; 54 55 /// @copydoc RENDER_SETTINGS::GetColor() 56 virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override; 57 IsBackgroundDark()58 inline bool IsBackgroundDark() const override 59 { 60 auto luma = m_backgroundColor.GetBrightness(); 61 return luma < 0.5; 62 } 63 GetBackgroundColor()64 const COLOR4D& GetBackgroundColor() override { return m_backgroundColor; } SetBackgroundColor(const COLOR4D & aColor)65 void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; } 66 SetNormalColor(const COLOR4D & aColor)67 void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; } SetSelectedColor(const COLOR4D & aColor)68 void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; } SetBrightenedColor(const COLOR4D & aColor)69 void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; } SetPageBorderColor(const COLOR4D & aColor)70 void SetPageBorderColor( const COLOR4D& aColor ) { m_pageBorderColor = aColor; } 71 GetGridColor()72 const COLOR4D& GetGridColor() override 73 { 74 m_gridColor = IsBackgroundDark() ? DARKGRAY : LIGHTGRAY; 75 return m_gridColor; 76 } 77 GetCursorColor()78 const COLOR4D& GetCursorColor() override 79 { 80 m_cursorColor = IsBackgroundDark() ? WHITE : BLACK; 81 return m_cursorColor; 82 } 83 84 private: 85 COLOR4D m_normalColor; 86 COLOR4D m_selectedColor; 87 COLOR4D m_brightenedColor; 88 89 COLOR4D m_gridColor; 90 COLOR4D m_cursorColor; 91 COLOR4D m_pageBorderColor; 92 }; 93 94 95 /** 96 * Methods for painting drawing sheet items. 97 */ 98 class DS_PAINTER : public PAINTER 99 { 100 public: DS_PAINTER(GAL * aGal)101 DS_PAINTER( GAL* aGal ) : 102 PAINTER( aGal ) 103 { } 104 105 /// @copydoc PAINTER::Draw() 106 virtual bool Draw( const VIEW_ITEM*, int ) override; 107 108 void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const; 109 110 /// @copydoc PAINTER::GetSettings() GetSettings()111 virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; } 112 113 private: 114 void draw( const DS_DRAW_ITEM_LINE* aItem, int aLayer ) const; 115 void draw( const DS_DRAW_ITEM_RECT* aItem, int aLayer ) const; 116 void draw( const DS_DRAW_ITEM_POLYPOLYGONS* aItem, int aLayer ) const; 117 void draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const; 118 void draw( const DS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const; 119 void draw( const DS_DRAW_ITEM_PAGE* aItem, int aLayer ) const; 120 121 private: 122 DS_RENDER_SETTINGS m_renderSettings; 123 }; 124 125 } // namespace KIGFX 126 127 128 /** 129 * Print the border and title block. 130 * 131 * @param aDC The device context. 132 * @param aPageInfo for margins and page size (in mils). 133 * @param aFullSheetName The sheetpath (full sheet name), for basic inscriptions. 134 * @param aFileName The file name, for basic inscriptions. 135 * @param aTitleBlock The sheet title block, for basic inscriptions. 136 * @param aSheetCount The number of sheets (for basic inscriptions). 137 * @param aPageNumber The page number. 138 * @param aScalar the scale factor to convert from mils to internal units. 139 * @param aSheetLayer The layer from Pcbnew. 140 * @param aIsFirstPage True when this is the first page. This only has meaning for schematics. 141 * 142 * Parameters used in aPageInfo 143 * - the size of the drawing sheet. 144 * - the LTmargin The left top margin of the drawing sheet. 145 * - the RBmargin The right bottom margin of the drawing sheet. 146 */ 147 void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo, 148 const wxString& aFullSheetName, const wxString& aFileName, 149 const TITLE_BLOCK& aTitleBlock, int aSheetCount, 150 const wxString& aPageNumber, double aScalar, const PROJECT* aProject, 151 const wxString& aSheetLayer = wxEmptyString, bool aIsFirstPage = true ); 152 153 #endif // DS_PAINTER_H 154