Rip out the unused leftovers of the old color system

This commit is contained in:
Jon Evans 2020-06-18 22:32:14 -04:00
parent 32738862b8
commit e91b9f6dfb
14 changed files with 150 additions and 512 deletions

View File

@ -107,8 +107,7 @@ add_library( singletop STATIC EXCLUDE_FROM_ALL
# Functions and data all need to use the #include <import_export.h> and be declared # Functions and data all need to use the #include <import_export.h> and be declared
# as APIEXPORT # as APIEXPORT
set( LIB_KICAD_SRCS set( LIB_KICAD_SRCS
colors.cpp string.cpp
string.cpp
) )
if( future ) if( future )
@ -272,8 +271,7 @@ set( COMMON_SRCS
bitmap_base.cpp bitmap_base.cpp
board_printout.cpp board_printout.cpp
build_version.cpp build_version.cpp
colors.cpp commit.cpp
commit.cpp
common.cpp common.cpp
config_params.cpp config_params.cpp
confirm.cpp confirm.cpp

View File

@ -1,184 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <colors.h>
#include <i18n_utility.h>
/**
* The predefined colors used in KiCad.
* Please: if you change a value, remember these values are carefully chosen
* to have good results in Pcbnew, that uses the ORed value of basic colors
* when displaying superimposed objects
* This list must have exactly NBCOLORS items
*/
const StructColors g_ColorRefs[NBCOLORS] =
{
{ 0, 0, 0, BLACK, _HKI( "Black" ), DARKDARKGRAY },
{ 72, 72, 72, DARKDARKGRAY, _HKI( "Gray 1" ), DARKGRAY },
{ 132, 132, 132, DARKGRAY, _HKI( "Gray 2" ), LIGHTGRAY },
{ 194, 194, 194, LIGHTGRAY, _HKI( "Gray 3" ), WHITE },
{ 255, 255, 255, WHITE, _HKI( "White" ), WHITE },
{ 194, 255, 255, LIGHTYELLOW, _HKI( "L.Yellow" ), WHITE },
{ 72, 0, 0, DARKBLUE, _HKI( "Blue 1" ), BLUE },
{ 0, 72, 0, DARKGREEN, _HKI( "Green 1" ), GREEN },
{ 72, 72, 0, DARKCYAN, _HKI( "Cyan 1" ), CYAN },
{ 0, 0, 72, DARKRED, _HKI( "Red 1" ), RED },
{ 72, 0, 72, DARKMAGENTA, _HKI( "Magenta 1" ), MAGENTA },
{ 0, 72, 72, DARKBROWN, _HKI( "Brown 1" ), BROWN },
{ 132, 0, 0, BLUE, _HKI( "Blue 2" ), LIGHTBLUE },
{ 0, 132, 0, GREEN, _HKI( "Green 2" ), LIGHTGREEN },
{ 132, 132, 0, CYAN, _HKI( "Cyan 2" ), LIGHTCYAN },
{ 0, 0, 132, RED, _HKI( "Red 2" ), LIGHTRED },
{ 132, 0, 132, MAGENTA, _HKI( "Magenta 2" ), LIGHTMAGENTA },
{ 0, 132, 132, BROWN, _HKI( "Brown 2" ), YELLOW },
{ 194, 0, 0, LIGHTBLUE, _HKI( "Blue 3" ), PUREBLUE, },
{ 0, 194, 0, LIGHTGREEN, _HKI( "Green 3" ), PUREGREEN },
{ 194, 194, 0, LIGHTCYAN, _HKI( "Cyan 3" ), PURECYAN },
{ 0, 0, 194, LIGHTRED, _HKI( "Red 3" ), PURERED },
{ 194, 0, 194, LIGHTMAGENTA, _HKI( "Magenta 3" ), PUREMAGENTA },
{ 0, 194, 194, YELLOW, _HKI( "Yellow 3" ), PUREYELLOW },
{ 255, 0, 0, PUREBLUE, _HKI( "Blue 4" ), WHITE },
{ 0, 255, 0, PUREGREEN, _HKI( "Green 4" ), WHITE },
{ 255, 255, 0, PURECYAN, _HKI( "Cyan 4" ), WHITE },
{ 0, 0, 255, PURERED, _HKI( "Red 4" ), WHITE },
{ 255, 0, 255, PUREMAGENTA, _HKI( "Magenta 4" ), WHITE },
{ 0, 255, 255, PUREYELLOW, _HKI( "Yellow 4" ), WHITE },
};
EDA_COLOR_T ColorByName( const wxString& aName )
{
// look for a match in the palette itself
for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) )
{
if( 0 == aName.CmpNoCase( ColorGetName( trying ) ) )
return trying;
}
// Not found, no idea...
return UNSPECIFIED_COLOR;
}
bool ColorIsLight( EDA_COLOR_T aColor )
{
const StructColors &c = g_ColorRefs[ColorGetBase( aColor )];
int r = c.m_Red;
int g = c.m_Green;
int b = c.m_Blue;
return ((r * r) + (g * g) + (b * b)) > (128 * 128 * 3);
}
EDA_COLOR_T ColorFindNearest( const wxColour &aColor )
{
return ColorFindNearest( aColor.Red(), aColor.Green(), aColor.Blue() );
}
EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB )
{
EDA_COLOR_T candidate = BLACK;
/* Find the 'nearest' color in the palette. This is fun. There is
a gazilion of metrics for the color space and no one of the
useful one is in the RGB color space. Who cares, this is a CAD,
not a photosomething...
I hereby declare that the distance is the sum of the square of the
component difference. Think about the RGB color cube. Now get the
euclidean distance, but without the square root... for ordering
purposes it's the same, obviously. Also each component can't be
less of the target one, since I found this currently work better...
*/
int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this
for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) )
{
const StructColors &c = g_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);
if( distance < nearest_distance && c.m_Red >= aR &&
c.m_Green >= aG && c.m_Blue >= aB )
{
nearest_distance = distance;
candidate = trying;
}
}
return candidate;
}
EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 )
{
/* Memoization storage. This could be potentially called for each
* color merge so a cache is useful (there are few colours anyway) */
static EDA_COLOR_T mix_cache[NBCOLORS][NBCOLORS];
// TODO how is alpha used? it's a mac only thing, I have no idea
aColor1 = ColorGetBase( aColor1 );
aColor2 = ColorGetBase( aColor2 );
// First easy thing: a black gives always the other colour
if( aColor1 == BLACK )
return aColor2;
if( aColor2 == BLACK)
return aColor1;
/* Now we are sure that black can't occur, so the rule is:
* BLACK means not computed yet. If we're lucky we already have
* an answer */
EDA_COLOR_T candidate = mix_cache[aColor1][aColor2];
if( candidate != BLACK )
return candidate;
// Blend the two colors (i.e. OR the RGB values)
const StructColors &c1 = g_ColorRefs[aColor1];
const StructColors &c2 = g_ColorRefs[aColor2];
// Ask the palette for the nearest color to the mix
wxColour mixed( c1.m_Red | c2.m_Red,
c1.m_Green | c2.m_Green,
c1.m_Blue | c2.m_Blue );
candidate = ColorFindNearest( mixed );
/* Here, BLACK is *not* a good answer, since it would recompute the next time.
* Even theorically its not possible (with the current rules), but
* maybe the metric will change in the future */
if( candidate == BLACK )
candidate = DARKDARKGRAY;
// Store the result in the cache. The operation is commutative, too
mix_cache[aColor1][aColor2] = candidate;
mix_cache[aColor2][aColor1] = candidate;
return candidate;
}

