← Back to team overview

kicad-developers team mailing list archive

[PATCH] Use the main workspace background in component chooser/browser dialogues

 

Hi,

Here is a small patch to make the component chooser dialogue and the
library browser dialogue use the main workspace background colour (white
or black, as configured) instead of white, which otherwise looks
inconsistent when the main workspace is black.

Because DIALOG_CHOOSE_COMPONENT and LIB_VIEW_FRAME both take wxWindow*
as the parents, you can't get directly to the EDA_DRAW_FRAME*. I have
gone around this with a dynamic_cast.

An alternative would be to do what DIALOG_LIB_EDIT_PIN does and take an
EDA_DRAW_FRAME* in the constructor, but pass a wxWindow* down to the
base class. Then, in the constructor, you can access the EDA_DRAW_FRAME
(and in this case, we'd have to save some state, perhaps a bool or
EDA_COLOR_T?)

Additionally, I have removed the saving and loading of the
LIBVIEW_BGCOLOR config. If it still makes sense to have the library
browser have a background colour independent of the parent, then maybe
the colour could be assigned by the first of these to be found:

  * Explicit config
  * Parent
  * White (hardcoded)

I think this logic would be a little complex if this config is not
actively useful.

John
diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp
index 383f7fa..a518f6e 100644
--- a/eeschema/dialogs/dialog_choose_component.cpp
+++ b/eeschema/dialogs/dialog_choose_component.cpp
@@ -260,7 +260,14 @@ void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEven
 void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART*      aComponent, int aUnit )
 {
     wxPaintDC dc( m_componentView );
-    dc.SetBackground( *wxWHITE_BRUSH );
+
+    bool white_bg = true;
+
+    // Attempt to re-use the colour from the parent EDA_DRAW_FRAME
+    if ( EDA_DRAW_FRAME* parent_frame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent ) )
+        white_bg = parent_frame->GetDrawBgColor() == WHITE;
+
+    dc.SetBackground( white_bg ? *wxWHITE_BRUSH : *wxBLACK_BRUSH );
     dc.Clear();
 
     if( aComponent == NULL )
diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp
index 0596d19..b3bf798 100644
--- a/eeschema/viewlib_frame.cpp
+++ b/eeschema/viewlib_frame.cpp
@@ -497,19 +497,19 @@ void LIB_VIEW_FRAME::ExportToSchematicLibraryPart( wxCommandEvent& event )
 #define LIBLIST_WIDTH_KEY wxT( "ViewLiblistWidth" )
 #define CMPLIST_WIDTH_KEY wxT( "ViewCmplistWidth" )
 
-// Currently, the library viewer has no dialog to change the background color
-// of the draw canvas. Therefore the background color is here just
-// in case of this option is added to some library viewer config dialog
-#define LIBVIEW_BGCOLOR   wxT( "LibviewBgColor" )
-
-
 void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
 {
     EDA_DRAW_FRAME::LoadSettings( aCfg );
 
     wxConfigPathChanger cpc( aCfg, m_configPath );
 
-    EDA_COLOR_T itmp = ColorByName( aCfg->Read( LIBVIEW_BGCOLOR, wxT( "WHITE" ) ) );
+    bool white_bg = true;
+
+    // Attempt to re-use the colour from the parent EDA_DRAW_FRAME
+    if ( EDA_DRAW_FRAME* parent_frame = dynamic_cast<EDA_DRAW_FRAME*>( m_parent ) )
+        white_bg = parent_frame->GetDrawBgColor() == WHITE;
+
+    EDA_COLOR_T itmp = ColorByName( white_bg ? wxT( "WHITE" ) : wxT( "BLACK" ) );
     SetDrawBgColor( itmp );
 
     aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 100 );
@@ -538,7 +538,6 @@ void LIB_VIEW_FRAME::SaveSettings( wxConfigBase* aCfg )
 
     m_cmpListWidth = m_cmpList->GetSize().x;
     aCfg->Write( CMPLIST_WIDTH_KEY, m_cmpListWidth );
-    aCfg->Write( LIBVIEW_BGCOLOR, ColorGetName( GetDrawBgColor() ) );
 }