From 9d395aa0c5c263d76ff3cded5a4267d21eab5d17 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Wed, 2 Apr 2008 14:16:14 +0000 Subject: [PATCH] MAC alpha support --- common/gr_basic.cpp | 128 +++++++++++++++-------------- include/colors.h | 178 +++++++++++++++++++++++++++-------------- pcbnew/class_track.cpp | 4 + 3 files changed, 191 insertions(+), 119 deletions(-) diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index a06d9ca5fa..6a10c4c6c2 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -62,7 +62,7 @@ static inline int USCALE( us arg, us num, us den ) static int inline ZoomValue( int value_to_zoom ) { int zoom = GET_ZOOM; - if( !zoom ) return 0; + if( !zoom ) return 0; if( value_to_zoom >= 0 ) return ( value_to_zoom + (zoom >> 1 ) ) / zoom; @@ -106,14 +106,14 @@ int GRMapY( int y ) /** * Function clip_line * @return bool - true when WHEN_OUTSIDE fires, else false. - */ + */ static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 ) { int temp; if( x1 > x2 ) { - EXCHG( x1, x2 ); + EXCHG( x1, x2 ); EXCHG( y1, y2 ); } 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 ) { temp = USCALE( (y2 - y1), (xcliplo - x1), (x2 - x1) ); - y1 += temp; + y1 += temp; x1 = xcliplo; WHEN_INSIDE; } if( x2 > xcliphi ) { temp = USCALE( (y2 - y1), (x2 - xcliphi), (x2 - x1) ); - y2 -= temp; + y2 -= temp; x2 = xcliphi; WHEN_INSIDE; } @@ -190,19 +190,19 @@ static inline bool clip_line( int& x1, int& y1, int& x2, int& y2 ) if( x1 < xcliplo ) { temp = USCALE( (y1 - y2), (xcliplo - x1), (x2 - x1) ); - y1 -= temp; + y1 -= temp; x1 = xcliplo; WHEN_INSIDE; } if( x2 > xcliphi ) { temp = USCALE( (y1 - y2), (x2 - xcliphi), (x2 - x1) ); - y2 += temp; + y2 += temp; x2 = xcliphi; WHEN_INSIDE; } } - + 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 ) { - Color &= MASKCOLOR; // Pour 32 couleurs Max - if( width < PenMinWidth ) width = PenMinWidth; if( ForceBlackPen && Color != WHITE ) - Color = BLACK; - - if( (lastcolor != Color) || (lastwidth != width) || (s_Last_Pen_Style != style) - || (lastDC != DC ) ) { - wxPen DrawPen; - DrawPen.SetColour( - ColorRefs[Color].m_Red, - ColorRefs[Color].m_Green, - ColorRefs[Color].m_Blue - ); + Color = BLACK; + } - DrawPen.SetWidth( width ); - DrawPen.SetStyle( style ); + if( lastcolor != Color + || 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; } } @@ -337,7 +343,11 @@ void GRMouseWarp( WinEDA_DrawPanel* panel, const wxPoint& pos ) void GRSetDrawMode( wxDC* DC, int draw_mode ) { if( draw_mode & GR_OR ) +#if defined(__WXMAC__) && wxMAC_USE_CORE_GRAPHICS + DC->SetLogicalFunction( wxCOPY ); +#else DC->SetLogicalFunction( wxOR ); +#endif else if( draw_mode & GR_XOR ) DC->SetLogicalFunction( wxXOR ); 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 ); rayon = (width + 1) >> 1; - - dx = x2 - x1; + + dx = x2 - x1; dy = y2 - y1; - + if( dx == 0 ) /* segment vertical */ { dwx = rayon; if( dy >= 0 ) dwx = -dwx; - - sx1 = x1 - dwx; + + sx1 = x1 - dwx; sy1 = y1; - - ex1 = x2 - dwx; + + ex1 = x2 - dwx; ey1 = y2; - + DC->DrawLine( sx1, sy1, ex1, ey1 ); - sx2 = x1 + dwx; + sx2 = x1 + dwx; sy2 = y1; - - ex2 = x2 + dwx; + + ex2 = x2 + dwx; ey2 = y2; - + DC->DrawLine( sx2, sy2, ex2, ey2 ); } 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; if( dx < 0 ) dwy = -dwy; - + sx1 = x1; sy1 = y1 - dwy; - - ex1 = x2; + + ex1 = x2; ey1 = y2 - dwy; - + DC->DrawLine( sx1, sy1, ex1, ey1 ); - sx2 = x1; + sx2 = x1; sy2 = y1 + dwy; - - ex2 = x2; + + ex2 = x2; ey2 = y2 + dwy; - + DC->DrawLine( sx2, sy2, ex2, ey2 ); } else @@ -769,27 +779,27 @@ void GRSCSegm( EDA_Rect* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int else { int delta_angle = ArcTangente( dy, dx ); - dwx = 0; + dwx = 0; dwy = width; RotatePoint( &dwx, &dwy, -delta_angle ); } - dwx2 = dwx >> 1; + dwx2 = dwx >> 1; dwy2 = dwy >> 1; - - sx1 = x1 - dwx2; + + sx1 = x1 - dwx2; sy1 = y1 - dwy2; - - ex1 = x2 - dwx2; + + ex1 = x2 - dwx2; ey1 = y2 - dwy2; - + DC->DrawLine( sx1, sy1, ex1, ey1 ); - sx2 = x1 + dwx2; + sx2 = x1 + dwx2; sy2 = y1 + dwy2; - - ex2 = x2 + dwx2; + + ex2 = x2 + dwx2; ey2 = y2 + dwy2; - + DC->DrawLine( sx2, sy2, ex2, ey2 ); } @@ -861,7 +871,9 @@ void GRSPoly( EDA_Rect* ClipBox, wxDC* DC, int n, int* Points, int Fill, } else { - startx = Points[n * 2 - 2]; starty = Points[n * 2 - 1]; + startx = Points[n * 2 - 2]; + starty = Points[n * 2 - 1]; + GRSetBrush( DC, Color ); DC->DrawLines( n, (wxPoint*) Points ); } diff --git a/include/colors.h b/include/colors.h index 239a163463..686c989166 100644 --- a/include/colors.h +++ b/include/colors.h @@ -10,81 +10,137 @@ #endif /* Definitions des Numeros des Couleurs ( palette de 32) */ -#define NBCOLOR 32 -#define MASKCOLOR 31 // masque pour bits significatifs +#define NBCOLOR 32 + +#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 { - 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, -LASTCOLOR + 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, + LASTCOLOR }; -class StructColors + +struct StructColors { -public: - unsigned char m_Blue, m_Green, m_Red, m_Numcolor; - const wxChar* m_Name; - int m_LightColor; + unsigned char m_Blue; + unsigned char m_Green; + unsigned char m_Red; + unsigned char m_Numcolor; + + const wxChar* m_Name; + int m_LightColor; }; + extern StructColors ColorRefs[NBCOLOR]; #ifdef MAIN -StructColors ColorRefs[NBCOLOR] = +StructColors ColorRefs[NBCOLOR] = { - { 0, 0, 0, BLACK, wxT("BLACK"), DARKDARKGRAY}, - { 192, 0, 0, BLUE, wxT("BLUE"), LIGHTBLUE}, - { 0, 160, 0, GREEN, wxT("GREEN"), LIGHTGREEN }, - { 160, 160, 0, CYAN, wxT("CYAN"), LIGHTCYAN }, - { 0, 0, 160, RED, wxT("RED"), LIGHTRED }, - { 160, 0, 160, MAGENTA, wxT("MAGENTA"), LIGHTMAGENTA }, - { 0, 128, 128, BROWN, wxT("BROWN"), YELLOW }, - { 192, 192, 192, LIGHTGRAY, wxT("GRAY"), WHITE }, - { 128, 128, 128, DARKGRAY, wxT("DARKGRAY"), LIGHTGRAY }, - { 255, 0, 0, LIGHTBLUE, wxT("LIGHTBLUE"), LIGHTBLUE }, - { 0, 255, 0, LIGHTGREEN, wxT("LIGHTGREEN"), LIGHTGREEN }, - { 255, 255, 0, LIGHTCYAN, wxT("LIGHTCYAN"), LIGHTCYAN }, - { 0, 0, 255, LIGHTRED, wxT("LIGHTRED"), LIGHTRED }, - { 255, 0, 255, LIGHTMAGENTA, wxT("LIGHTMAGENTA"), LIGHTMAGENTA }, - { 0, 255, 255, YELLOW, wxT("YELLOW"), YELLOW }, - { 255, 255, 255, WHITE, wxT("WHITE"), WHITE }, - { 64, 64, 64, DARKDARKGRAY, wxT("DARKDARKGRAY"), DARKGRAY }, - { 64, 0, 0, DARKBLUE, wxT("DARKBLUE"), BLUE }, - { 0, 64, 0, DARKGREEN, wxT("DARKGREEN"), GREEN }, - { 64, 64, 0, DARKCYAN, wxT("DARKCYAN"), CYAN }, - { 0, 0, 80, DARKRED, wxT("DARKRED"), RED }, - { 64, 0, 64, DARKMAGENTA, wxT("DARKMAGENTA"), MAGENTA }, - { 0, 64, 64, DARKBROWN, wxT("DARKBROWN"), BROWN }, - { 128, 255, 255, LIGHTYELLOW, wxT("LIGHTYELLOW"), LIGHTYELLOW } + { 0, 0, 0, BLACK, wxT("BLACK"), DARKDARKGRAY}, + { 192, 0, 0, BLUE, wxT("BLUE"), LIGHTBLUE}, + { 0, 160, 0, GREEN, wxT("GREEN"), LIGHTGREEN }, + { 160, 160, 0, CYAN, wxT("CYAN"), LIGHTCYAN }, + { 0, 0, 160, RED, wxT("RED"), LIGHTRED }, + { 160, 0, 160, MAGENTA, wxT("MAGENTA"), LIGHTMAGENTA }, + { 0, 128, 128, BROWN, wxT("BROWN"), YELLOW }, + { 192, 192, 192, LIGHTGRAY, wxT("GRAY"), WHITE }, + { 128, 128, 128, DARKGRAY, wxT("DARKGRAY"), LIGHTGRAY }, + { 255, 0, 0, LIGHTBLUE, wxT("LIGHTBLUE"), LIGHTBLUE }, + { 0, 255, 0, LIGHTGREEN, wxT("LIGHTGREEN"), LIGHTGREEN }, + { 255, 255, 0, LIGHTCYAN, wxT("LIGHTCYAN"), LIGHTCYAN }, + { 0, 0, 255, LIGHTRED, wxT("LIGHTRED"), LIGHTRED }, + { 255, 0, 255, LIGHTMAGENTA, wxT("LIGHTMAGENTA"), LIGHTMAGENTA }, + { 0, 255, 255, YELLOW, wxT("YELLOW"), YELLOW }, + { 255, 255, 255, WHITE, wxT("WHITE"), WHITE }, + { 64, 64, 64, DARKDARKGRAY, wxT("DARKDARKGRAY"), DARKGRAY }, + { 64, 0, 0, DARKBLUE, wxT("DARKBLUE"), BLUE }, + { 0, 64, 0, DARKGREEN, wxT("DARKGREEN"), GREEN }, + { 64, 64, 0, DARKCYAN, wxT("DARKCYAN"), CYAN }, + { 0, 0, 80, DARKRED, wxT("DARKRED"), RED }, + { 64, 0, 64, DARKMAGENTA, wxT("DARKMAGENTA"), MAGENTA }, + { 0, 64, 64, DARKBROWN, wxT("DARKBROWN"), BROWN }, + { 128, 255, 255, LIGHTYELLOW, wxT("LIGHTYELLOW"), LIGHTYELLOW } }; #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 */ diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 05351e0237..6aef4e82d5 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -670,9 +670,12 @@ void TRACK::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoin else color |= HIGHT_LIGHT_FLAG; } + if( color & HIGHT_LIGHT_FLAG ) color = ColorRefs[color & MASKCOLOR].m_LightColor; + SetAlpha( &color, 150 ); + zoom = panel->GetZoom(); 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; if( rayon < zoom ) rayon = zoom; + GRCircle( &panel->m_ClipBox, DC, m_Start.x, m_Start.y, rayon, color ); if( rayon > (4 * zoom) ) {