View File

@ -24,7 +24,6 @@
*/ */
#include <colors.h> // for ColorByName, EDA_COLOR_T, UNSPECIFIE...
#include <common.h> // for LOCALE_IO #include <common.h> // for LOCALE_IO
#include <config_params.h> // for PARAM_CFG_INT_WITH_SCALE, PARAM_CFG_... #include <config_params.h> // for PARAM_CFG_INT_WITH_SCALE, PARAM_CFG_...
#include <gal/color4d.h> // for COLOR4D #include <gal/color4d.h> // for COLOR4D
@ -243,73 +242,6 @@ void PARAM_CFG_INT_WITH_SCALE::SaveParam( wxConfigBase* aConfig ) const
} }
PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR( const wxString& ident, COLOR4D* ptparam,
COLOR4D default_val,
const wxChar* group ) :
PARAM_CFG( ident, PARAM_SETCOLOR, group )
{
m_Pt_param = ptparam;
m_Default = default_val;
}
PARAM_CFG_SETCOLOR::PARAM_CFG_SETCOLOR( bool Insetup,
const wxString& ident,
COLOR4D* ptparam,
COLOR4D default_val,
const wxChar* group ) :
PARAM_CFG( ident, PARAM_SETCOLOR, group )
{
m_Pt_param = ptparam;
m_Default = default_val;
m_Setup = Insetup;
}
void PARAM_CFG_SETCOLOR::ReadParam( wxConfigBase* aConfig ) const
{
if( !m_Pt_param || !aConfig )
return;
COLOR4D temp;
if( aConfig->HasEntry( m_Ident ) )
{
if( temp.SetFromWxString( aConfig->Read( m_Ident, wxT( "NONE" ) ) ) )
{
*m_Pt_param = temp;
return;
}
}
// If no luck, try reading legacy format
wxString legacy_Ident = m_Ident;
legacy_Ident.Replace( wxT( "4D" ), wxEmptyString );
EDA_COLOR_T old = ColorByName( aConfig->Read( legacy_Ident, wxT( "NONE" ) ) );
if( old != UNSPECIFIED_COLOR )
{
if( m_Ident == wxT( "Color4DErcWEx" ) || m_Ident == wxT( "Color4DErcEEx" ) )
*m_Pt_param = COLOR4D( old ).WithAlpha( 0.8 );
else
*m_Pt_param = COLOR4D( old );
return;
}
*m_Pt_param = m_Default;
}
void PARAM_CFG_SETCOLOR::SaveParam( wxConfigBase* aConfig ) const
{
if( !m_Pt_param || !aConfig )
return;
aConfig->Write( m_Ident, m_Pt_param->ToColour().GetAsString( wxC2S_CSS_SYNTAX ) );
}
PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam, PARAM_CFG_DOUBLE::PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
double default_val, double min, double max, double default_val, double min, double max,
const wxChar* group ) : const wxChar* group ) :

