2009-11-23 20:18:47 +00:00
|
|
|
/************/
|
|
|
|
/* colors.h */
|
|
|
|
/************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#ifndef COLORS_H_
|
|
|
|
#define COLORS_H_
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
/** The color enumeration. Also contains a flag and the alpha value in
|
|
|
|
* the upper bits
|
2008-04-02 14:16:14 +00:00
|
|
|
*/
|
2012-03-26 23:47:08 +00:00
|
|
|
enum EDA_COLOR_T
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
UNSPECIFIED_COLOR = -1,
|
2008-04-02 14:16:14 +00:00
|
|
|
BLACK = 0,
|
2013-04-05 17:23:56 +00:00
|
|
|
DARKDARKGRAY,
|
|
|
|
DARKGRAY,
|
|
|
|
LIGHTGRAY,
|
|
|
|
WHITE,
|
|
|
|
LIGHTYELLOW,
|
|
|
|
DARKBLUE,
|
|
|
|
DARKGREEN,
|
|
|
|
DARKCYAN,
|
|
|
|
DARKRED,
|
|
|
|
DARKMAGENTA,
|
|
|
|
DARKBROWN,
|
2008-04-02 14:16:14 +00:00
|
|
|
BLUE,
|
|
|
|
GREEN,
|
|
|
|
CYAN,
|
|
|
|
RED,
|
|
|
|
MAGENTA,
|
|
|
|
BROWN,
|
|
|
|
LIGHTBLUE,
|
|
|
|
LIGHTGREEN,
|
|
|
|
LIGHTCYAN,
|
|
|
|
LIGHTRED,
|
|
|
|
LIGHTMAGENTA,
|
|
|
|
YELLOW,
|
2013-04-06 12:01:53 +00:00
|
|
|
PUREBLUE,
|
|
|
|
PUREGREEN,
|
|
|
|
PURECYAN,
|
|
|
|
PURERED,
|
2013-04-05 17:23:56 +00:00
|
|
|
PUREMAGENTA,
|
2013-04-06 12:01:53 +00:00
|
|
|
PUREYELLOW,
|
2013-04-04 21:35:01 +00:00
|
|
|
NBCOLORS, ///< Number of colors
|
2012-09-02 12:06:47 +00:00
|
|
|
HIGHLIGHT_FLAG = ( 1<<19 ),
|
2013-04-05 17:23:56 +00:00
|
|
|
MASKCOLOR = 31 ///< mask for color index into g_ColorRefs[]
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
/// Checked cast. Use only when necessary (usually I/O)
|
2012-09-02 12:06:47 +00:00
|
|
|
inline EDA_COLOR_T ColorFromInt( int aColor )
|
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor < NBCOLORS );
|
2012-09-02 12:06:47 +00:00
|
|
|
return static_cast<EDA_COLOR_T>( aColor );
|
|
|
|
}
|
|
|
|
|
2013-04-06 12:01:53 +00:00
|
|
|
inline EDA_COLOR_T NextColor( EDA_COLOR_T& aColor )
|
2013-04-04 21:35:01 +00:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
/// Return only the plain color part
|
|
|
|
inline EDA_COLOR_T ColorGetBase( EDA_COLOR_T aColor)
|
|
|
|
{
|
2013-04-04 21:35:01 +00:00
|
|
|
EDA_COLOR_T base = static_cast<EDA_COLOR_T>( aColor & MASKCOLOR );
|
|
|
|
return base;
|
2012-09-02 12:06:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
/// Mix two colors in some way (hopefully like a logical OR)
|
|
|
|
EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 );
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
2008-04-02 14:16:14 +00:00
|
|
|
|
|
|
|
struct StructColors
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-04-02 14:16:14 +00:00
|
|
|
unsigned char m_Blue;
|
|
|
|
unsigned char m_Green;
|
|
|
|
unsigned char m_Red;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T m_Numcolor;
|
2008-04-02 14:16:14 +00:00
|
|
|
|
|
|
|
const wxChar* m_Name;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T m_LightColor;
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
/// 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
|
2014-01-18 09:07:05 +00:00
|
|
|
EDA_COLOR_T ColorByName( const wxString& aName );
|
2013-04-04 21:35:01 +00:00
|
|
|
|
|
|
|
/// Find the nearest color match
|
|
|
|
EDA_COLOR_T ColorFindNearest( const wxColour &aColor );
|
|
|
|
|
2013-09-11 09:11:27 +00:00
|
|
|
/**
|
|
|
|
* 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 aG is the blue component of the color to be matched (in range 0-255)
|
|
|
|
*/
|
|
|
|
EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB );
|
|
|
|
|
2013-04-09 17:16:53 +00:00
|
|
|
/**
|
|
|
|
* Check if a color is light i.e. if black would be more readable than
|
|
|
|
* white on it
|
|
|
|
*/
|
|
|
|
bool ColorIsLight( EDA_COLOR_T aColor );
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
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_Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-04-02 14:16:14 +00:00
|
|
|
/**
|
|
|
|
* Function MakeColour
|
2011-09-30 18:15:37 +00:00
|
|
|
* returns a wxWidgets wxColor from a KiCad color index with alpha value.
|
2008-04-02 14:16:14 +00:00
|
|
|
* 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. wxGtk 2.8.4 is
|
|
|
|
* not supporting alpha.
|
2011-09-30 18:15:37 +00:00
|
|
|
* @return wxColour - given a KiCad color index with alpha value
|
2008-04-02 14:16:14 +00:00
|
|
|
*/
|
2012-09-02 12:06:47 +00:00
|
|
|
inline wxColour MakeColour( EDA_COLOR_T aColor )
|
2008-04-02 14:16:14 +00:00
|
|
|
{
|
2008-04-14 18:42:33 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,5)
|
2008-04-02 14:16:14 +00:00
|
|
|
int alpha = GetAlpha( aColor );
|
|
|
|
alpha = alpha ? alpha : wxALPHA_OPAQUE;
|
2008-04-14 18:42:33 +00:00
|
|
|
#endif
|
2013-04-04 21:35:01 +00:00
|
|
|
EDA_COLOR_T ndx = ColorGetBase( aColor );
|
|
|
|
wxASSERT( ndx > UNSPECIFIED_COLOR && ndx < NBCOLORS );
|
2008-04-02 14:16:14 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
return wxColour( g_ColorRefs[ndx].m_Red,
|
|
|
|
g_ColorRefs[ndx].m_Green,
|
|
|
|
g_ColorRefs[ndx].m_Blue
|
2008-04-14 18:42:33 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,5)
|
2009-11-23 20:18:47 +00:00
|
|
|
,(unsigned char) alpha
|
2008-04-14 18:42:33 +00:00
|
|
|
#endif
|
2009-11-23 20:18:47 +00:00
|
|
|
);
|
2008-04-02 14:16:14 +00:00
|
|
|
}
|
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#endif // COLORS_H_
|