← Back to team overview

kicad-developers team mailing list archive

[PATCH] Move layer color settings from child class to base class RENDER_SETTINGS

 

Hi all,

This patch follows up on the one I sent earlier, to finish removing
dependency on pcbnew for the GAL draw panel.  Since layer color settings
will be useful in other applications, I moved them from PCB_RENDER_SETTINGS
up to RENDER_SETTINGS.  I left GetColor() in the pcb class for now, but if
I make progress on enabling GAL in GerbView it might become more obvious
how that should be refactored into the base class.

Best,
Jon
From 7122ee9236d230bdd49bb40cabca166b1b15347c Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Wed, 15 Feb 2017 22:26:03 -0500
Subject: [PATCH] Move layer colors from PCB_RENDER_SETTINGS to
 RENDER_SETTINGS

---
 common/draw_panel_gal.cpp |  6 ++----
 common/painter.cpp        |  8 ++++++++
 include/painter.h         | 36 ++++++++++++++++++++++++++++++++++++
 pcbnew/pcb_painter.cpp    | 14 --------------
 pcbnew/pcb_painter.h      | 39 ---------------------------------------
 5 files changed, 46 insertions(+), 57 deletions(-)

diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp
index e14181d..69002a6 100644
--- a/common/draw_panel_gal.cpp
+++ b/common/draw_panel_gal.cpp
@@ -30,7 +30,7 @@
 #include <class_draw_panel_gal.h>
 #include <view/view.h>
 #include <view/wx_view_controls.h>
-#include <pcb_painter.h>
+#include <painter.h>

 #include <gal/graphics_abstraction_layer.h>
 #include <gal/opengl/opengl_gal.h>
@@ -39,8 +39,6 @@
 #include <tool/tool_dispatcher.h>
 #include <tool/tool_manager.h>

-#include <pcbstruct.h>  // display options definition
-
 #ifdef PROFILE
 #include <profile.h>
 #endif /* PROFILE */
@@ -164,7 +162,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
     wxASSERT( m_painter );

     m_drawing = true;
-    KIGFX::PCB_RENDER_SETTINGS* settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_painter->GetSettings() );
+    KIGFX::RENDER_SETTINGS* settings = static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );

 // Scrollbars broken in GAL on OSX
 #ifndef __WXMAC__
diff --git a/common/painter.cpp b/common/painter.cpp
index 0d6b1f0..60d6614 100644
--- a/common/painter.cpp
+++ b/common/painter.cpp
@@ -62,6 +62,14 @@ void RENDER_SETTINGS::update()
 {
     m_hiContrastColor = COLOR4D( m_hiContrastFactor, m_hiContrastFactor, m_hiContrastFactor,
                                  m_layerOpacity );
+
+    // Calculate darkened/highlighted variants of layer colors
+    for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
+    {
+        m_layerColorsHi[i]   = m_layerColors[i].Brightened( m_highlightFactor );
+        m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
+        m_layerColorsSel[i]  = m_layerColors[i].Brightened( m_selectFactor );
+    }
 }


diff --git a/include/painter.h b/include/painter.h
index cf586fa..cf6cefc 100644
--- a/include/painter.h
+++ b/include/painter.h
@@ -33,6 +33,7 @@
 #include <gal/color4d.h>
 #include <colors.h>
 #include <worksheet_shape_builder.h>
+#include <layers_id_colors_and_visibility.h>
 #include <memory>

 class EDA_ITEM;
@@ -207,6 +208,29 @@ public:
         m_backgroundColor = aColor;
     }