View File

@ -26,9 +26,47 @@
#include <map> #include <map>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <gal/color4d.h> #include <gal/color4d.h>
#include <i18n_utility.h>
using namespace KIGFX; using namespace KIGFX;
#define TS( string ) wxString( _HKI( string ) ).ToStdString()
const StructColors g_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 },
};
COLOR4D::COLOR4D( EDA_COLOR_T aColor ) COLOR4D::COLOR4D( EDA_COLOR_T aColor )
{ {
if( aColor <= UNSPECIFIED_COLOR || aColor >= NBCOLORS ) if( aColor <= UNSPECIFIED_COLOR || aColor >= NBCOLORS )
@ -390,3 +428,40 @@ COLOR4D& COLOR4D::Saturate( double aFactor )
constexpr COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 ); constexpr COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 );
constexpr COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 ); constexpr COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 );
constexpr COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 ); constexpr COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 );
EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB )
{
EDA_COLOR_T candidate = EDA_COLOR_T::BLACK;
/* Find the 'nearest' color in the palette. This is fun. There is
a gazilion of metrics for the color space and no one of the
useful one is in the RGB color space. Who cares, this is a CAD,
not a photosomething...
I hereby declare that the distance is the sum of the square of the
component difference. Think about the RGB color cube. Now get the
euclidean distance, but without the square root... for ordering
purposes it's the same, obviously. Also each component can't be
less of the target one, since I found this currently work better...
*/
int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this
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];
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);
if( distance < nearest_distance && c.m_Red >= aR &&
c.m_Green >= aG && c.m_Blue >= aB )
{
nearest_distance = distance;
candidate = trying;
}
}
return candidate;
}

View File

