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.

303 lines
9.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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. #ifndef RENDER_SETTINGS_H
  24. #define RENDER_SETTINGS_H
  25. #include <map>
  26. #include <set>
  27. #include <gal/color4d.h>
  28. #include <layers_id_colors_and_visibility.h>
  29. #include <memory>
  30. #include <wx/dc.h>
  31. class COLOR_SETTINGS;
  32. namespace KIGFX
  33. {
  34. class VIEW_ITEM;
  35. /**
  36. * RENDER_SETTINGS
  37. * Contains all the knowledge about how graphical objects are drawn on any output
  38. * surface/device. This includes:
  39. * - color/transparency settings
  40. * - highlighting and high contrast mode control
  41. * - drawing quality control (sketch/outline mode)
  42. * - text processing flags
  43. * The class acts as an interface between the PAINTER object and the GUI (i.e. Layers/Items
  44. * widget or display options dialog).
  45. */
  46. class RENDER_SETTINGS
  47. {
  48. public:
  49. RENDER_SETTINGS();
  50. virtual ~RENDER_SETTINGS();
  51. virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
  52. /**
  53. * Function SetLayerIsHighContrast
  54. * Sets the specified layer as high-contrast.
  55. * @param aLayerId is a layer number that should be displayed in a specific mode.
  56. * @param aEnabled is the new layer state ( true = active or false = not active).
  57. */
  58. inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
  59. {
  60. if( aEnabled )
  61. m_highContrastLayers.insert( aLayerId );
  62. else
  63. m_highContrastLayers.erase( aLayerId );
  64. }
  65. /**
  66. * Function GetLayerIsHighContrast
  67. * Returns information whether the queried layer is marked as high-contrast.
  68. * @return True if the queried layer is marked as active.
  69. */
  70. inline bool GetLayerIsHighContrast( int aLayerId ) const
  71. {
  72. return ( m_highContrastLayers.count( aLayerId ) > 0 );
  73. }
  74. /**
  75. * Function GetHighContrastLayers()
  76. * Returns the set of currently high-contrast layers.
  77. */
  78. const std::set<unsigned int> GetHighContrastLayers() const
  79. {
  80. return m_highContrastLayers;
  81. }
  82. /**
  83. * Returns the board layer which is in high-contrast. There should only be one
  84. * board layer which is high-contrast at any given time, although there might be
  85. * many high-contrast synthetic (GAL) layers.
  86. */
  87. PCB_LAYER_ID GetPrimaryHighContrastLayer() const
  88. {
  89. for( int layer : m_highContrastLayers )
  90. {
  91. if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
  92. return (PCB_LAYER_ID) layer;
  93. }
  94. return UNDEFINED_LAYER;
  95. }
  96. PCB_LAYER_ID GetActiveLayer() const { return m_activeLayer; }
  97. void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
  98. /**
  99. * Function ClearHighContrastLayers
  100. * Clears the list of active layers.
  101. */
  102. inline void ClearHighContrastLayers()
  103. {
  104. m_highContrastLayers.clear();
  105. }
  106. /**
  107. * Function IsHighlightEnabled
  108. * Returns current highlight setting.
  109. * @return True if highlight is enabled, false otherwise.
  110. */
  111. inline bool IsHighlightEnabled() const
  112. {
  113. return m_highlightEnabled;
  114. }
  115. /**
  116. * Function GetHighlightNetCode
  117. * Returns netcode of currently highlighted net.
  118. * @return Netcode of currently highlighted net.
  119. */
  120. inline const std::set<int>& GetHighlightNetCodes() const
  121. {
  122. return m_highlightNetcodes;
  123. }
  124. /**
  125. * Function SetHighlight
  126. * Turns on/off highlighting - it may be done for the active layer or the specified net(s).
  127. * @param aEnabled tells if highlighting should be enabled.
  128. * @param aNetcode is optional and if specified, turns on higlighting only for the net with
  129. * number given as the parameter.
  130. */
  131. inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
  132. {
  133. m_highlightEnabled = aEnabled;
  134. if( aEnabled )
  135. {
  136. if( !aMulti )
  137. m_highlightNetcodes.clear();
  138. m_highlightNetcodes.insert( aNetcode );
  139. }
  140. else
  141. m_highlightNetcodes.clear();
  142. }
  143. /**
  144. * Function SetHighContrast
  145. * Turns on/off high contrast display mode.
  146. */
  147. void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
  148. bool GetHighContrast() const { return m_hiContrastEnabled; }
  149. /**
  150. * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer
  151. * using currently used render settings.
  152. * @param aItem is the VIEW_ITEM.
  153. * @param aLayer is the layer.
  154. * @return The color.
  155. */
  156. virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
  157. float GetWorksheetLineWidth() const { return m_worksheetLineWidth; }
  158. int GetDefaultPenWidth() const { return m_defaultPenWidth; }
  159. void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
  160. int GetMinPenWidth() const { return m_minPenWidth; }
  161. void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
  162. bool GetShowPageLimits() const { return m_showPageLimits; }
  163. void SetShowPageLimits( bool aDraw ) { m_showPageLimits = aDraw; }
  164. /**
  165. * Function GetBackgroundColor
  166. * Returns current background color settings.
  167. */
  168. virtual const COLOR4D& GetBackgroundColor() = 0;
  169. /**
  170. * Sets the background color.
  171. */
  172. virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
  173. /**
  174. * Function GetGridColor
  175. * Returns current grid color settings.
  176. */
  177. virtual const COLOR4D& GetGridColor() = 0;
  178. /**
  179. * Function GetCursorColor
  180. * Returns current cursor color settings.
  181. */
  182. virtual const COLOR4D& GetCursorColor() = 0;
  183. /**
  184. * Function GetLayerColor
  185. * Returns the color used to draw a layer.
  186. * @param aLayer is the layer number.
  187. */
  188. inline const COLOR4D& GetLayerColor( int aLayer ) const
  189. {
  190. return m_layerColors[aLayer];
  191. }
  192. /**
  193. * Function SetLayerColor
  194. * Changes the color used to draw a layer.
  195. * @param aLayer is the layer number.
  196. * @param aColor is the new color.
  197. */
  198. inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
  199. {
  200. m_layerColors[aLayer] = aColor;
  201. update(); // recompute other shades of the color
  202. }
  203. virtual bool IsBackgroundDark() const
  204. {
  205. return false;
  206. }
  207. /**
  208. * Set line width used for drawing outlines.
  209. *
  210. * @param aWidth is the new width.
  211. */
  212. void SetOutlineWidth( float aWidth )
  213. {
  214. m_outlineWidth = aWidth;
  215. }
  216. void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
  217. void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
  218. void SetHighContrastFactor( float aFactor ) { m_hiContrastFactor = aFactor; }
  219. // TODO: these can go away once the worksheet is moved to Cairo-based printing
  220. wxDC* GetPrintDC() { return m_printDC; }
  221. void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
  222. protected:
  223. /**
  224. * Function update
  225. * Precalculates extra colors for layers (e.g. highlighted, darkened and any needed version
  226. * of base colors).
  227. */
  228. virtual void update();
  229. PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
  230. std::set<unsigned int> m_highContrastLayers; // High-contrast layers (both board layers and
  231. // synthetic GAL layers)
  232. COLOR4D m_layerColors[LAYER_ID_COUNT]; // Layer colors
  233. COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
  234. COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
  235. COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
  236. COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
  237. COLOR4D m_backgroundColor; // The background color
  238. /// Parameters for display modes
  239. bool m_hiContrastEnabled; // High contrast display mode on/off
  240. float m_hiContrastFactor; // Factor used for computing high contrast color
  241. bool m_highlightEnabled; // Highlight display mode on/off
  242. std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
  243. float m_highlightFactor; // Factor used for computing highlight color
  244. float m_selectFactor; // Specifies how color of selected items is changed
  245. float m_outlineWidth; // Line width used when drawing outlines
  246. float m_worksheetLineWidth; // Line width used when drawing worksheet
  247. int m_defaultPenWidth;
  248. int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
  249. // lines. This sets an absolute minimum.
  250. bool m_showPageLimits;
  251. wxDC* m_printDC; // This can go away once the worksheet is moved to
  252. // Cairo-based printing.
  253. };
  254. }
  255. #endif /* RENDER_SETTINGS_H */