2009-11-23 20:18:47 +00:00
|
|
|
/************/
|
|
|
|
/* colors.h */
|
|
|
|
/************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifndef _COLORS_H
|
|
|
|
#define _COLORS_H
|
|
|
|
|
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,
|
|
|
|
BLUE,
|
|
|
|
GREEN,
|
|
|
|
CYAN,
|
|
|
|
RED,
|
|
|
|
MAGENTA,
|
|
|
|
BROWN,
|
|
|
|
LIGHTGRAY,
|
|
|
|
DARKGRAY,
|
|
|
|
LIGHTBLUE,
|
|
|
|
LIGHTGREEN,
|
|
|
|
LIGHTCYAN,
|
|
|
|
LIGHTRED,
|
|
|
|
LIGHTMAGENTA,
|
|
|
|
YELLOW,
|
|
|
|
WHITE,
|
|
|
|
DARKDARKGRAY,
|
|
|
|
DARKBLUE,
|
|
|
|
DARKGREEN,
|
|
|
|
DARKCYAN,
|
|
|
|
DARKRED,
|
|
|
|
DARKMAGENTA,
|
|
|
|
DARKBROWN,
|
|
|
|
LIGHTYELLOW,
|
2012-09-02 12:06:47 +00:00
|
|
|
LASTCOLOR,
|
|
|
|
HIGHLIGHT_FLAG = ( 1<<19 ),
|
|
|
|
NBCOLOR = 24, ///< Number of colors
|
|
|
|
MASKCOLOR = 31 ///< mask for color index into ColorRefs[]
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
/// Checked cast. Use only when necessary (ex. I/O)
|
|
|
|
inline EDA_COLOR_T ColorFromInt( int aColor )
|
|
|
|
{
|
|
|
|
wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor < LASTCOLOR );
|
|
|
|
return static_cast<EDA_COLOR_T>( aColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return only the plain color part
|
|
|
|
inline EDA_COLOR_T ColorGetBase( EDA_COLOR_T aColor)
|
|
|
|
{
|
|
|
|
return static_cast<EDA_COLOR_T>( aColor & MASKCOLOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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
|
|
|
};
|
|
|
|
|
2009-07-09 04:54:11 +00:00
|
|
|
// list of existing Colors:
|
2007-05-06 16:03:28 +00:00
|
|
|
extern StructColors ColorRefs[NBCOLOR];
|
|
|
|
|
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
|
2008-04-02 14:16:14 +00:00
|
|
|
int ndx = aColor & MASKCOLOR;
|
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
return wxColour( ColorRefs[ndx].m_Red,
|
|
|
|
ColorRefs[ndx].m_Green,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif /* ifndef _COLORS_H */
|