diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index cab9d70398..c96ff33ba3 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -561,7 +561,10 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR { if( aColorName.StartsWith( "#" ) ) { - return KIGFX::COLOR4D( wxColour( aColorName ) ); + /// Keep only the non-alpha channels of the color string, + /// i.e. first 6 hex digits and the '#' + + return KIGFX::COLOR4D( aColorName ); } else { diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index c9980ecc64..2ce99a1fab 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -110,6 +110,13 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor ) #ifdef WX_COMPATIBILITY +COLOR4D::COLOR4D( const wxString& aColorStr ) +{ + if( !SetFromHexString( aColorStr ) ) + SetFromWxString( aColorStr ); +} + + COLOR4D::COLOR4D( const wxColour& aColor ) { r = aColor.Red() / 255.0; diff --git a/include/gal/color4d.h b/include/gal/color4d.h index e5cad3bcb3..7d91ad77a4 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -146,6 +146,13 @@ public: COLOR4D& FromCSSRGBA( int aRed, int aGreen, int aBlue, double aAlpha = 1.0 ); #ifdef WX_COMPATIBILITY + + /** + * Defines a color from a CSS or HTML-type string + * @param aColorStr input string + */ + COLOR4D( const wxString& aColorStr ); + /** * @param aColor is the color type used by wxWidgets. */ diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp index 024d75015e..89aafaa92a 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp @@ -545,7 +545,7 @@ void PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard( bool aFullSync ) if( item->GetColor().StartsWith( "#" ) ) // User defined color { - ui_row_item.m_UserColor = wxColour( item->GetColor() ); + ui_row_item.m_UserColor = COLOR4D( item->GetColor() ).ToColour(); if( bm_combo ) // Update user color shown in the wxBitmapComboBox { @@ -799,7 +799,9 @@ BOARD_STACKUP_ROW_UI_ITEM PANEL_SETUP_BOARD_STACKUP::createRowData( int aRow, if( item->IsColorEditable() ) { if( item->GetColor().StartsWith( "#" ) ) // User defined color - ui_row_item.m_UserColor = wxColour( item->GetColor() ); + { + ui_row_item.m_UserColor = COLOR4D( item->GetColor() ).ToColour(); + } else ui_row_item.m_UserColor = GetDefaultUserColor( item->GetType() ); @@ -1478,7 +1480,7 @@ wxBitmapComboBox* PANEL_SETUP_BOARD_STACKUP::createColorBox( BOARD_STACKUP_ITEM* if( ii == GetColorUserDefinedListIdx() && aStackupItem && aStackupItem->GetColor().StartsWith( "#" ) ) { - curr_color = wxColour( aStackupItem->GetColor() ); + curr_color = wxColour( COLOR4D( aStackupItem->GetColor() ).ToColour() ); // NB: wxWidgets 3.0's color.GetAsString( wxC2S_HTML_SYNTAX ) pukes on alpha label = getColourAsHexString( curr_color ); diff --git a/pcbnew/exporters/gerber_jobfile_writer.cpp b/pcbnew/exporters/gerber_jobfile_writer.cpp index c2d42d6603..b3461338ec 100644 --- a/pcbnew/exporters/gerber_jobfile_writer.cpp +++ b/pcbnew/exporters/gerber_jobfile_writer.cpp @@ -650,7 +650,7 @@ void GERBER_JOBFILE_WRITER::addJSONMaterialStackup() if( colorName.StartsWith( "#" ) ) // This is a user defined color. { // In job file a color can be given by its RGB values (0...255) - wxColor color( colorName ); + wxColor color( COLOR4D( colorName ).ToColour() ); colorName.Printf( "R%dG%dB%d", color.Red(), color.Green(), color.Blue() ); }