From 6aad8d43ae0f029b12c766f1a4a69b26c15e1607 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@craftyjon.com>
Date: Sat, 18 Feb 2017 15:21:09 -0500
Subject: [PATCH 2/2] Revert from wxColourPickerCtrl to wxBitmapButton

wxColourPickerCtrl apparently looks bad on Windows 10
---
 eeschema/widgets/widget_eeschema_color_config.cpp | 97 ++++++++++++++++-------
 1 file changed, 68 insertions(+), 29 deletions(-)

diff --git a/eeschema/widgets/widget_eeschema_color_config.cpp b/eeschema/widgets/widget_eeschema_color_config.cpp
index 11e148e..e7519d7 100644
--- a/eeschema/widgets/widget_eeschema_color_config.cpp
+++ b/eeschema/widgets/widget_eeschema_color_config.cpp
@@ -104,6 +104,7 @@ static BUTTONINDEX buttonGroups[] = {
     { wxT( "" ), NULL }
 };
 
+static COLORBUTTON bgColorButton = { _( "" ), LAYER_BACKGROUND };
 
 static COLOR4D currentColors[ LAYERSCH_ID_COUNT ];
 
@@ -153,13 +154,24 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
             COLOR4D color = GetLayerColor( LAYERSCH_ID( buttons->m_Layer ) );
             currentColors[ buttons->m_Layer ] = color;
 
-            wxColourPickerCtrl* colourPicker = new wxColourPickerCtrl(
-                                    this, buttonId, color.ToColour(), wxDefaultPosition,
-                                    wxSize( BUTT_SIZE_X+20, BUTT_SIZE_Y+20 ) );
+            wxMemoryDC iconDC;
+            wxBitmap   bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
 
-            colourPicker->SetClientData( (void*) buttons );
+            iconDC.SelectObject( bitmap );
+            iconDC.SetPen( *wxBLACK_PEN );
 
-            rowBoxSizer->Add( colourPicker, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
+            wxBrush brush;
+            brush.SetColour( color.ToColour() );
+            brush.SetStyle( wxBRUSHSTYLE_SOLID );
+            iconDC.SetBrush( brush );
+            iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
+
+            wxBitmapButton* bitmapButton = new wxBitmapButton(
+                                    this, buttonId, bitmap, wxDefaultPosition,
+                                    wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) );
+            bitmapButton->SetClientData( (void*) buttons );
+
+            rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
 
             label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
             rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
@@ -170,22 +182,27 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
         groups++;
     }
 
-    Connect( 1800, buttonId - 1, wxEVT_COLOURPICKER_CHANGED,
-             wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
+    COLOR4D bgColor = GetDrawFrame()->GetDrawBgColor();
+    wxMemoryDC iconDC;
+    wxBitmap   bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
 
-    /*wxArrayString selBgColorStrings;
-    selBgColorStrings.Add( _( "White" ) );
-    selBgColorStrings.Add( _( "Black" ) );
-    m_SelBgColor = new wxRadioBox( this, wxID_ANY, _( "Background Color" ),
-                                   wxDefaultPosition, wxDefaultSize,
-                                   selBgColorStrings, 1, wxRA_SPECIFY_COLS );
-    m_SelBgColor->SetSelection( ( GetDrawFrame()->GetDrawBgColor() == BLACK ) ? 1 : 0 );
-    */
+    iconDC.SelectObject( bitmap );
+    iconDC.SetPen( *wxBLACK_PEN );
 
-    COLOR4D bgColor = GetDrawFrame()->GetDrawBgColor();
-    m_SelBgColor = new wxColourPickerCtrl(
-                        this, buttonId, bgColor.ToColour(), wxDefaultPosition,
-                        wxSize( BUTT_SIZE_X+20, BUTT_SIZE_Y+20 ) );
+    wxBrush brush;
+    brush.SetColour( bgColor.ToColour() );
+    brush.SetStyle( wxBRUSHSTYLE_SOLID );
+    iconDC.SetBrush( brush );
+    iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
+
+    buttonId++;
+    wxBitmapButton* m_SelBgColor = new wxBitmapButton(
+                            this, buttonId, bitmap, wxDefaultPosition,
+                            wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) );
+    m_SelBgColor->SetClientData( (void*) &bgColorButton );
+
+    Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED,
+             wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
 
     wxStaticText* bgColorLabel = new wxStaticText( this, wxID_ANY, _( "Background Color" ) );
     wxFont font( bgColorLabel->GetFont() );
@@ -200,8 +217,7 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
         columnBoxSizer->Add( m_SelBgColor, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
     }
 
-    // TODO(jon) fix currentColors
-    //currentColors[ LAYER_BACKGROUND ] =  GetDrawFrame()->GetDrawBgColor();
+    currentColors[ LAYER_BACKGROUND ] = bgColor;
 
     // Dialog now needs to be resized, but the associated command is found elsewhere.
 }
@@ -209,21 +225,44 @@ void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls()
 
 void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor( wxCommandEvent& event )
 {
-    wxColourPickerCtrl* picker = (wxColourPickerCtrl*) event.GetEventObject();
+    wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
 
-    wxCHECK_RET( picker != NULL, wxT( "Color picker event object is NULL." ) );
+    wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
 
-    COLORBUTTON* colorButton = (COLORBUTTON*) picker->GetClientData();
+    COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
 
     wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
 
-    // DisplayColorFrame( this, currentColors[colorButton->m_Layer] );
-    COLOR4D color = COLOR4D( picker->GetColour() );
+    wxColourData colourData;
+    colourData.SetColour( currentColors[ colorButton->m_Layer ].ToColour() );
+    wxColourDialog *dialog = new wxColourDialog( this, &colourData );
 
-    if( color == UNSPECIFIED_COLOR4D || currentColors[ colorButton->m_Layer ] == color )
+    COLOR4D newColor = UNSPECIFIED_COLOR4D;
+
+    if( dialog->ShowModal() == wxID_OK )
+    {
+        newColor = COLOR4D( dialog->GetColourData().GetColour() );
+    }
+
+    if( newColor == UNSPECIFIED_COLOR4D || currentColors[ colorButton->m_Layer ] == newColor )
         return;
 
-    currentColors[ colorButton->m_Layer ] = color;
+    currentColors[ colorButton->m_Layer ] = newColor;
+
+    wxMemoryDC iconDC;
+
+    wxBitmap bitmap = button->GetBitmapLabel();
+    iconDC.SelectObject( bitmap );
+    iconDC.SetPen( *wxBLACK_PEN );
+
+    wxBrush  brush;
+    brush.SetColour( newColor.ToColour() );
+    brush.SetStyle( wxBRUSHSTYLE_SOLID );
+
+    iconDC.SetBrush( brush );
+    iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
+    button->SetBitmapLabel( bitmap );
+    button->Refresh();
 
     Refresh( false );
 }
@@ -236,7 +275,7 @@ bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl()
     // Check for color conflicts with background color to give user a chance to bail
     // out before making changes.
 
-    COLOR4D bgcolor = m_SelBgColor->GetColour();
+    COLOR4D bgcolor = currentColors[ LAYER_BACKGROUND ];
 
     for( LAYERSCH_ID clyr = LAYER_WIRE; clyr < LAYERSCH_ID_COUNT; ++clyr )
     {
-- 
2.8.2.windows.1

