Fix initialization order fiasco with colors
The legacy color refs are needed by the COLOR4D constructor when constructing a static variable, so they can't be static themselves.
This commit is contained in:
parent
5649558cff
commit
5b3d947b7e
|
@ -237,7 +237,7 @@ void DIALOG_COLOR_PICKER::initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColo
|
|||
grid_row++;
|
||||
}
|
||||
|
||||
int ii = grid_row + (grid_col*table_row_count); // The index in g_ColorRefs
|
||||
int ii = grid_row + (grid_col*table_row_count); // The index in colorRefs()
|
||||
|
||||
int butt_ID = ID_COLOR_BLACK + ii;
|
||||
wxMemoryDC iconDC;
|
||||
|
@ -246,7 +246,7 @@ void DIALOG_COLOR_PICKER::initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColo
|
|||
|
||||
iconDC.SelectObject( ButtBitmap );
|
||||
|
||||
KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( g_ColorRefs[ii].m_Numcolor );
|
||||
KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( colorRefs()[ii].m_Numcolor );
|
||||
m_Color4DList[ butt_ID - ID_COLOR_BLACK ] = buttcolor;
|
||||
|
||||
iconDC.SetPen( *wxBLACK_PEN );
|
||||
|
@ -265,7 +265,7 @@ void DIALOG_COLOR_PICKER::initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColo
|
|||
wxLEFT | wxBOTTOM, 5 );
|
||||
|
||||
wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
|
||||
wxGetTranslation( g_ColorRefs[ii].m_ColorName ),
|
||||
wxGetTranslation( colorRefs()[ii].m_ColorName ),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_fgridColor->Add( label, 1,
|
||||
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
|
||||
|
|
|
@ -32,7 +32,11 @@ using namespace KIGFX;
|
|||
|
||||
#define TS( string ) wxString( _HKI( string ) ).ToStdString()
|
||||
|
||||
const StructColors g_ColorRefs[NBCOLORS] =
|
||||
// We can't have this as a plain static variable, because it is referenced during the initialization
|
||||
// of other static variables, so we must initialize it explicitly on first use.
|
||||
const StructColors* colorRefs()
|
||||
{
|
||||
static StructColors s_ColorRefs[NBCOLORS] =
|
||||
{
|
||||
{ 0, 0, 0, BLACK, TS( "Black" ), DARKDARKGRAY },
|
||||
{ 72, 72, 72, DARKDARKGRAY, TS( "Gray 1" ), DARKGRAY },
|
||||
|
@ -65,6 +69,8 @@ const StructColors g_ColorRefs[NBCOLORS] =
|
|||
{ 255, 0, 255, PUREMAGENTA, TS( "Magenta 4" ), WHITE },
|
||||
{ 0, 255, 255, PUREYELLOW, TS( "Yellow 4" ), WHITE },
|
||||
};
|
||||
return s_ColorRefs;
|
||||
}
|
||||
|
||||
|
||||
COLOR4D::COLOR4D( EDA_COLOR_T aColor )
|
||||
|
@ -75,9 +81,9 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor )
|
|||
return;
|
||||
}
|
||||
|
||||
r = g_ColorRefs[aColor].m_Red / 255.0;
|
||||
g = g_ColorRefs[aColor].m_Green / 255.0;
|
||||
b = g_ColorRefs[aColor].m_Blue / 255.0;
|
||||
r = colorRefs()[aColor].m_Red / 255.0;
|
||||
g = colorRefs()[aColor].m_Green / 255.0;
|
||||
b = colorRefs()[aColor].m_Blue / 255.0;
|
||||
a = 1.0;
|
||||
}
|
||||
|
||||
|
@ -450,7 +456,7 @@ EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB )
|
|||
for( EDA_COLOR_T trying = EDA_COLOR_T::BLACK; trying < EDA_COLOR_T::NBCOLORS;
|
||||
trying = static_cast<EDA_COLOR_T>( int( trying ) + 1 ) )
|
||||
{
|
||||
const StructColors &c = g_ColorRefs[trying];
|
||||
const StructColors &c = colorRefs()[trying];
|
||||
int distance = (aR - c.m_Red) * (aR - c.m_Red) +
|
||||
(aG - c.m_Green) * (aG - c.m_Green) +
|
||||
(aB - c.m_Blue) * (aB - c.m_Blue);
|
||||
|
|
|
@ -87,7 +87,7 @@ struct StructColors
|
|||
};
|
||||
|
||||
/// Global list of legacy color names, still used all over the place for constructing COLOR4D's
|
||||
extern const StructColors g_ColorRefs[NBCOLORS];
|
||||
const StructColors* colorRefs();
|
||||
|
||||
|
||||
namespace KIGFX
|
||||
|
|
Loading…
Reference in New Issue