@ -118,9 +118,9 @@ static const char* getDXFLineType( PLOT_DASH_TYPE aType )
// DXF files do not use a RGB definition // DXF files do not use a RGB definition
static wxString getDXFColorName( COLOR4D aColor ) static wxString getDXFColorName( COLOR4D aColor )
{ {
EDA_COLOR_T color = ColorFindNearest( int( aColor.r*255 ), EDA_COLOR_T color = COLOR4D::FindNearestLegacyColor( int( aColor.r * 255 ),
int( aColor.g*255 ), int( aColor.g * 255 ),
int( aColor.b*255 ) ); int( aColor.b * 255 ) );
wxString cname( dxf_layer[color].name ); wxString cname( dxf_layer[color].name );
return cname; return cname;
} }
@ -357,7 +357,9 @@ bool DXF_PLOTTER::StartPlot()
- Greys (251 - 255) - Greys (251 - 255)
*/ */
for( EDA_COLOR_T i = BLACK; i < numLayers; i = NextColor(i) ) wxASSERT( numLayers < NBCOLORS );
for( EDA_COLOR_T i = BLACK; i < numLayers; i = static_cast<EDA_COLOR_T>( int( i ) + 1 ) )
{ {
fprintf( outputFile, fprintf( outputFile,
" 0\n" " 0\n"

View File

@ -1,222 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with
* legacy canvas. Once there is no need for legacy support, the color
* table g_ColorRefs in colors.cpp can be re-written in COLOR4D and this
* file can go away.
*
* Please use COLOR4D instead of including this file.
*/
#ifndef COLORS_H_
#define COLORS_H_
#include <wx/wx.h>
/** The color enumeration. Also contains a flag and the alpha value in
* the upper bits
*/
enum EDA_COLOR_T
{
UNSPECIFIED_COLOR = -1,
BLACK = 0,
DARKDARKGRAY,
DARKGRAY,
LIGHTGRAY,
WHITE,
LIGHTYELLOW,
DARKBLUE,
DARKGREEN,
DARKCYAN,
DARKRED,
DARKMAGENTA,
DARKBROWN,
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
PUREBLUE,
PUREGREEN,
PURECYAN,
PURERED,
PUREMAGENTA,
PUREYELLOW,
NBCOLORS, ///< Number of colors
HIGHLIGHT_FLAG = ( 1<<19 ),
MASKCOLOR = 31 ///< mask for color index into g_ColorRefs[]
};
/// Checked cast. Use only when necessary (usually I/O)
inline EDA_COLOR_T ColorFromInt( int aColor )
{
wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor < NBCOLORS );
return static_cast<EDA_COLOR_T>( aColor );
}
inline EDA_COLOR_T NextColor( EDA_COLOR_T& aColor )
{
// We have to accept NBCOLORS for loop termination conditions
wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor <= NBCOLORS );
aColor = static_cast<EDA_COLOR_T>( int( aColor ) + 1 );
return aColor;
}
/// Return only the plain color part
inline EDA_COLOR_T ColorGetBase( EDA_COLOR_T aColor)
{
EDA_COLOR_T base = static_cast<EDA_COLOR_T>( aColor & MASKCOLOR );
return base;
}
/// Mix two colors in some way (hopefully like a logical OR)
EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 );
/// Force the color part of a color to darkdarkgray
inline void ColorTurnToDarkDarkGray( EDA_COLOR_T *aColor )
{
*aColor = static_cast<EDA_COLOR_T>( (int(*aColor) & ~MASKCOLOR) | DARKDARKGRAY );
}
inline void ColorChangeHighlightFlag( EDA_COLOR_T *aColor, bool flag )
{
if( flag )
*aColor = static_cast<EDA_COLOR_T>( (int(*aColor) | HIGHLIGHT_FLAG ) );
else
*aColor = static_cast<EDA_COLOR_T>( (int(*aColor) & ~HIGHLIGHT_FLAG ) );
}
/**
* Function SetAlpha
* ORs in the alpha blend parameter in to a color index.
*/
inline void SetAlpha( EDA_COLOR_T* aColor, unsigned char aBlend )
{
const unsigned char MASKALPHA = 0xFF;
*aColor = static_cast<EDA_COLOR_T>((*aColor & ~(MASKALPHA << 24))
| ((aBlend & MASKALPHA) << 24));
}
/**
* Function GetAlpha
* returns the alpha blend parameter from a color index.
*/
inline unsigned char GetAlpha( EDA_COLOR_T aColor )
{
const unsigned char MASKALPHA = 0xFF;
return (aColor >> 24) & MASKALPHA;
}
struct StructColors
{
unsigned char m_Blue;
unsigned char m_Green;
unsigned char m_Red;
EDA_COLOR_T m_Numcolor;
const wxChar* m_ColorName;
EDA_COLOR_T m_LightColor;
};
/// list of existing Colors
extern const StructColors g_ColorRefs[NBCOLORS];
/// Step a color to the highlighted version if the highlight flag is set
inline void ColorApplyHighlightFlag( EDA_COLOR_T *aColor )
{
EDA_COLOR_T base = ColorGetBase( *aColor );
wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
if( *aColor & HIGHLIGHT_FLAG )
*aColor = g_ColorRefs[base].m_LightColor;
}
/// Find a color by name
EDA_COLOR_T ColorByName( const wxString& aName );
/// Find the nearest color match
EDA_COLOR_T ColorFindNearest( const wxColour &aColor );
/**
* Find the nearest color match
* @param aR is the red component of the color to be matched (in range 0-255)
* @param aG is the green component of the color to be matched (in range 0-255)
* @param aB is the blue component of the color to be matched (in range 0-255)
*/
EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB );
/**
* Check if a color is light i.e. if black would be more readable than
* white on it
*/
bool ColorIsLight( EDA_COLOR_T aColor );
inline const wxChar *ColorGetName( EDA_COLOR_T aColor )
{
EDA_COLOR_T base = ColorGetBase( aColor );
wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
return g_ColorRefs[base].m_ColorName;
}
inline void ColorSetBrush( wxBrush *aBrush, EDA_COLOR_T aColor )
{
EDA_COLOR_T base = ColorGetBase( aColor );
wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
const StructColors &col = g_ColorRefs[base];
aBrush->SetColour( col.m_Red, col.m_Green, col.m_Blue );
}
/**
* Function MakeColour
* returns a wxWidgets wxColor from a KiCad color index with alpha value.
* Note that alpha support is not available on every wxWidgets platform. On
* such platform the behavior is the same as for wxALPHA_OPAQUE and that
* means the alpha value has no effect and will be ignored.
* @return wxColour - given a KiCad color index with alpha value
*/
inline wxColour MakeColour( EDA_COLOR_T aColor )
{
int alpha = GetAlpha( aColor );
alpha = alpha ? alpha : wxALPHA_OPAQUE;
EDA_COLOR_T ndx = ColorGetBase( aColor );
wxASSERT( ndx > UNSPECIFIED_COLOR && ndx < NBCOLORS );
return wxColour( g_ColorRefs[ndx].m_Red,
g_ColorRefs[ndx].m_Green,
g_ColorRefs[ndx].m_Blue
,(unsigned char) alpha
);
}
#endif // COLORS_H_

