MAC alpha support

This commit is contained in:
dickelbeck 2008-04-02 14:16:14 +00:00
parent 1a063f6a78
commit 9d395aa0c5
3 changed files with 191 additions and 119 deletions

View File

@ -62,7 +62,7 @@ static inline int USCALE( us arg, us num, us den )
static int inline ZoomValue( int value_to_zoom ) { static int inline ZoomValue( int value_to_zoom ) {
int zoom = GET_ZOOM; int zoom = GET_ZOOM;
if( !zoom ) return 0; if( !zoom ) return 0;
if( value_to_zoom >= 0 ) if( value_to_zoom >= 0 )
return ( value_to_zoom + (zoom >> 1 ) ) / zoom; return ( value_to_zoom + (zoom >> 1 ) ) / zoom;
@ -106,14 +106,14 @@ int GRMapY( int y )
/** /**
* Function clip_line * Function clip_line
* @return bool - true when WHEN_OUTSIDE fires, else false. * @return bool - true when WHEN_OUTSIDE fires, else false.
*/ */
static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 ) static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 )
{ {
int temp; int temp;
if( x1 > x2 ) if( x1 > x2 )
{ {
EXCHG( x1, x2 ); EXCHG( x1, x2 );
EXCHG( y1, y2 ); EXCHG( y1, y2 );
} }
if( (x2 < xcliplo) || (x1 > xcliphi) ) if( (x2 < xcliplo) || (x1 > xcliphi) )
@ -149,14 +149,14 @@ static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 )
if( x1 < xcliplo ) if( x1 < xcliplo )
{ {
temp = USCALE( (y2 - y1), (xcliplo - x1), (x2 - x1) ); temp = USCALE( (y2 - y1), (xcliplo - x1), (x2 - x1) );
y1 += temp; y1 += temp;
x1 = xcliplo; x1 = xcliplo;
WHEN_INSIDE; WHEN_INSIDE;
} }
if( x2 > xcliphi ) if( x2 > xcliphi )
{ {
temp = USCALE( (y2 - y1), (x2 - xcliphi), (x2 - x1) ); temp = USCALE( (y2 - y1), (x2 - xcliphi), (x2 - x1) );
y2 -= temp; y2 -= temp;
x2 = xcliphi; x2 = xcliphi;
WHEN_INSIDE; WHEN_INSIDE;
} }
@ -190,19 +190,19 @@ static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 )
if( x1 < xcliplo ) if( x1 < xcliplo )
{ {
temp = USCALE( (y1 - y2), (xcliplo - x1), (x2 - x1) ); temp = USCALE( (y1 - y2), (xcliplo - x1), (x2 - x1) );
y1 -= temp; y1 -= temp;
x1 = xcliplo; x1 = xcliplo;
WHEN_INSIDE; WHEN_INSIDE;
} }
if( x2 > xcliphi ) if( x2 > xcliphi )
{ {
temp = USCALE( (y1 - y2), (x2 - xcliphi), (x2 - x1) ); temp = USCALE( (y1 - y2), (x2 - xcliphi), (x2 - x1) );
y2 += temp; y2 += temp;
x2 = xcliphi; x2 = xcliphi;
WHEN_INSIDE; WHEN_INSIDE;
} }
} }
return false; return false;
} }
@ -257,33 +257,39 @@ void SetPenMinWidth( int minwidth )
} }
/* Routine de changement de couleurs et epaisseur de la plume courante */ /**
* Function GRSetColorPen
* sets a pen style, width, color, and alpha into the given device context.
*/
void GRSetColorPen( wxDC* DC, int Color, int width, int style ) void GRSetColorPen( wxDC* DC, int Color, int width, int style )
{ {
Color &= MASKCOLOR; // Pour 32 couleurs Max
if( width < PenMinWidth ) if( width < PenMinWidth )
width = PenMinWidth; width = PenMinWidth;
if( ForceBlackPen && Color != WHITE ) if( ForceBlackPen && Color != WHITE )
Color = BLACK;
if( (lastcolor != Color) || (lastwidth != width) || (s_Last_Pen_Style != style)
|| (lastDC != DC ) )
{ {
wxPen DrawPen; Color = BLACK;
DrawPen.SetColour( }
ColorRefs[Color].m_Red,
ColorRefs[Color].m_Green,
ColorRefs[Color].m_Blue
);
DrawPen.SetWidth( width ); if( lastcolor != Color
DrawPen.SetStyle( style ); || lastwidth != width
|| s_Last_Pen_Style != style
|| lastDC != DC )
{
wxPen pen;
wxColour wx_color = MakeColour( Color );
pen.SetColour( wx_color );
pen.SetWidth( width );
pen.SetStyle( style );
DC->SetPen( pen );
lastcolor = Color;
lastwidth = width;
lastDC = DC;
// if ( &DC->GetPen() != DrawPen )
DC->SetPen( DrawPen );
lastcolor = Color; lastwidth = width; lastDC = DC;
s_Last_Pen_Style = style; s_Last_Pen_Style = style;
} }
} }
@ -337,7 +343,11 @@ void GRMouseWarp( WinEDA_DrawPanel* panel, const wxPoint& pos )
void GRSetDrawMode( wxDC* DC, int draw_mode ) void GRSetDrawMode( wxDC* DC, int draw_mode )
{ {
if( draw_mode & GR_OR ) if( draw_mode & GR_OR )
#if defined(__WXMAC__) && wxMAC_USE_CORE_GRAPHICS
DC->SetLogicalFunction( wxCOPY );
#else
DC->SetLogicalFunction( wxOR ); DC->SetLogicalFunction( wxOR );
#endif
else if( draw_mode & GR_XOR ) else if( draw_mode & GR_XOR )
DC->SetLogicalFunction( wxXOR ); DC->SetLogicalFunction( wxXOR );
else if( draw_mode & GR_NXOR ) else if( draw_mode & GR_NXOR )
@ -698,30 +708,30 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int
GRSetBrush( DC, Color, FALSE ); GRSetBrush( DC, Color, FALSE );
rayon = (width + 1) >> 1; rayon = (width + 1) >> 1;
dx = x2 - x1; dx = x2 - x1;
dy = y2 - y1; dy = y2 - y1;
if( dx == 0 ) /* segment vertical */ if( dx == 0 ) /* segment vertical */
{ {
dwx = rayon; dwx = rayon;
if( dy >= 0 ) if( dy >= 0 )
dwx = -dwx; dwx = -dwx;
sx1 = x1 - dwx; sx1 = x1 - dwx;
sy1 = y1; sy1 = y1;
ex1 = x2 - dwx; ex1 = x2 - dwx;
ey1 = y2; ey1 = y2;
DC->DrawLine( sx1, sy1, ex1, ey1 ); DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1 + dwx; sx2 = x1 + dwx;
sy2 = y1; sy2 = y1;
ex2 = x2 + dwx; ex2 = x2 + dwx;
ey2 = y2; ey2 = y2;
DC->DrawLine( sx2, sy2, ex2, ey2 ); DC->DrawLine( sx2, sy2, ex2, ey2 );
} }
else if( dy == 0 ) /* segment horizontal */ else if( dy == 0 ) /* segment horizontal */
@ -729,21 +739,21 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int
dwy = rayon; dwy = rayon;
if( dx < 0 ) if( dx < 0 )
dwy = -dwy; dwy = -dwy;
sx1 = x1; sx1 = x1;
sy1 = y1 - dwy; sy1 = y1 - dwy;
ex1 = x2; ex1 = x2;
ey1 = y2 - dwy; ey1 = y2 - dwy;
DC->DrawLine( sx1, sy1, ex1, ey1 ); DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1; sx2 = x1;
sy2 = y1 + dwy; sy2 = y1 + dwy;
ex2 = x2; ex2 = x2;
ey2 = y2 + dwy; ey2 = y2 + dwy;
DC->DrawLine( sx2, sy2, ex2, ey2 ); DC->DrawLine( sx2, sy2, ex2, ey2 );
} }
else else
@ -769,27 +779,27 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int
else else
{ {
int delta_angle = ArcTangente( dy, dx ); int delta_angle = ArcTangente( dy, dx );
dwx = 0; dwx = 0;
dwy = width; dwy = width;
RotatePoint( &dwx, &dwy, -delta_angle ); RotatePoint( &dwx, &dwy, -delta_angle );
} }
dwx2 = dwx >> 1; dwx2 = dwx >> 1;
dwy2 = dwy >> 1; dwy2 = dwy >> 1;
sx1 = x1 - dwx2; sx1 = x1 - dwx2;
sy1 = y1 - dwy2; sy1 = y1 - dwy2;
ex1 = x2 - dwx2; ex1 = x2 - dwx2;
ey1 = y2 - dwy2; ey1 = y2 - dwy2;
DC->DrawLine( sx1, sy1, ex1, ey1 ); DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1 + dwx2; sx2 = x1 + dwx2;
sy2 = y1 + dwy2; sy2 = y1 + dwy2;
ex2 = x2 + dwx2; ex2 = x2 + dwx2;
ey2 = y2 + dwy2; ey2 = y2 + dwy2;
DC->DrawLine( sx2, sy2, ex2, ey2 ); DC->DrawLine( sx2, sy2, ex2, ey2 );
} }
@ -861,7 +871,9 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, int Fill,
} }
else else
{ {
startx = Points[n * 2 - 2]; starty = Points[n * 2 - 1]; startx = Points[n * 2 - 2];
starty = Points[n * 2 - 1];
GRSetBrush( DC, Color ); GRSetBrush( DC, Color );
DC->DrawLines( n, (wxPoint*) Points ); DC->DrawLines( n, (wxPoint*) Points );
} }

