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,39 +32,45 @@ 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()
|
||||
{
|
||||
{ 0, 0, 0, BLACK, TS( "Black" ), DARKDARKGRAY },
|
||||
{ 72, 72, 72, DARKDARKGRAY, TS( "Gray 1" ), DARKGRAY },
|
||||
{ 132, 132, 132, DARKGRAY, TS( "Gray 2" ), LIGHTGRAY },
|
||||
{ 194, 194, 194, LIGHTGRAY, TS( "Gray 3" ), WHITE },
|
||||
{ 255, 255, 255, WHITE, TS( "White" ), WHITE },
|
||||
{ 194, 255, 255, LIGHTYELLOW, TS( "L.Yellow" ), WHITE },
|
||||
{ 72, 0, 0, DARKBLUE, TS( "Blue 1" ), BLUE },
|
||||
{ 0, 72, 0, DARKGREEN, TS( "Green 1" ), GREEN },
|
||||
{ 72, 72, 0, DARKCYAN, TS( "Cyan 1" ), CYAN },
|
||||
{ 0, 0, 72, DARKRED, TS( "Red 1" ), RED },
|
||||
{ 72, 0, 72, DARKMAGENTA, TS( "Magenta 1" ), MAGENTA },
|
||||
{ 0, 72, 72, DARKBROWN, TS( "Brown 1" ), BROWN },
|
||||
{ 132, 0, 0, BLUE, TS( "Blue 2" ), LIGHTBLUE },
|
||||
{ 0, 132, 0, GREEN, TS( "Green 2" ), LIGHTGREEN },
|
||||
{ 132, 132, 0, CYAN, TS( "Cyan 2" ), LIGHTCYAN },
|
||||
{ 0, 0, 132, RED, TS( "Red 2" ), LIGHTRED },
|
||||
{ 132, 0, 132, MAGENTA, TS( "Magenta 2" ), LIGHTMAGENTA },
|
||||
{ 0, 132, 132, BROWN, TS( "Brown 2" ), YELLOW },
|
||||
{ 194, 0, 0, LIGHTBLUE, TS( "Blue 3" ), PUREBLUE, },
|
||||
{ 0, 194, 0, LIGHTGREEN, TS( "Green 3" ), PUREGREEN },
|
||||
{ 194, 194, 0, LIGHTCYAN, TS( "Cyan 3" ), PURECYAN },
|
||||
{ 0, 0, 194, LIGHTRED, TS( "Red 3" ), PURERED },
|
||||
{ 194, 0, 194, LIGHTMAGENTA, TS( "Magenta 3" ), PUREMAGENTA },
|
||||
{ 0, 194, 194, YELLOW, TS( "Yellow 3" ), PUREYELLOW },
|
||||
{ 255, 0, 0, PUREBLUE, TS( "Blue 4" ), WHITE },
|
||||
{ 0, 255, 0, PUREGREEN, TS( "Green 4" ), WHITE },
|
||||
{ 255, 255, 0, PURECYAN, TS( "Cyan 4" ), WHITE },
|
||||
{ 0, 0, 255, PURERED, TS( "Red 4" ), WHITE },
|
||||
{ 255, 0, 255, PUREMAGENTA, TS( "Magenta 4" ), WHITE },
|
||||
{ 0, 255, 255, PUREYELLOW, TS( "Yellow 4" ), WHITE },
|
||||
};
|
||||
static StructColors s_ColorRefs[NBCOLORS] =
|
||||
{
|
||||
{ 0, 0, 0, BLACK, TS( "Black" ), DARKDARKGRAY },
|
||||
{ 72, 72, 72, DARKDARKGRAY, TS( "Gray 1" ), DARKGRAY },
|
||||
{ 132, 132, 132, DARKGRAY, TS( "Gray 2" ), LIGHTGRAY },
|
||||
{ 194, 194, 194, LIGHTGRAY, TS( "Gray 3" ), WHITE },
|
||||
{ 255, 255, 255, WHITE, TS( "White" ), WHITE },
|
||||
{ 194, 255, 255, LIGHTYELLOW, TS( "L.Yellow" ), WHITE },
|
||||
{ 72, 0, 0, DARKBLUE, TS( "Blue 1" ), BLUE },
|
||||
{ 0, 72, 0, DARKGREEN, TS( "Green 1" ), GREEN },
|
||||
{ 72, 72, 0, DARKCYAN, TS( "Cyan 1" ), CYAN },
|
||||
{ 0, 0, 72, DARKRED, TS( "Red 1" ), RED },
|
||||
{ 72, 0, 72, DARKMAGENTA, TS( "Magenta 1" ), MAGENTA },
|
||||
{ 0, 72, 72, DARKBROWN, TS( "Brown 1" ), BROWN },
|
||||
{ 132, 0, 0, BLUE, TS( "Blue 2" ), LIGHTBLUE },
|
||||
{ 0, 132, 0, GREEN, TS( "Green 2" ), LIGHTGREEN },
|
||||
{ 132, 132, 0, CYAN, TS( "Cyan 2" ), LIGHTCYAN },
|
||||
{ 0, 0, 132, RED, TS( "Red 2" ), LIGHTRED },
|
||||
{ 132, 0, 132, MAGENTA, TS( "Magenta 2" ), LIGHTMAGENTA },
|
||||
{ 0, 132, 132, BROWN, TS( "Brown 2" ), YELLOW },
|
||||
{ 194, 0, 0, LIGHTBLUE, TS( "Blue 3" ), PUREBLUE, },
|
||||
{ 0, 194, 0, LIGHTGREEN, TS( "Green 3" ), PUREGREEN },
|
||||
{ 194, 194, 0, LIGHTCYAN, TS( "Cyan 3" ), PURECYAN },
|
||||
{ 0, 0, 194, LIGHTRED, TS( "Red 3" ), PURERED },
|
||||
{ 194, 0, 194, LIGHTMAGENTA, TS( "Magenta 3" ), PUREMAGENTA },
|
||||
{ 0, 194, 194, YELLOW, TS( "Yellow 3" ), PUREYELLOW },
|
||||
{ 255, 0, 0, PUREBLUE, TS( "Blue 4" ), WHITE },
|
||||
{ 0, 255, 0, PUREGREEN, TS( "Green 4" ), WHITE },
|
||||
{ 255, 255, 0, PURECYAN, TS( "Cyan 4" ), WHITE },
|
||||
{ 0, 0, 255, PURERED, TS( "Red 4" ), WHITE },
|
||||
{ 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