View File

@ -70,7 +70,6 @@ void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double
enum paramcfg_id { enum paramcfg_id {
PARAM_INT, PARAM_INT,
PARAM_INT_WITH_SCALE, PARAM_INT_WITH_SCALE,
PARAM_SETCOLOR,
PARAM_DOUBLE, PARAM_DOUBLE,
PARAM_BOOL, PARAM_BOOL,
PARAM_LIBNAME_LIST, PARAM_LIBNAME_LIST,
@ -186,27 +185,6 @@ public:
}; };
/**
* Configuration parameter - SetColor Class
*
*/
class PARAM_CFG_SETCOLOR : public PARAM_CFG
{
public:
COLOR4D* m_Pt_param; ///< Pointer to the parameter value
COLOR4D m_Default; ///< The default value of the parameter
public:
PARAM_CFG_SETCOLOR( const wxString& ident, COLOR4D* ptparam,
COLOR4D default_val, const wxChar* group = NULL );
PARAM_CFG_SETCOLOR( bool Insetup, const wxString& ident, COLOR4D* ptparam,
COLOR4D default_val, const wxChar* group = NULL );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
};
/** /**
* Configuration parameter - Double Precision Class * Configuration parameter - Double Precision Class
* *

View File

@ -27,10 +27,69 @@
#ifndef COLOR4D_H_ #ifndef COLOR4D_H_
#define COLOR4D_H_ #define COLOR4D_H_
#include <colors.h>
#include <cassert> #include <cassert>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
#ifdef WX_COMPATIBILITY
#include <wx/wx.h>
#endif
/**
* Legacy color enumeration. Also contains a flag and the alpha value in
* the upper bits
*/
enum EDA_COLOR_T
{
UNSPECIFIED_COLOR = -1,
BLACK = 0,
DARKDARKGRAY,
DARKGRAY,
LIGHTGRAY,
WHITE,
LIGHTYELLOW,
DARKBLUE,
DARKGREEN,
DARKCYAN,
DARKRED,
DARKMAGENTA,
DARKBROWN,
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
PUREBLUE,
PUREGREEN,
PURECYAN,
PURERED,
PUREMAGENTA,
PUREYELLOW,
NBCOLORS, ///< Number of colors
HIGHLIGHT_FLAG = ( 1<<19 ),
MASKCOLOR = 31 ///< mask for color index into g_ColorRefs[]
};
struct StructColors
{
unsigned char m_Blue;
unsigned char m_Green;
unsigned char m_Red;
EDA_COLOR_T m_Numcolor;
std::string m_ColorName;
EDA_COLOR_T m_LightColor;
};
/// Global list of legacy color names, still used all over the place for constructing COLOR4D's
extern const StructColors g_ColorRefs[NBCOLORS];
namespace KIGFX namespace KIGFX
{ {
/** /**
@ -298,6 +357,11 @@ public:
*/ */
void FromHSV( double aInH, double aInS, double aInV ); void FromHSV( double aInH, double aInS, double aInV );
/**
* Returns a legacy color ID that is closest to the given 8-bit RGB values.
*/
static EDA_COLOR_T FindNearestLegacyColor( int aR, int aG, int aB );
// Color components: red, green, blue, alpha // Color components: red, green, blue, alpha
double r; ///< Red component double r; ///< Red component
double g; ///< Green component double g; ///< Green component

View File

@ -173,7 +173,7 @@ void PLEDITOR_PRINTOUT::PrintPage( int aPageNum )
GRForceBlackPen( true ); GRForceBlackPen( true );
COLOR4D bg_color = m_parent->GetDrawBgColor(); COLOR4D bg_color = m_parent->GetDrawBgColor();
m_parent->SetDrawBgColor( MakeColour( WHITE ) ); m_parent->SetDrawBgColor( WHITE );
screen->m_ScreenNumber = aPageNum; screen->m_ScreenNumber = aPageNum;

View File

@ -39,7 +39,6 @@
#include <trigo.h> #include <trigo.h>
#include <board_design_settings.h> // for BOARD_DESIGN_SETTINGS #include <board_design_settings.h> // for BOARD_DESIGN_SETTINGS
#include <colors.h> // for LIGHTGRAY, WHITE
#include <core/typeinfo.h> // for dyn_cast, PCB_DIMENSION_T #include <core/typeinfo.h> // for dyn_cast, PCB_DIMENSION_T
#include <eda_text.h> // for FILLED, EDA_DRAW_MODE_T #include <eda_text.h> // for FILLED, EDA_DRAW_MODE_T
#include <gal/color4d.h> // for COLOR4D, operator!= #include <gal/color4d.h> // for COLOR4D, operator!=

View File

@ -33,7 +33,6 @@ set( common_srcs
${CMAKE_SOURCE_DIR}/common/base_units.cpp ${CMAKE_SOURCE_DIR}/common/base_units.cpp
# stuff from common which is needed...why? # stuff from common which is needed...why?
${CMAKE_SOURCE_DIR}/common/colors.cpp
${CMAKE_SOURCE_DIR}/common/observable.cpp ${CMAKE_SOURCE_DIR}/common/observable.cpp
wximage_test_utils.cpp wximage_test_utils.cpp

View File

@ -27,7 +27,6 @@ add_executable( qa_common_tools
# ../../common/eda_text.cpp # ../../common/eda_text.cpp
# stuff from common which is needed...why? # stuff from common which is needed...why?
${CMAKE_SOURCE_DIR}/common/colors.cpp
${CMAKE_SOURCE_DIR}/common/observable.cpp ${CMAKE_SOURCE_DIR}/common/observable.cpp
# Mock Pgm needed for advanced_config in coroutines # Mock Pgm needed for advanced_config in coroutines
@ -66,4 +65,4 @@ target_include_directories( qa_common_tools PRIVATE
$<TARGET_PROPERTY:libcontext,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:libcontext,INTERFACE_INCLUDE_DIRECTORIES>
) )
kicad_add_utils_executable( qa_common_tools ) kicad_add_utils_executable( qa_common_tools )

View File

@ -33,7 +33,6 @@ include_directories(
set( QA_EESCHEMA_SRCS set( QA_EESCHEMA_SRCS
# stuff from common which is needed...why? # stuff from common which is needed...why?
${CMAKE_SOURCE_DIR}/common/colors.cpp
${CMAKE_SOURCE_DIR}/common/observable.cpp ${CMAKE_SOURCE_DIR}/common/observable.cpp
# need the mock Pgm for many functions # need the mock Pgm for many functions

View File

@ -31,7 +31,6 @@ add_executable( qa_pcbnew
${CMAKE_SOURCE_DIR}/common/eda_text.cpp ${CMAKE_SOURCE_DIR}/common/eda_text.cpp
# stuff from common which is needed...why? # stuff from common which is needed...why?
${CMAKE_SOURCE_DIR}/common/colors.cpp
${CMAKE_SOURCE_DIR}/common/observable.cpp ${CMAKE_SOURCE_DIR}/common/observable.cpp
# The main test entry points # The main test entry points