Jerry-rig HTML-format alpha parsing

On wx3.0, the HTML format #RRGGBBAA cannot handle the alpha channel.
Instead, we route this through a COLOR4D routine when we need to use
these colors

Fixes https://gitlab.com/kicad/code/kicad/issues/9963
This commit is contained in:
Seth Hillbrand 2021-12-13 16:03:19 -08:00
parent 348c2bc612
commit 78ff9a857a
5 changed files with 24 additions and 5 deletions

View File

@ -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
{

View File

@ -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;

View File

@ -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.
*/

View File

@ -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 );

View File

@ -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() );
}