You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
5.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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. // For page and paper size, values are in 1/1000 inch
  24. #ifndef DS_PAINTER_H
  25. #define DS_PAINTER_H
  26. #include <gal/color4d.h>
  27. #include <gal/painter.h>
  28. #include <page_info.h>
  29. #include <drawing_sheet/ds_draw_item.h>
  30. // Forward declarations:
  31. class TITLE_BLOCK;
  32. using KIGFX::COLOR4D;
  33. namespace KIGFX
  34. {
  35. /**
  36. * Store page-layout-specific render settings.
  37. */
  38. class DS_RENDER_SETTINGS : public RENDER_SETTINGS
  39. {
  40. public:
  41. friend class DS_PAINTER;
  42. DS_RENDER_SETTINGS();
  43. void LoadColors( const COLOR_SETTINGS* aSettings ) override;
  44. /// @copydoc RENDER_SETTINGS::GetColor()
  45. virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
  46. inline bool IsBackgroundDark() const override
  47. {
  48. auto luma = m_backgroundColor.GetBrightness();
  49. return luma < 0.5;
  50. }
  51. const COLOR4D& GetBackgroundColor() const override { return m_backgroundColor; }
  52. void SetBackgroundColor( const COLOR4D& aColor ) override { m_backgroundColor = aColor; }
  53. void SetNormalColor( const COLOR4D& aColor ) { m_normalColor = aColor; }
  54. void SetSelectedColor( const COLOR4D& aColor ) { m_selectedColor = aColor; }
  55. void SetBrightenedColor( const COLOR4D& aColor ) { m_brightenedColor = aColor; }
  56. void SetPageBorderColor( const COLOR4D& aColor ) { m_pageBorderColor = aColor; }
  57. const COLOR4D& GetGridColor() override
  58. {
  59. m_gridColor = IsBackgroundDark() ? DARKGRAY : LIGHTGRAY;
  60. return m_gridColor;
  61. }
  62. const COLOR4D& GetCursorColor() override
  63. {
  64. m_cursorColor = IsBackgroundDark() ? WHITE : BLACK;
  65. return m_cursorColor;
  66. }
  67. private:
  68. COLOR4D m_normalColor;
  69. COLOR4D m_selectedColor;
  70. COLOR4D m_brightenedColor;
  71. COLOR4D m_gridColor;
  72. COLOR4D m_cursorColor;
  73. COLOR4D m_pageBorderColor;
  74. };
  75. /**
  76. * Methods for painting drawing sheet items.
  77. */
  78. class DS_PAINTER : public PAINTER
  79. {
  80. public:
  81. DS_PAINTER( GAL* aGal ) :
  82. PAINTER( aGal )
  83. { }
  84. /// @copydoc PAINTER::Draw()
  85. virtual bool Draw( const VIEW_ITEM*, int ) override;
  86. void DrawBorder( const PAGE_INFO* aPageInfo, int aScaleFactor ) const;
  87. /// @copydoc PAINTER::GetSettings()
  88. virtual RENDER_SETTINGS* GetSettings() override { return &m_renderSettings; }
  89. private:
  90. void draw( const DS_DRAW_ITEM_LINE* aItem, int aLayer ) const;
  91. void draw( const DS_DRAW_ITEM_RECT* aItem, int aLayer ) const;
  92. void draw( const DS_DRAW_ITEM_POLYPOLYGONS* aItem, int aLayer ) const;
  93. void draw( const DS_DRAW_ITEM_TEXT* aItem, int aLayer ) const;
  94. void draw( const DS_DRAW_ITEM_BITMAP* aItem, int aLayer ) const;
  95. void draw( const DS_DRAW_ITEM_PAGE* aItem, int aLayer ) const;
  96. private:
  97. DS_RENDER_SETTINGS m_renderSettings;
  98. };
  99. } // namespace KIGFX
  100. /**
  101. * Print the border and title block.
  102. *
  103. * @param aDC The device context.
  104. * @param aPageInfo for margins and page size (in mils).
  105. * @param aSheetName The sheet name, for basic inscriptions.
  106. * @param aSheetPath The sheetpath (full sheet name), for basic inscriptions.
  107. * @param aFileName The file name, for basic inscriptions.
  108. * @param aTitleBlock The sheet title block, for text variable resolution.
  109. * @param aProperties Optional properties for text variable resolution.
  110. * @param aSheetCount The number of sheets (for text variable resolution).
  111. * @param aPageNumber The page number.
  112. * @param aScalar the scale factor to convert from mils to internal units.
  113. * @param aSheetLayer The layer from Pcbnew.
  114. * @param aIsFirstPage True when this is the first page. This only has meaning for schematics.
  115. *
  116. * Parameters used in aPageInfo
  117. * - the size of the drawing sheet.
  118. * - the LTmargin The left top margin of the drawing sheet.
  119. * - the RBmargin The right bottom margin of the drawing sheet.
  120. */
  121. void PrintDrawingSheet( const RENDER_SETTINGS* aSettings, const PAGE_INFO& aPageInfo,
  122. const wxString& aSheetName, const wxString& aSheetPath,
  123. const wxString& aFileName, const TITLE_BLOCK& aTitleBlock,
  124. const std::map<wxString, wxString>* aProperties, int aSheetCount,
  125. const wxString& aPageNumber, double aScalar, const PROJECT* aProject,
  126. const wxString& aSheetLayer = wxEmptyString, bool aIsFirstPage = true );
  127. #endif // DS_PAINTER_H