Preserve color scheme when switching to legacy (Fixes lp:1670669)
Instead of modifying the colors when switching to legacy canvas, they will now be preserved and only returned as the "legacy" colors.
This commit is contained in:
parent
f36350cb88
commit
0564d3456b
|
@ -96,6 +96,7 @@ static const EDA_COLOR_T default_items_color[] = {
|
||||||
COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS( FRAME_T aFrameType )
|
COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS( FRAME_T aFrameType )
|
||||||
{
|
{
|
||||||
m_frameType = aFrameType;
|
m_frameType = aFrameType;
|
||||||
|
m_legacyMode = false;
|
||||||
|
|
||||||
for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
|
for( unsigned src = 0, dst = 0; dst < DIM( m_LayersColors ); ++dst )
|
||||||
{
|
{
|
||||||
|
@ -124,7 +125,8 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
|
||||||
{
|
{
|
||||||
if( (unsigned) aLayer < DIM( m_LayersColors ) )
|
if( (unsigned) aLayer < DIM( m_LayersColors ) )
|
||||||
{
|
{
|
||||||
return m_LayersColors[aLayer];
|
return m_legacyMode ? m_LayersColors[aLayer].AsLegacyColor()
|
||||||
|
: m_LayersColors[aLayer];
|
||||||
}
|
}
|
||||||
return COLOR4D::UNSPECIFIED;
|
return COLOR4D::UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +145,8 @@ COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
|
||||||
{
|
{
|
||||||
if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
|
if( (unsigned) aItemIdx < DIM( m_LayersColors ) )
|
||||||
{
|
{
|
||||||
return m_LayersColors[aItemIdx];
|
return m_legacyMode ? m_LayersColors[aItemIdx].AsLegacyColor()
|
||||||
|
: m_LayersColors[aItemIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
return COLOR4D::UNSPECIFIED;
|
return COLOR4D::UNSPECIFIED;
|
||||||
|
|
|
@ -144,7 +144,7 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EDA_COLOR_T COLOR4D::GetNearestLegacyColor( COLOR4D &aColor )
|
EDA_COLOR_T COLOR4D::GetNearestLegacyColor( const COLOR4D &aColor )
|
||||||
{
|
{
|
||||||
// Cache layer implemented here, because all callers are using wxColour
|
// Cache layer implemented here, because all callers are using wxColour
|
||||||
static std::map< unsigned int, unsigned int > nearestCache;
|
static std::map< unsigned int, unsigned int > nearestCache;
|
||||||
|
|
|
@ -221,7 +221,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ):
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
forceColorsToLegacy();
|
m_colorsSettings->SetLegacyMode( true );
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1039,17 +1039,6 @@ void GERBVIEW_FRAME::unitsChangeRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::forceColorsToLegacy()
|
|
||||||
{
|
|
||||||
for( int i = 0; i < LAYER_ID_COUNT; i++ )
|
|
||||||
{
|
|
||||||
COLOR4D c = m_colorsSettings->GetLayerColor( i );
|
|
||||||
c.SetToNearestLegacyColor();
|
|
||||||
m_colorsSettings->SetLayerColor( i, c );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::UseGalCanvas( bool aEnable )
|
void GERBVIEW_FRAME::UseGalCanvas( bool aEnable )
|
||||||
{
|
{
|
||||||
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
|
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
|
||||||
|
@ -1065,6 +1054,8 @@ void GERBVIEW_FRAME::UseGalCanvas( bool aEnable )
|
||||||
if( m_toolManager )
|
if( m_toolManager )
|
||||||
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
|
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
|
||||||
|
|
||||||
|
m_colorsSettings->SetLegacyMode( false );
|
||||||
|
|
||||||
galCanvas->GetGAL()->SetGridColor( GetLayerColor( LAYER_GERBVIEW_GRID ) );
|
galCanvas->GetGAL()->SetGridColor( GetLayerColor( LAYER_GERBVIEW_GRID ) );
|
||||||
|
|
||||||
galCanvas->GetView()->RecacheAllItems();
|
galCanvas->GetView()->RecacheAllItems();
|
||||||
|
@ -1081,7 +1072,7 @@ void GERBVIEW_FRAME::UseGalCanvas( bool aEnable )
|
||||||
// Redirect all events to the legacy canvas
|
// Redirect all events to the legacy canvas
|
||||||
galCanvas->SetEventDispatcher( NULL );
|
galCanvas->SetEventDispatcher( NULL );
|
||||||
|
|
||||||
forceColorsToLegacy();
|
m_colorsSettings->SetLegacyMode( true );
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,9 +173,6 @@ protected:
|
||||||
/// The last filename chosen to be proposed to the user
|
/// The last filename chosen to be proposed to the user
|
||||||
wxString m_lastFileName;
|
wxString m_lastFileName;
|
||||||
|
|
||||||
///> @copydoc EDA_DRAW_FRAME::forceColorsToLegacy()
|
|
||||||
virtual void forceColorsToLegacy() override;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxChoice* m_SelComponentBox; // a choice box to display and highlight component graphic items
|
wxChoice* m_SelComponentBox; // a choice box to display and highlight component graphic items
|
||||||
wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist graphic items
|
wxChoice* m_SelNetnameBox; // a choice box to display and highlight netlist graphic items
|
||||||
|
|
|
@ -92,9 +92,25 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetAllColorsAs( COLOR4D aColor );
|
void SetAllColorsAs( COLOR4D aColor );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables legacy color mode. When enabled, all colors will be
|
||||||
|
* quantized to the legacy color palette when returned from GetItemColor and
|
||||||
|
* GetLayerColor (but the underlying color will not be changed, and can
|
||||||
|
* still be set to arbitrary colors).
|
||||||
|
*/
|
||||||
|
void SetLegacyMode( bool aMode )
|
||||||
|
{
|
||||||
|
m_legacyMode = aMode;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FRAME_T m_frameType;
|
FRAME_T m_frameType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see SetLegacyMode()
|
||||||
|
*/
|
||||||
|
bool m_legacyMode;
|
||||||
|
|
||||||
void setupConfigParams();
|
void setupConfigParams();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -149,12 +149,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual void unitsChangeRefresh();
|
virtual void unitsChangeRefresh();
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to coerce all colors to legacy-compatible when
|
|
||||||
* switching from GAL to legacy canvas
|
|
||||||
*/
|
|
||||||
virtual void forceColorsToLegacy() {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GeneralControlKeyMovement
|
* Function GeneralControlKeyMovement
|
||||||
* Handle the common part of GeneralControl dedicated to global
|
* Handle the common part of GeneralControl dedicated to global
|
||||||
|
|
|
@ -121,6 +121,11 @@ public:
|
||||||
*/
|
*/
|
||||||
COLOR4D& SetToNearestLegacyColor();
|
COLOR4D& SetToNearestLegacyColor();
|
||||||
|
|
||||||
|
COLOR4D AsLegacyColor() const
|
||||||
|
{
|
||||||
|
return COLOR4D( COLOR4D::GetNearestLegacyColor( *this ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packs the color into an unsigned int for compatibility with legacy canvas.
|
* Packs the color into an unsigned int for compatibility with legacy canvas.
|
||||||
* Note that this is a lossy downsampling and also that the alpha channel is lost.
|
* Note that this is a lossy downsampling and also that the alpha channel is lost.
|
||||||
|
@ -135,7 +140,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Determines the "nearest" EDA_COLOR_T according to ColorFindNearest
|
* Determines the "nearest" EDA_COLOR_T according to ColorFindNearest
|
||||||
*/
|
*/
|
||||||
static EDA_COLOR_T GetNearestLegacyColor( COLOR4D &aColor );
|
static EDA_COLOR_T GetNearestLegacyColor( const COLOR4D &aColor );
|
||||||
#endif /* WX_COMPATIBLITY */
|
#endif /* WX_COMPATIBLITY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -713,11 +713,15 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
|
||||||
Compile_Ratsnest( NULL, true );
|
Compile_Ratsnest( NULL, true );
|
||||||
|
|
||||||
PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
|
PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
|
||||||
|
COLORS_DESIGN_SETTINGS& cds = Settings().Colors();
|
||||||
|
|
||||||
if( aEnable )
|
if( aEnable )
|
||||||
{
|
{
|
||||||
COLORS_DESIGN_SETTINGS& cds = Settings().Colors();
|
cds.SetLegacyMode( false );
|
||||||
GetGalCanvas()->GetGAL()->SetGridColor( cds.GetLayerColor( LAYER_GRID ) );
|
GetGalCanvas()->GetGAL()->SetGridColor( cds.GetLayerColor( LAYER_GRID ) );
|
||||||
|
auto view = GetGalCanvas()->GetView();
|
||||||
|
view->GetPainter()->GetSettings()->ImportLegacyColors( &cds );
|
||||||
|
GetGalCanvas()->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
enableGALSpecificMenus();
|
enableGALSpecificMenus();
|
||||||
|
@ -725,7 +729,7 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
|
||||||
// Force colors to be legacy-compatible in case they were changed in GAL
|
// Force colors to be legacy-compatible in case they were changed in GAL
|
||||||
if( !aEnable )
|
if( !aEnable )
|
||||||
{
|
{
|
||||||
forceColorsToLegacy();
|
cds.SetLegacyMode( true );
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,21 +738,6 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCB_EDIT_FRAME::forceColorsToLegacy()
|
|
||||||
{
|
|
||||||
COLORS_DESIGN_SETTINGS& cds = Settings().Colors();
|
|
||||||
|
|
||||||
for( unsigned i = 0; i < DIM( cds.m_LayersColors ); i++ )
|
|
||||||
{
|
|
||||||
COLOR4D c = cds.GetLayerColor( i );
|
|
||||||
c.SetToNearestLegacyColor();
|
|
||||||
// Note the alpha chanel is not modified. Therefore the value
|
|
||||||
// is the previous value used in GAL canvas.
|
|
||||||
cds.SetLayerColor( i, c );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PCB_EDIT_FRAME::enableGALSpecificMenus()
|
void PCB_EDIT_FRAME::enableGALSpecificMenus()
|
||||||
{
|
{
|
||||||
// some menus are active only in GAL mode and do nothing in legacy mode.
|
// some menus are active only in GAL mode and do nothing in legacy mode.
|
||||||
|
|
|
@ -123,9 +123,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual void SwitchCanvas( wxCommandEvent& aEvent ) override;
|
virtual void SwitchCanvas( wxCommandEvent& aEvent ) override;
|
||||||
|
|
||||||
///> @copydoc EDA_DRAW_FRAME::forceColorsToLegacy()
|
|
||||||
virtual void forceColorsToLegacy() override;
|
|
||||||
|
|
||||||
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
||||||
/**
|
/**
|
||||||
* Function RebuildActionPluginMenus
|
* Function RebuildActionPluginMenus
|
||||||
|
|
Loading…
Reference in New Issue