View File

@ -10,81 +10,137 @@
#endif #endif
/* Definitions des Numeros des Couleurs ( palette de 32) */ /* Definitions des Numeros des Couleurs ( palette de 32) */
#define NBCOLOR 32 #define NBCOLOR 32
#define MASKCOLOR 31 // masque pour bits significatifs
#define MASKCOLOR 31 ///< mask for color index into ColorRefs[]
/// bit indicateur d'affichage (vu / non vu) des items : (defini dans les valeurs des couleurs
#define ITEM_NOT_SHOW (1<<18) // 0x40000
/// Definition du bit de surbrillance
#define HIGHT_LIGHT_FLAG (1<<19) // 0x80000
/**
* Function SetAlpha
* ORs in the alpha blend parameter in to a color index.
*/
static inline void SetAlpha( int* aColor, int aBlend )
{
const int MASKALPHA = 0xFF;
*aColor = (*aColor & ~(MASKALPHA << 24)) | ((aBlend & MASKALPHA) << 24);
}
/**
* Function GetAlpha
* returns the alpha blend parameter from a color index.
*/
static inline int GetAlpha( int aColor )
{
const int MASKALPHA = 0xFF;
return (aColor >> 24) & MASKALPHA;
}
/* bit indicateur d'affichage (vu / non vu) des items : (defini dans les valeurs des couleurs*/
#define ITEM_NOT_SHOW 0x40000
/* Definition du bit de surbrillance */
#define HIGHT_LIGHT_FLAG 0x80000
enum EDA_Colors enum EDA_Colors
{ {
BLACK = 0, BLACK = 0,
BLUE, BLUE,
GREEN, GREEN,
CYAN, CYAN,
RED, RED,
MAGENTA, MAGENTA,
BROWN, BROWN,
LIGHTGRAY, LIGHTGRAY,
DARKGRAY, DARKGRAY,
LIGHTBLUE, LIGHTBLUE,
LIGHTGREEN, LIGHTGREEN,
LIGHTCYAN, LIGHTCYAN,
LIGHTRED, LIGHTRED,
LIGHTMAGENTA, LIGHTMAGENTA,
YELLOW, YELLOW,
WHITE, WHITE,
DARKDARKGRAY, DARKDARKGRAY,
DARKBLUE, DARKBLUE,
DARKGREEN, DARKGREEN,
DARKCYAN, DARKCYAN,
DARKRED, DARKRED,
DARKMAGENTA, DARKMAGENTA,
DARKBROWN, DARKBROWN,
LIGHTYELLOW, LIGHTYELLOW,
LASTCOLOR LASTCOLOR
}; };
class StructColors
struct StructColors
{ {
public: unsigned char m_Blue;
unsigned char m_Blue, m_Green, m_Red, m_Numcolor; unsigned char m_Green;
const wxChar* m_Name; unsigned char m_Red;
int m_LightColor; unsigned char m_Numcolor;
const wxChar* m_Name;
int m_LightColor;
}; };
extern StructColors ColorRefs[NBCOLOR]; extern StructColors ColorRefs[NBCOLOR];
#ifdef MAIN #ifdef MAIN
StructColors ColorRefs[NBCOLOR] = StructColors ColorRefs[NBCOLOR] =
{ {
{ 0, 0, 0, BLACK, wxT("BLACK"), DARKDARKGRAY}, { 0, 0, 0, BLACK, wxT("BLACK"), DARKDARKGRAY},
{ 192, 0, 0, BLUE, wxT("BLUE"), LIGHTBLUE}, { 192, 0, 0, BLUE, wxT("BLUE"), LIGHTBLUE},
{ 0, 160, 0, GREEN, wxT("GREEN"), LIGHTGREEN }, { 0, 160, 0, GREEN, wxT("GREEN"), LIGHTGREEN },
{ 160, 160, 0, CYAN, wxT("CYAN"), LIGHTCYAN }, { 160, 160, 0, CYAN, wxT("CYAN"), LIGHTCYAN },
{ 0, 0, 160, RED, wxT("RED"), LIGHTRED }, { 0, 0, 160, RED, wxT("RED"), LIGHTRED },
{ 160, 0, 160, MAGENTA, wxT("MAGENTA"), LIGHTMAGENTA }, { 160, 0, 160, MAGENTA, wxT("MAGENTA"), LIGHTMAGENTA },
{ 0, 128, 128, BROWN, wxT("BROWN"), YELLOW }, { 0, 128, 128, BROWN, wxT("BROWN"), YELLOW },
{ 192, 192, 192, LIGHTGRAY, wxT("GRAY"), WHITE }, { 192, 192, 192, LIGHTGRAY, wxT("GRAY"), WHITE },
{ 128, 128, 128, DARKGRAY, wxT("DARKGRAY"), LIGHTGRAY }, { 128, 128, 128, DARKGRAY, wxT("DARKGRAY"), LIGHTGRAY },
{ 255, 0, 0, LIGHTBLUE, wxT("LIGHTBLUE"), LIGHTBLUE }, { 255, 0, 0, LIGHTBLUE, wxT("LIGHTBLUE"), LIGHTBLUE },
{ 0, 255, 0, LIGHTGREEN, wxT("LIGHTGREEN"), LIGHTGREEN }, { 0, 255, 0, LIGHTGREEN, wxT("LIGHTGREEN"), LIGHTGREEN },
{ 255, 255, 0, LIGHTCYAN, wxT("LIGHTCYAN"), LIGHTCYAN }, { 255, 255, 0, LIGHTCYAN, wxT("LIGHTCYAN"), LIGHTCYAN },
{ 0, 0, 255, LIGHTRED, wxT("LIGHTRED"), LIGHTRED }, { 0, 0, 255, LIGHTRED, wxT("LIGHTRED"), LIGHTRED },
{ 255, 0, 255, LIGHTMAGENTA, wxT("LIGHTMAGENTA"), LIGHTMAGENTA }, { 255, 0, 255, LIGHTMAGENTA, wxT("LIGHTMAGENTA"), LIGHTMAGENTA },
{ 0, 255, 255, YELLOW, wxT("YELLOW"), YELLOW }, { 0, 255, 255, YELLOW, wxT("YELLOW"), YELLOW },
{ 255, 255, 255, WHITE, wxT("WHITE"), WHITE }, { 255, 255, 255, WHITE, wxT("WHITE"), WHITE },
{ 64, 64, 64, DARKDARKGRAY, wxT("DARKDARKGRAY"), DARKGRAY }, { 64, 64, 64, DARKDARKGRAY, wxT("DARKDARKGRAY"), DARKGRAY },
{ 64, 0, 0, DARKBLUE, wxT("DARKBLUE"), BLUE }, { 64, 0, 0, DARKBLUE, wxT("DARKBLUE"), BLUE },
{ 0, 64, 0, DARKGREEN, wxT("DARKGREEN"), GREEN }, { 0, 64, 0, DARKGREEN, wxT("DARKGREEN"), GREEN },
{ 64, 64, 0, DARKCYAN, wxT("DARKCYAN"), CYAN }, { 64, 64, 0, DARKCYAN, wxT("DARKCYAN"), CYAN },
{ 0, 0, 80, DARKRED, wxT("DARKRED"), RED }, { 0, 0, 80, DARKRED, wxT("DARKRED"), RED },
{ 64, 0, 64, DARKMAGENTA, wxT("DARKMAGENTA"), MAGENTA }, { 64, 0, 64, DARKMAGENTA, wxT("DARKMAGENTA"), MAGENTA },
{ 0, 64, 64, DARKBROWN, wxT("DARKBROWN"), BROWN }, { 0, 64, 64, DARKBROWN, wxT("DARKBROWN"), BROWN },
{ 128, 255, 255, LIGHTYELLOW, wxT("LIGHTYELLOW"), LIGHTYELLOW } { 128, 255, 255, LIGHTYELLOW, wxT("LIGHTYELLOW"), LIGHTYELLOW }
}; };
#endif /* ifdef MAIN */ #endif /* ifdef MAIN */
/**
* 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. wxGtk 2.8.4 is
* not supporting alpha.
* @return wxColour - given a KICAD color index with alpha value
*/
static inline wxColour MakeColour( int aColor )
{
int alpha = GetAlpha( aColor );
alpha = alpha ? alpha : wxALPHA_OPAQUE;
int ndx = aColor & MASKCOLOR;
return wxColour(
ColorRefs[ndx].m_Red,
ColorRefs[ndx].m_Green,
ColorRefs[ndx].m_Blue,
(unsigned char) alpha
);
}
#endif /* ifndef _COLORS_H */ #endif /* ifndef _COLORS_H */

View File

@ -670,9 +670,12 @@ void TRACK::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoin
else else
color |= HIGHT_LIGHT_FLAG; color |= HIGHT_LIGHT_FLAG;
} }
if( color & HIGHT_LIGHT_FLAG ) if( color & HIGHT_LIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor; color = ColorRefs[color & MASKCOLOR].m_LightColor;
SetAlpha( &color, 150 );
zoom = panel->GetZoom(); zoom = panel->GetZoom();
l_piste = m_Width >> 1; l_piste = m_Width >> 1;
@ -682,6 +685,7 @@ void TRACK::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoin
rayon = l_piste; rayon = l_piste;
if( rayon < zoom ) if( rayon < zoom )
rayon = zoom; rayon = zoom;
GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color ); GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color );
if( rayon > (4 * zoom) ) if( rayon > (4 * zoom) )
{ {