+    /**
+     * Function GetLayerColor
+     * Returns the color used to draw a layer.
+     * @param aLayer is the layer number.
+     */
+    inline const COLOR4D& GetLayerColor( int aLayer ) const
+    {
+        return m_layerColors[aLayer];
+    }
+
+    /**
+     * Function SetLayerColor
+     * Changes the color used to draw a layer.
+     * @param aLayer is the layer number.
+     * @param aColor is the new color.
+     */
+    inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
+    {
+        m_layerColors[aLayer] = aColor;
+
+        update();       // recompute other shades of the color
+    }
+
 protected:
     /**
      * Function update
@@ -217,6 +241,18 @@ protected:

     std::set<unsigned int> m_activeLayers; ///< Stores active layers number

+    ///> Colors for all layers (normal)
+    COLOR4D m_layerColors[TOTAL_LAYER_COUNT];
+
+    ///> Colors for all layers (highlighted)
+    COLOR4D m_layerColorsHi[TOTAL_LAYER_COUNT];
+
+    ///> Colors for all layers (selected)
+    COLOR4D m_layerColorsSel[TOTAL_LAYER_COUNT];
+
+    ///> Colors for all layers (darkened)
+    COLOR4D m_layerColorsDark[TOTAL_LAYER_COUNT];
+
     /// Parameters for display modes
     bool    m_hiContrastEnabled;    ///< High contrast display mode on/off
     COLOR4D m_hiContrastColor;      ///< Color used for high contrast display mode
diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp
index 94bae89..2206052 100644
--- a/pcbnew/pcb_painter.cpp
+++ b/pcbnew/pcb_painter.cpp
@@ -225,20 +225,6 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer
 }


-void PCB_RENDER_SETTINGS::update()
-{
-    RENDER_SETTINGS::update();
-
-    // Calculate darkened/highlighted variants of layer colors
-    for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
-    {
-        m_layerColorsHi[i]   = m_layerColors[i].Brightened( m_highlightFactor );
-        m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
-        m_layerColorsSel[i]  = m_layerColors[i].Brightened( m_selectFactor );
-    }
-}
-
-
 PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
     PAINTER( aGal )
 {
diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h
index 718f619..25235fb 100644
--- a/pcbnew/pcb_painter.h
+++ b/pcbnew/pcb_painter.h
@@ -27,7 +27,6 @@
 #ifndef __CLASS_PCB_PAINTER_H
 #define __CLASS_PCB_PAINTER_H

-#include <layers_id_colors_and_visibility.h>
 #include <painter.h>

 #include <memory>
@@ -106,29 +105,6 @@ public:
     virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;

     /**
-     * Function GetLayerColor
-     * Returns the color used to draw a layer.
-     * @param aLayer is the layer number.
-     */
-    inline const COLOR4D& GetLayerColor( int aLayer ) const
-    {
-        return m_layerColors[aLayer];
-    }
-
-    /**
-     * Function SetLayerColor
-     * Changes the color used to draw a layer.
-     * @param aLayer is the layer number.
-     * @param aColor is the new color.
-     */
-    inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
-    {
-        m_layerColors[aLayer] = aColor;
-
-        update();       // recompute other shades of the color
-    }
-
-    /**
      * Function SetSketchMode
      * Turns on/off sketch mode for given item layer.
      * @param aItemLayer is the item layer that is changed.
@@ -151,21 +127,6 @@ public:
     }

 protected:
-    ///> @copydoc RENDER_SETTINGS::Update()
-    void update() override;
-
-    ///> Colors for all layers (normal)
-    COLOR4D m_layerColors[TOTAL_LAYER_COUNT];
-
-    ///> Colors for all layers (highlighted)
-    COLOR4D m_layerColorsHi[TOTAL_LAYER_COUNT];
-
-    ///> Colors for all layers (selected)
-    COLOR4D m_layerColorsSel[TOTAL_LAYER_COUNT];
-
-    ///> Colors for all layers (darkened)
-    COLOR4D m_layerColorsDark[TOTAL_LAYER_COUNT];
-
     ///> Flag determining if items on a given layer should be drawn as an outline or a filled item
     bool    m_sketchMode[TOTAL_LAYER_COUNT];

--
2.7.4


Follow ups