From 89b1fdabe9c9c3508bd5e087aa2308458f7029e4 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 26 Jul 2021 13:28:37 -0400 Subject: [PATCH] Pass COLOR4D object by reference instead of on the stack. --- 3d-viewer/3d_canvas/board_adapter.cpp | 2 +- 3d-viewer/3d_canvas/board_adapter.h | 4 +- common/bitmap_base.cpp | 2 +- common/eda_text.cpp | 2 +- common/gal/color4d.cpp | 161 ++++++------- common/gr_basic.cpp | 259 +++++++-------------- common/gr_text.cpp | 19 +- common/preview_items/preview_utils.cpp | 4 +- common/settings/color_settings.cpp | 2 +- common/widgets/layer_box_selector.cpp | 3 +- gerbview/am_primitive.cpp | 2 +- gerbview/am_primitive.h | 2 +- gerbview/gerber_draw_item.cpp | 2 +- gerbview/gerber_draw_item.h | 3 +- gerbview/gerbview_frame.cpp | 7 +- gerbview/gerbview_frame.h | 6 +- gerbview/widgets/gerbview_layer_widget.cpp | 4 +- gerbview/widgets/gerbview_layer_widget.h | 4 +- gerbview/widgets/layer_widget.cpp | 34 +-- gerbview/widgets/layer_widget.h | 10 +- include/bitmap_base.h | 2 +- include/eda_draw_frame.h | 6 +- include/eda_text.h | 2 +- include/gal/color4d.h | 2 +- include/gr_basic.h | 79 ++++--- include/gr_text.h | 8 +- include/pcb_base_frame.h | 9 +- include/preview_items/preview_utils.h | 27 +-- include/settings/color_settings.h | 2 +- include/widgets/layer_box_selector.h | 3 +- pcbnew/pcb_base_frame.cpp | 2 +- pcbnew/pcb_edit_frame.cpp | 2 +- pcbnew/pcb_edit_frame.h | 4 +- pcbnew/pcbplot.h | 4 +- pcbnew/plot_brditems_plotter.cpp | 12 +- 35 files changed, 316 insertions(+), 380 deletions(-) diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index e6927e8457..556d46f10a 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -546,7 +546,7 @@ SFVEC4F BOARD_ADAPTER::GetItemColor( int aItemId ) const } -SFVEC4F BOARD_ADAPTER::GetColor( COLOR4D aColor ) const +SFVEC4F BOARD_ADAPTER::GetColor( const COLOR4D& aColor ) const { return SFVEC4F( aColor.r, aColor.g, aColor.b, aColor.a ); } diff --git a/3d-viewer/3d_canvas/board_adapter.h b/3d-viewer/3d_canvas/board_adapter.h index d7ce10552b..62de17e4ca 100644 --- a/3d-viewer/3d_canvas/board_adapter.h +++ b/3d-viewer/3d_canvas/board_adapter.h @@ -339,10 +339,10 @@ public: SFVEC4F GetItemColor( int aItemId ) const; /** - * @param aColor the color mapped. + * @param[in] aColor is the color mapped. * @return the color in SFVEC3F format */ - SFVEC4F GetColor( COLOR4D aColor ) const; + SFVEC4F GetColor( const COLOR4D& aColor ) const; /** * Get the top z position. diff --git a/common/bitmap_base.cpp b/common/bitmap_base.cpp index 3d4d61b000..8c5bb384c7 100644 --- a/common/bitmap_base.cpp +++ b/common/bitmap_base.cpp @@ -331,7 +331,7 @@ void BITMAP_BASE::Rotate( bool aRotateCCW ) void BITMAP_BASE::PlotImage( PLOTTER* aPlotter, const wxPoint& aPos, - COLOR4D aDefaultColor, + const COLOR4D& aDefaultColor, int aDefaultPensize ) const { if( m_image == nullptr ) diff --git a/common/eda_text.cpp b/common/eda_text.cpp index b6f07f6bc5..a261e828cb 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -405,7 +405,7 @@ bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy void EDA_TEXT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, - COLOR4D aColor, OUTLINE_MODE aFillMode ) + const COLOR4D& aColor, OUTLINE_MODE aFillMode ) { if( IsMultilineAllowed() ) { diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index 771d1a537c..be50762333 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright 2012 Torsten Hueter, torstenhtr gmx.de - * Copyright 2017-2019 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright 2017-2021 Kicad Developers, see AUTHORS.txt for contributors. * * * This program is free software; you can redistribute it and/or @@ -108,89 +108,86 @@ COLOR4D::COLOR4D( EDA_COLOR_T aColor ) #ifdef WX_COMPATIBILITY - COLOR4D::COLOR4D( const wxColour& aColor ) +COLOR4D::COLOR4D( const wxColour& aColor ) +{ + r = aColor.Red() / 255.0; + g = aColor.Green() / 255.0; + b = aColor.Blue() / 255.0; + a = aColor.Alpha() / 255.0; +} + + +bool COLOR4D::SetFromWxString( const wxString& aColorString ) +{ + wxColour c; + + if( c.Set( aColorString ) ) { - r = aColor.Red() / 255.0; - g = aColor.Green() / 255.0; - b = aColor.Blue() / 255.0; - a = aColor.Alpha() / 255.0; - } - - - bool COLOR4D::SetFromWxString( const wxString& aColorString ) - { - wxColour c; - - if( c.Set( aColorString ) ) - { - r = c.Red() / 255.0; - g = c.Green() / 255.0; - b = c.Blue() / 255.0; - a = c.Alpha() / 255.0; - - return true; - } - - return false; - } - - - wxString COLOR4D::ToWxString( long flags ) const - { - wxColour c = ToColour(); - return c.GetAsString( flags ); - } - - - wxColour COLOR4D::ToColour() const - { - using CHAN_T = wxColourBase::ChannelType; - - const wxColour colour( - static_cast( r * 255 + 0.5 ), - static_cast( g * 255 + 0.5 ), - static_cast( b * 255 + 0.5 ), - static_cast( a * 255 + 0.5 ) - ); - return colour; - } - - - COLOR4D COLOR4D::LegacyMix( COLOR4D aColor ) const - { - COLOR4D candidate; - - // Blend the two colors (i.e. OR the RGB values) - candidate.r = ( (unsigned)( 255.0 * r ) | (unsigned)( 255.0 * aColor.r ) ) / 255.0, - candidate.g = ( (unsigned)( 255.0 * g ) | (unsigned)( 255.0 * aColor.g ) ) / 255.0, - candidate.b = ( (unsigned)( 255.0 * b ) | (unsigned)( 255.0 * aColor.b ) ) / 255.0, - - // the alpha channel can be reinitialized - // but what is the best value? - candidate.a = ( aColor.a + a ) / 2; - - return candidate; - } - - - unsigned int COLOR4D::ToU32() const - { - return ToColour().GetRGB(); - } - - - void COLOR4D::FromU32( unsigned int aPackedColor ) - { - wxColour c; - c.SetRGB( aPackedColor ); r = c.Red() / 255.0; g = c.Green() / 255.0; b = c.Blue() / 255.0; a = c.Alpha() / 255.0; + + return true; } + return false; +} + + +wxString COLOR4D::ToWxString( long flags ) const +{ + wxColour c = ToColour(); + return c.GetAsString( flags ); +} + + +wxColour COLOR4D::ToColour() const +{ + using CHAN_T = wxColourBase::ChannelType; + + const wxColour colour( + static_cast( r * 255 + 0.5 ), static_cast( g * 255 + 0.5 ), + static_cast( b * 255 + 0.5 ), static_cast( a * 255 + 0.5 ) ); + return colour; +} + + +COLOR4D COLOR4D::LegacyMix( const COLOR4D& aColor ) const +{ + COLOR4D candidate; + + // Blend the two colors (i.e. OR the RGB values) + candidate.r = ( (unsigned) ( 255.0 * r ) | (unsigned) ( 255.0 * aColor.r ) ) / 255.0, + candidate.g = ( (unsigned) ( 255.0 * g ) | (unsigned) ( 255.0 * aColor.g ) ) / 255.0, + candidate.b = ( (unsigned) ( 255.0 * b ) | (unsigned) ( 255.0 * aColor.b ) ) / 255.0, + + // the alpha channel can be reinitialized but what is the best value? + candidate.a = ( aColor.a + a ) / 2; + + return candidate; +} + + +unsigned int COLOR4D::ToU32() const +{ + return ToColour().GetRGB(); +} + + +void COLOR4D::FromU32( unsigned int aPackedColor ) +{ + wxColour c; + c.SetRGB( aPackedColor ); + r = c.Red() / 255.0; + g = c.Green() / 255.0; + b = c.Blue() / 255.0; + a = c.Alpha() / 255.0; +} + #endif + namespace KIGFX { const bool operator==( const COLOR4D& lhs, const COLOR4D& rhs ) @@ -204,6 +201,7 @@ const bool operator!=( const COLOR4D& lhs, const COLOR4D& rhs ) return !( lhs == rhs ); } + const bool operator<( const COLOR4D& lhs, const COLOR4D& rhs ) { if( lhs.r < rhs.r ) @@ -218,11 +216,13 @@ const bool operator<( const COLOR4D& lhs, const COLOR4D& rhs ) return false; } + std::ostream &operator<<( std::ostream &aStream, COLOR4D const &aColor ) { return aStream << aColor.ToWxString( wxC2S_CSS_SYNTAX ); } + void to_json( nlohmann::json& aJson, const COLOR4D& aColor ) { aJson = nlohmann::json( aColor.ToWxString( wxC2S_CSS_SYNTAX ).ToStdString() ); @@ -309,7 +309,8 @@ void COLOR4D::FromHSL( double aInHue, double aInSaturation, double aInLightness } -void COLOR4D::ToHSV( double& aOutHue, double& aOutSaturation, double& aOutValue, bool aAlwaysDefineHue ) const +void COLOR4D::ToHSV( double& aOutHue, double& aOutSaturation, double& aOutValue, + bool aAlwaysDefineHue ) const { double min, max, delta; @@ -450,6 +451,7 @@ COLOR4D& COLOR4D::Saturate( double aFactor ) return *this; } + const COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 ); const COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 ); const COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 ); @@ -477,9 +479,9 @@ EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB ) trying = static_cast( int( trying ) + 1 ) ) { const StructColors &c = 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); + 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 ) @@ -492,6 +494,7 @@ EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB ) return candidate; } + COLOR4D& COLOR4D::FromCSSRGBA( int aRed, int aGreen, int aBlue, double aAlpha ) { r = std::max( 0, std::min( 255, aRed ) ) / 255.0; diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index b4c4d984f6..70230e5dbe 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -19,11 +19,6 @@ * with this program. If not, see . */ -/********************************/ -/* Low level graphics routines */ -/********************************/ - - #include #include #include @@ -77,7 +72,7 @@ static void ClipAndDrawPoly( EDA_RECT* ClipBox, wxDC* DC, const wxPoint* Points, * from user units to screen units(pixels coordinates) */ static void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, - int x2, int y2, int aWidth, COLOR4D aColor, + int x2, int y2, int aWidth, const COLOR4D& aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); /**/ @@ -113,9 +108,6 @@ static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int } -/* Forcing a reset of the current pen. - * Must be called after changing the graphical device before any trace. - */ void GRResetPenAndBrush( wxDC* DC ) { GRSetBrush( DC, BLACK ); // Force no fill @@ -125,11 +117,10 @@ void GRResetPenAndBrush( wxDC* DC ) } -/** - * Set a pen style, width, color, and alpha into the given device context. - */ -void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) +void GRSetColorPen( wxDC* DC, const COLOR4D& Color, int width, wxPenStyle style ) { + COLOR4D color = Color; + wxDash dots[2] = { 1, 3 }; // Under OSX and while printing when wxPen is set to 0, renderer follows the request drawing @@ -138,16 +129,15 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) width = DC->DeviceToLogicalXRel( 1 ); if( s_ForceBlackPen ) - Color = COLOR4D::BLACK; + color = COLOR4D::BLACK; const wxPen& curr_pen = DC->GetPen(); - if( !curr_pen.IsOk() || curr_pen.GetColour() != Color.ToColour() - || curr_pen.GetWidth() != width - || curr_pen.GetStyle() != style ) + if( !curr_pen.IsOk() || curr_pen.GetColour() != color.ToColour() + || curr_pen.GetWidth() != width || curr_pen.GetStyle() != style ) { wxPen pen; - pen.SetColour( Color.ToColour() ); + pen.SetColour( color.ToColour() ); if( style == wxPENSTYLE_DOT ) { @@ -170,18 +160,18 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) } -void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill ) +void GRSetBrush( wxDC* DC, const COLOR4D& Color, bool fill ) { - if( s_ForceBlackPen ) - Color = COLOR4D::BLACK; + COLOR4D color = Color; - if( s_DC_lastbrushcolor != Color - || s_DC_lastbrushfill != fill - || s_DC_lastDC != DC ) + if( s_ForceBlackPen ) + color = COLOR4D::BLACK; + + if( s_DC_lastbrushcolor != color || s_DC_lastbrushfill != fill || s_DC_lastDC != DC ) { wxBrush brush; - brush.SetColour( Color.ToColour() ); + brush.SetColour( color.ToColour() ); if( fill ) brush.SetStyle( wxBRUSHSTYLE_SOLID ); @@ -190,32 +180,26 @@ void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill ) DC->SetBrush( brush ); - s_DC_lastbrushcolor = Color; + s_DC_lastbrushcolor = color; s_DC_lastbrushfill = fill; s_DC_lastDC = DC; } } -/** - * @param flagforce True to force a black pen whenever the asked color. - */ void GRForceBlackPen( bool flagforce ) { s_ForceBlackPen = flagforce; } -/** - * @return true if a black pen was forced. - */ bool GetGRForceBlackPenState( void ) { return s_ForceBlackPen; } -void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, COLOR4D Color ) +void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, const COLOR4D& Color ) { if( ClipBox && !ClipBox->Contains( x, y ) ) return; @@ -225,18 +209,8 @@ void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, COLOR4D Color ) } -/* - * Draw a line, in object space. - */ -void GRLine( EDA_RECT* ClipBox, - wxDC* DC, - int x1, - int y1, - int x2, - int y2, - int width, - COLOR4D Color, - wxPenStyle aStyle) +void GRLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, + const COLOR4D& Color, wxPenStyle aStyle) { GRSetColorPen( DC, Color, width, aStyle ); WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width ); @@ -246,15 +220,12 @@ void GRLine( EDA_RECT* ClipBox, void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, - COLOR4D aColor, wxPenStyle aStyle ) + const COLOR4D& aColor, wxPenStyle aStyle ) { GRLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, aColor, aStyle ); } -/* - * Move to a new position, in object space. - */ void GRMoveTo( int x, int y ) { GRLastMoveToX = x; @@ -262,27 +233,14 @@ void GRMoveTo( int x, int y ) } -/* - * Draw line to a new position, in object space. - */ -void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, COLOR4D Color ) +void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, const COLOR4D& Color ) { GRLine( ClipBox, DC, GRLastMoveToX, GRLastMoveToY, x, y, width, Color ); } -/** - * Draw an array of lines (not a polygon). - * - * @param aClipBox is the clip box. - * @param aDC is the device context into which drawing should occur. - * @param aLines is a list of pair of coordinate in user space: a pair for each line. - * @param aWidth is the width of each line. - * @param aColor is the color to draw the lines. - * @see COLOR4D - */ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, - int aWidth, COLOR4D aColor ) + int aWidth, const COLOR4D& aColor ) { if( aLines.empty() ) return; @@ -298,6 +256,7 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, int y1 = aLines[i].y; int x2 = aLines[i + 1].x; int y2 = aLines[i + 1].y; + if( ( aClipBox == nullptr ) || !ClipLine( aClipBox, x1, y1, x2, y2 ) ) aDC->DrawLine( x1, y1, x2, y2 ); } @@ -305,21 +264,20 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, GRMoveTo( aLines[aLines.size() - 1].x, aLines[aLines.size() - 1].y ); if( aClipBox ) - aClipBox->Inflate(-aWidth/2); + aClipBox->Inflate( -aWidth / 2 ); } -// Draw the outline of a thick segment with rounded ends -void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, int aPenSize, COLOR4D Color ) +void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, + int aPenSize, const COLOR4D& Color ) { GRLastMoveToX = x2; GRLastMoveToY = y2; if( ClipBox ) { - EDA_RECT clipbox(*ClipBox); - clipbox.Inflate(width/2); + EDA_RECT clipbox( *ClipBox ); + clipbox.Inflate( width / 2 ); if( ClipLine( &clipbox, x1, y1, x2, y2 ) ) return; @@ -335,27 +293,27 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, GRSetBrush( DC, Color, NOT_FILLED ); GRSetColorPen( DC, Color, aPenSize ); - int radius = (width + 1) >> 1; + int radius = ( width + 1 ) >> 1; int dx = x2 - x1; int dy = y2 - y1; double angle = -ArcTangente( dy, dx ); wxPoint start; wxPoint end; - wxPoint org( x1, y1); + wxPoint org( x1, y1 ); int len = (int) hypot( dx, dy ); // We know if the DC is mirrored, to draw arcs int slx = DC->DeviceToLogicalX( 1 ) - DC->DeviceToLogicalX( 0 ); int sly = DC->DeviceToLogicalY( 1 ) - DC->DeviceToLogicalY( 0 ); - bool mirrored = (slx > 0 && sly < 0) || (slx < 0 && sly > 0); + bool mirrored = ( slx > 0 && sly < 0 ) || ( slx < 0 && sly > 0 ); // first edge start.x = 0; start.y = radius; end.x = len; end.y = radius; - RotatePoint( &start, angle); - RotatePoint( &end, angle); + RotatePoint( &start, angle ); + RotatePoint( &end, angle ); start += org; end += org; @@ -365,7 +323,7 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, // first rounded end end.x = 0; end.y = -radius; - RotatePoint( &end, angle); + RotatePoint( &end, angle ); end += org; if( !mirrored ) @@ -376,7 +334,7 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, // second edge start.x = len; start.y = -radius; - RotatePoint( &start, angle); + RotatePoint( &start, angle ); start += org; DC->DrawLine( start, end ); @@ -394,25 +352,22 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, } -void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, COLOR4D Color ) +void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, + const COLOR4D& Color ) { GRCSegm( ClipBox, DC, x1, y1, x2, y2, width, 0, Color ); } -void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - int aWidth, COLOR4D aColor ) +void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, + const COLOR4D& aColor ) { GRCSegm( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, 0, aColor ); } -/* - * Draw segment (full) with rounded ends in object space (real coords.). - */ void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, COLOR4D Color ) + int width, const COLOR4D& Color ) { GRSetColorPen( DC, Color, width ); WinClipAndDrawLine( ClipBox, DC, x1, y1, x2, y2, width ); @@ -420,13 +375,12 @@ void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - int aWidth, COLOR4D aColor ) + int aWidth, const COLOR4D& aColor ) { GRSetColorPen( aDC, aColor, aWidth ); WinClipAndDrawLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth ); } - static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, const wxPoint* Points ) { if( !ClipBox ) @@ -466,11 +420,11 @@ static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, const wxPoint* Points ) } -/* +/** * Draw a new polyline and fill it if Fill, in screen space. */ static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, - int width, COLOR4D Color, COLOR4D BgColor ) + int width, const COLOR4D& Color, const COLOR4D& BgColor ) { if( !IsGRSPolyDrawable( ClipBox, n, Points ) ) return; @@ -499,11 +453,11 @@ static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, } -/* +/** * Draw a new closed polyline and fill it if Fill, in screen space. */ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints, - bool aFill, int aWidth, COLOR4D aColor, COLOR4D aBgColor ) + bool aFill, int aWidth, const COLOR4D& aColor, const COLOR4D& aBgColor ) { if( !IsGRSPolyDrawable( aClipBox, aPointCount, aPoints ) ) return; @@ -537,28 +491,28 @@ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC, int aPointCount, const } -/* +/** * Draw a new polyline and fill it if Fill, in drawing space. */ void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width, - COLOR4D Color, COLOR4D BgColor ) + const COLOR4D& Color, const COLOR4D& BgColor ) { GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor ); } -/* +/** * Draw a closed polyline and fill it if Fill, in object space. */ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, - COLOR4D Color, COLOR4D BgColor ) + const COLOR4D& Color, const COLOR4D& BgColor ) { GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor ); } void GRClosedPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width, - COLOR4D Color, COLOR4D BgColor ) + const COLOR4D& Color, const COLOR4D& BgColor ) { GRSClosedPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor ); } @@ -594,7 +548,7 @@ static bool clipCircle( EDA_RECT* aClipBox, int xc, int yc, int r, int aWidth ) } -void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, int r, int width, COLOR4D Color ) +void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, int r, int width, const COLOR4D& Color ) { if( clipCircle( ClipBox, xc, yc, r, width ) || r <= 0 ) return; @@ -605,21 +559,21 @@ void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, int r, int width, CO } -void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, COLOR4D Color ) +void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, const COLOR4D& Color ) { GRCircle( ClipBox, DC, x, y, r, 0, Color ); } void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, - COLOR4D aColor ) + const COLOR4D& aColor ) { GRCircle( aClipBox, aDC, aPos.x, aPos.y, aRadius, aWidth, aColor ); } -void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, - int width, COLOR4D Color, COLOR4D BgColor ) +void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, + const COLOR4D& Color, const COLOR4D& BgColor ) { if( clipCircle( ClipBox, x, y, r, width ) || r <= 0 ) return; @@ -630,27 +584,22 @@ void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, } -void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, COLOR4D aColor ) +void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, + const COLOR4D& aColor ) { GRFilledCircle( aClipBox, aDC, aPos.x, aPos.y, aRadius, 0, aColor, aColor ); } -/* - * Draw an arc in user space. - */ -void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int xc, int yc, COLOR4D Color ) +void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int xc, int yc, + const COLOR4D& Color ) { GRArc1( ClipBox, DC, x1, y1, x2, y2, xc, yc, 0, Color ); } -/* - * Draw an arc, width = width in user space. - */ -void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int xc, int yc, int width, COLOR4D Color ) +void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int xc, int yc, + int width, const COLOR4D& Color ) { /* Clip arcs off screen. */ if( ClipBox ) @@ -661,12 +610,16 @@ void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, xm = ClipBox->GetRight(); ym = ClipBox->GetBottom(); r = KiROUND( Distance( x1, y1, xc, yc ) ); + if( xc < ( x0 - r ) ) return; + if( yc < ( y0 - r ) ) return; + if( xc > ( r + xm ) ) return; + if( yc > ( r + ym ) ) return; } @@ -677,27 +630,16 @@ void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, } -void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - wxPoint aCenter, int aWidth, COLOR4D aColor ) +void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, wxPoint aCenter, + int aWidth, const COLOR4D& aColor ) { GRArc1( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aCenter.x, aCenter.y, aWidth, aColor ); } -/* - * Draw a filled arc in drawing space. - */ -void GRFilledArc( EDA_RECT* ClipBox, - wxDC* DC, - int x, - int y, - double StAngle, - double EndAngle, - int r, - int width, - COLOR4D Color, - COLOR4D BgColor ) +void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, double EndAngle, + int r, int width, const COLOR4D& Color, const COLOR4D& BgColor ) { int x1, y1, x2, y2; @@ -737,19 +679,15 @@ void GRFilledArc( EDA_RECT* ClipBox, } -void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, - double StAngle, double EndAngle, int r, - COLOR4D Color, COLOR4D BgColor ) +void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, double EndAngle, + int r, const COLOR4D& Color, const COLOR4D& BgColor ) { GRFilledArc( ClipBox, DC, x, y, StAngle, EndAngle, r, 0, Color, BgColor ); } -/* - * Draw an arc in drawing space. - */ -void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, double StAngle, - double EndAngle, int r, COLOR4D Color ) +void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, double StAngle, double EndAngle, int r, + const COLOR4D& Color ) { int x1, y1, x2, y2; @@ -792,18 +730,8 @@ void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, double StAngle, } -/* - * Draw an arc with width = width in drawing space. - */ -void GRArc( EDA_RECT* ClipBox, - wxDC* DC, - int x, - int y, - double StAngle, - double EndAngle, - int r, - int width, - COLOR4D Color ) +void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, double EndAngle, + int r, int width, const COLOR4D& Color ) { int x1, y1, x2, y2; @@ -843,16 +771,13 @@ void GRArc( EDA_RECT* ClipBox, } -/* - * Draw a rectangle in drawing space. - */ -void GRRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, COLOR4D aColor ) +void GRRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, const COLOR4D& aColor ) { GRSRect( aClipBox, aDC, x1, y1, x2, y2, 0, aColor ); } -void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, COLOR4D aColor, +void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, const COLOR4D& aColor, wxPenStyle aStyle ) { int x1 = aRect.GetX(); @@ -864,16 +789,15 @@ void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, COLOR4D aCo } -/* - * Draw a rectangle (thick lines) in drawing space. - */ -void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color ) +void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, + const COLOR4D& Color ) { GRSRect( ClipBox, DC, x1, y1, x2, y2, width, Color ); } -void GRRect( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, int aWidth, COLOR4D aColor ) +void GRRect( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, int aWidth, + const COLOR4D& aColor ) { int x1 = aRect.GetX(); int y1 = aRect.GetY(); @@ -884,31 +808,22 @@ void GRRect( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, int aWidth, C } -/* - * Draw a rectangle (filled with AreaColor) in drawing space. - */ void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - COLOR4D Color, COLOR4D BgColor ) + const COLOR4D& Color, const COLOR4D& BgColor ) { GRSFilledRect( ClipBox, DC, x1, y1, x2, y2, 0, Color, BgColor ); } -/* - * Draw a rectangle (filled with AreaColor) in drawing space. - */ void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, COLOR4D Color, COLOR4D BgColor ) + int width, const COLOR4D& Color, const COLOR4D& BgColor ) { GRSFilledRect( ClipBox, DC, x1, y1, x2, y2, width, Color, BgColor ); } -/* - * Draw a rectangle in screen space. - */ void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, - int aWidth, COLOR4D aColor, wxPenStyle aStyle ) + int aWidth, const COLOR4D& aColor, wxPenStyle aStyle ) { wxPoint points[5]; points[0] = wxPoint( x1, y1 ); @@ -921,7 +836,7 @@ void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, - int aWidth, COLOR4D aColor, COLOR4D aBgColor ) + int aWidth, const COLOR4D& aColor, const COLOR4D& aBgColor ) { wxPoint points[5]; points[0] = wxPoint( x1, y1 ); @@ -992,7 +907,7 @@ void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint* Points, int void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aPoint, - int aWidth, COLOR4D aColor ) + int aWidth, const COLOR4D& aColor ) { std::vector output; @@ -1003,7 +918,7 @@ void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aPoint, } -void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y, int aSize, COLOR4D aColor ) +void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y, int aSize, const COLOR4D& aColor ) { int anchor_size = aDC->DeviceToLogicalXRel( aSize ); diff --git a/common/gr_text.cpp b/common/gr_text.cpp index 86cd793de2..df524159fd 100644 --- a/common/gr_text.cpp +++ b/common/gr_text.cpp @@ -127,7 +127,7 @@ int GraphicTextWidth( const wxString& aText, const wxSize& aSize, bool aItalic, * @param aPlotter is a PLOTTER instance, when this function is used to plot * the text. NULL to draw this text. */ -void GRText( wxDC* aDC, const wxPoint& aPos, COLOR4D aColor, const wxString& aText, +void GRText( wxDC* aDC, const wxPoint& aPos, const COLOR4D& aColor, const wxString& aText, double aOrient, const wxSize& aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void (* aCallback)( int x0, int y0, int xf, int yf, void* aData ), @@ -171,28 +171,31 @@ void GRText( wxDC* aDC, const wxPoint& aPos, COLOR4D aColor, const wxString& aTe } -void GRHaloText( wxDC* aDC, const wxPoint &aPos, COLOR4D aBgColor, COLOR4D aColor1, - COLOR4D aColor2, const wxString &aText, double aOrient, const wxSize &aSize, +void GRHaloText( wxDC* aDC, const wxPoint &aPos, const COLOR4D& aBgColor, const COLOR4D& aColor1, + const COLOR4D& aColor2, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void (*aCallback)( int x0, int y0, int xf, int yf, void* aData ), void* aCallbackData, PLOTTER * aPlotter ) { + COLOR4D color1 = aColor1; + COLOR4D color2 = aColor2; + // Swap color if contrast would be better // TODO: Maybe calculate contrast some way other than brightness if( aBgColor.GetBrightness() > 0.5 ) { - COLOR4D c = aColor1; - aColor1 = aColor2; - aColor2 = c; + COLOR4D c = color1; + color1 = color2; + color2 = c; } // Draw the background - GRText( aDC, aPos, aColor1, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, + GRText( aDC, aPos, color1, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic, aBold, aCallback, aCallbackData, aPlotter ); // Draw the text - GRText( aDC, aPos, aColor2, aText, aOrient, aSize, aH_justify, aV_justify, aWidth/4, aItalic, + GRText( aDC, aPos, color2, aText, aOrient, aSize, aH_justify, aV_justify, aWidth / 4, aItalic, aBold, aCallback, aCallbackData, aPlotter ); } diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 860b2088d4..1889f155fb 100644 --- a/common/preview_items/preview_utils.cpp +++ b/common/preview_items/preview_utils.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KICAD, a free EDA CAD application. * - * Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 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 @@ -105,7 +105,7 @@ KIGFX::PREVIEW::TEXT_DIMS KIGFX::PREVIEW::SetConstantGlyphHeight( KIGFX::GAL* aG } -KIGFX::COLOR4D KIGFX::PREVIEW::GetShadowColor(class KIGFX::COLOR4D aColor) +KIGFX::COLOR4D KIGFX::PREVIEW::GetShadowColor( const KIGFX::COLOR4D& aColor ) { if( aColor.GetBrightness() > 0.5 ) return COLOR4D::BLACK; diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index 6bee89073d..3a71dcba69 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -346,7 +346,7 @@ COLOR4D COLOR_SETTINGS::GetDefaultColor( int aLayer ) } -void COLOR_SETTINGS::SetColor( int aLayer, COLOR4D aColor ) +void COLOR_SETTINGS::SetColor( int aLayer, const COLOR4D& aColor ) { m_colors[ aLayer ] = aColor; } diff --git a/common/widgets/layer_box_selector.cpp b/common/widgets/layer_box_selector.cpp index 65f37e70dc..82b62603a9 100644 --- a/common/widgets/layer_box_selector.cpp +++ b/common/widgets/layer_box_selector.cpp @@ -45,7 +45,8 @@ bool LAYER_SELECTOR::SetLayersHotkeys( bool value ) } -void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, COLOR4D aBackground, COLOR4D aColor ) +void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, const COLOR4D& aBackground, + const COLOR4D& aColor ) { wxMemoryDC bmpDC; wxBrush brush; diff --git a/gerbview/am_primitive.cpp b/gerbview/am_primitive.cpp index be40beee4c..402efbe3ca 100644 --- a/gerbview/am_primitive.cpp +++ b/gerbview/am_primitive.cpp @@ -858,7 +858,7 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, - wxDC* aDC, COLOR4D aColor, wxPoint aShapePos, + wxDC* aDC, const COLOR4D& aColor, wxPoint aShapePos, bool aFilledShape ) { SHAPE_POLY_SET* shapeBuffer = GetApertureMacroShape( aParent, aShapePos ); diff --git a/gerbview/am_primitive.h b/gerbview/am_primitive.h index 167217d216..38ba3163f5 100644 --- a/gerbview/am_primitive.h +++ b/gerbview/am_primitive.h @@ -204,7 +204,7 @@ struct APERTURE_MACRO * @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode. */ void DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC, - COLOR4D aColor, wxPoint aShapePos, bool aFilledShape ); + const COLOR4D& aColor, wxPoint aShapePos, bool aFilledShape ); /** * Calculate a value that can be used to evaluate the size of text when displaying the diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 04ed18b4c7..4f7c1030d5 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -646,7 +646,7 @@ void GERBER_DRAW_ITEM::ConvertSegmentToPolygon() } -void GERBER_DRAW_ITEM::PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, +void GERBER_DRAW_ITEM::PrintGerberPoly( wxDC* aDC, const COLOR4D& aColor, const wxPoint& aOffset, bool aFilledShape ) { std::vector points; diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 2aa31db20d..a1491c63f0 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -192,7 +192,8 @@ public: /** * Print the polygon stored in m_PolyCorners. */ - void PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, bool aFilledShape ); + void PrintGerberPoly( wxDC* aDC, const COLOR4D& aColor, const wxPoint& aOffset, + bool aFilledShape ); int Shape() const { return m_Shape; } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 19683530f5..824d479577 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -755,7 +755,7 @@ void GERBVIEW_FRAME::SetGridVisibility( bool aVisible ) } -void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, COLOR4D aColor ) +void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, const COLOR4D& aColor ) { COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings(); @@ -768,6 +768,7 @@ void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, COLOR4D aColor ) case LAYER_GERBVIEW_DRAWINGSHEET: settings->SetColor( LAYER_GERBVIEW_DRAWINGSHEET, aColor ); + // LAYER_DRAWINGSHEET color is also used to draw the drawing-sheet // FIX ME: why LAYER_DRAWINGSHEET must be set, although LAYER_GERBVIEW_DRAWINGSHEET // is used to initialize the drawing-sheet color layer. @@ -806,7 +807,7 @@ COLOR4D GERBVIEW_FRAME::GetLayerColor( int aLayer ) const } -void GERBVIEW_FRAME::SetLayerColor( int aLayer, COLOR4D aColor ) +void GERBVIEW_FRAME::SetLayerColor( int aLayer, const COLOR4D& aColor ) { Pgm().GetSettingsManager().GetColorSettings()->SetColor( aLayer, aColor ); applyDisplaySettingsToGAL(); @@ -891,7 +892,7 @@ COLOR4D GERBVIEW_FRAME::GetGridColor() } -void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor ) +void GERBVIEW_FRAME::SetGridColor( const COLOR4D& aColor ) { Pgm().GetSettingsManager().GetColorSettings()->SetColor( LAYER_GRID, aColor ); GetCanvas()->GetGAL()->SetGridColor( aColor ); diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 32f54b7330..0031106b5f 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -155,10 +155,10 @@ public: */ COLOR4D GetVisibleElementColor( int aLayerID ); - void SetVisibleElementColor( int aLayerID, COLOR4D aColor ); + void SetVisibleElementColor( int aLayerID, const COLOR4D& aColor ); COLOR4D GetLayerColor( int aLayer ) const; - void SetLayerColor( int aLayer, COLOR4D aColor ); + void SetLayerColor( int aLayer, const COLOR4D& aColor ); /** * This is usually the background color, but can be another color in order to see @@ -456,7 +456,7 @@ public: COLOR4D GetGridColor() override; ///< @copydoc EDA_DRAW_FRAME::SetGridColor() - virtual void SetGridColor( COLOR4D aColor ) override; + virtual void SetGridColor( const COLOR4D& aColor ) override; const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override { diff --git a/gerbview/widgets/gerbview_layer_widget.cpp b/gerbview/widgets/gerbview_layer_widget.cpp index 421eb738c5..3b808dadc0 100644 --- a/gerbview/widgets/gerbview_layer_widget.cpp +++ b/gerbview/widgets/gerbview_layer_widget.cpp @@ -242,7 +242,7 @@ void GERBER_LAYER_WIDGET::OnLayerRightClick( wxMenu& aMenu ) } -void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, COLOR4D aColor ) +void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, const COLOR4D& aColor ) { // NOTE: Active layer in GerbView is stored as 0-indexed, but layer color is // stored according to the GERBER_DRAW_LAYER() offset. @@ -297,7 +297,7 @@ void GERBER_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFin } -void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor ) +void GERBER_LAYER_WIDGET::OnRenderColorChange( int aId, const COLOR4D& aColor ) { m_frame->SetVisibleElementColor( aId, aColor ); diff --git a/gerbview/widgets/gerbview_layer_widget.h b/gerbview/widgets/gerbview_layer_widget.h index f03c301788..6ade9df60e 100644 --- a/gerbview/widgets/gerbview_layer_widget.h +++ b/gerbview/widgets/gerbview_layer_widget.h @@ -54,10 +54,10 @@ public: //---------------- void OnLayerRightClick( wxMenu& aMenu ) override; - void OnLayerColorChange( int aLayer, COLOR4D aColor ) override; + void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) override; bool OnLayerSelect( int aLayer ) override; void OnLayerVisible( int aLayer, bool isVisible, bool isFinal ) override; - void OnRenderColorChange( int aId, COLOR4D aColor ) override; + void OnRenderColorChange( int aId, const COLOR4D& aColor ) override; void OnRenderEnable( int aId, bool isEnabled ) override; /** diff --git a/gerbview/widgets/layer_widget.cpp b/gerbview/widgets/layer_widget.cpp index 879c55f7e0..cddf53115b 100644 --- a/gerbview/widgets/layer_widget.cpp +++ b/gerbview/widgets/layer_widget.cpp @@ -91,6 +91,7 @@ void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) int height = 0; int rowCount = GetLayerRowCount(); + for( row = 0; rowGetNewSwatchColor(); - } else { - event.Skip(); - } - } ); + menu.Bind( wxEVT_COMMAND_MENU_SELECTED, [aColorSwatch]( wxCommandEvent& event ) + { + if( event.GetId() == ID_CHANGE_LAYER_COLOR ) + { + aColorSwatch->GetNewSwatchColor(); + } + else + { + event.Skip(); + } + } ); PopupMenu( &menu ); passOnFocus(); @@ -170,7 +176,8 @@ void LAYER_WIDGET::OnLayerCheckBox( wxCommandEvent& event ) } -void LAYER_WIDGET::OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, const wxString& aRenderName ) +void LAYER_WIDGET::OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, + const wxString& aRenderName ) { wxMenu menu; @@ -424,7 +431,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) { col = 1; cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ), - aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); + aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); shrinkFont( cb, m_PointSize ); cb->SetValue( aSpec.state ); cb->Enable( aSpec.changeable ); @@ -434,6 +441,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec ) // column 0 col = 0; + if( aSpec.color != COLOR4D::UNSPECIFIED ) { auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ), @@ -759,7 +767,7 @@ bool LAYER_WIDGET::IsLayerVisible( LAYER_NUM aLayer ) } -void LAYER_WIDGET::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor ) +void LAYER_WIDGET::SetLayerColor( LAYER_NUM aLayer, const COLOR4D& aColor ) { int row = findLayerRow( aLayer ); @@ -881,7 +889,7 @@ class MYFRAME : public wxFrame { } - void OnLayerColorChange( int aLayer, COLOR4D aColor ) + void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) { /* a test trigger only if( aLayer == 2 ) @@ -900,7 +908,7 @@ class MYFRAME : public wxFrame { } - void OnRenderColorChange( int aId, COLOR4D aColor ) + void OnRenderColorChange( int aId, const COLOR4D& aColor ) { } diff --git a/gerbview/widgets/layer_widget.h b/gerbview/widgets/layer_widget.h index 92ebd6c4d1..2787f426ae 100644 --- a/gerbview/widgets/layer_widget.h +++ b/gerbview/widgets/layer_widget.h @@ -92,9 +92,9 @@ public: bool spacer; ///< if true, this row is a spacer COLOR4D defaultColor; ///< The default color for the row - ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED, + ROW( const wxString& aRowName, int aId, const COLOR4D& aColor = COLOR4D::UNSPECIFIED, const wxString& aTooltip = wxEmptyString, bool aState = true, - bool aChangeable = true, COLOR4D aDefaultColor = COLOR4D::UNSPECIFIED ) + bool aChangeable = true, const COLOR4D& aDefaultColor = COLOR4D::UNSPECIFIED ) { rowName = aRowName; id = aId; @@ -238,7 +238,7 @@ public: /** * Change the color of \a aLayer */ - void SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor ); + void SetLayerColor( LAYER_NUM aLayer, const COLOR4D& aColor ); /** * Return the color of the layer ROW associated with \a aLayer id. @@ -299,7 +299,7 @@ public: * @param aLayer is the board layer to change. * @param aColor is the new color. */ - virtual void OnLayerColorChange( int aLayer, COLOR4D aColor ) = 0; + virtual void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) = 0; /** * Notify client code whenever the user selects a different layer. @@ -335,7 +335,7 @@ public: * function. * @param aColor is the new color. */ - virtual void OnRenderColorChange( int aId, COLOR4D aColor ) = 0; + virtual void OnRenderColorChange( int aId, const COLOR4D& aColor ) = 0; /** * Notify client code whenever the user changes an rendering enable in one of the rendering diff --git a/include/bitmap_base.h b/include/bitmap_base.h index 9f3195a649..0afa4dc596 100644 --- a/include/bitmap_base.h +++ b/include/bitmap_base.h @@ -231,7 +231,7 @@ public: * @param aDefaultPensize the pen size used to plot the rectangle when bitmap is not supported. */ void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos, - KIGFX::COLOR4D aDefaultColor, int aDefaultPensize ) const; + const KIGFX::COLOR4D& aDefaultColor, int aDefaultPensize ) const; private: double m_scale; // The scaling factor of the bitmap diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index 00bba67bd9..aaaa400c75 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -3,7 +3,7 @@ * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -171,7 +171,7 @@ public: // the background color of the draw canvas: // Virtual because some frames can have a specific way to get/set the bg color virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; } - virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; } + virtual void SetDrawBgColor( const COLOR4D& aColor) { m_drawBgColor= aColor ; } /// Returns a pointer to the active color theme settings virtual COLOR_SETTINGS* GetColorSettings() const; @@ -225,7 +225,7 @@ public: virtual void SetGridVisibility( bool aVisible ); virtual COLOR4D GetGridColor() { return m_gridColor; } - virtual void SetGridColor( COLOR4D aColor ) { m_gridColor = aColor; } + virtual void SetGridColor( const COLOR4D& aColor ) { m_gridColor = aColor; } /** * Command event handler for selecting grid sizes. diff --git a/include/eda_text.h b/include/eda_text.h index 6dc3206df4..c31929f266 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -266,7 +266,7 @@ public: * @param aDisplay_mode #FILLED or #SKETCH. */ void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, - COLOR4D aColor, OUTLINE_MODE aDisplay_mode = FILLED ); + const COLOR4D& aColor, OUTLINE_MODE aDisplay_mode = FILLED ); /** * Convert the text shape to a list of segment. diff --git a/include/gal/color4d.h b/include/gal/color4d.h index e55dea465c..4fbcf4d6df 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -165,7 +165,7 @@ public: * * @param aColor The color to mix with this one */ - COLOR4D LegacyMix( COLOR4D aColor ) const; + COLOR4D LegacyMix( const COLOR4D& aColor ) const; /** * Packs the color into an unsigned int for compatibility with legacy canvas. diff --git a/include/gr_basic.h b/include/gr_basic.h index 51240f9759..f9c2d8a871 100644 --- a/include/gr_basic.h +++ b/include/gr_basic.h @@ -90,8 +90,9 @@ typedef enum { void GRResetPenAndBrush( wxDC* DC ); -void GRSetColorPen( wxDC* DC, COLOR4D Color, int width = 1, wxPenStyle stype = wxPENSTYLE_SOLID ); -void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill = false ); +void GRSetColorPen( wxDC* DC, const COLOR4D& Color, int width = 1, + wxPenStyle stype = wxPENSTYLE_SOLID ); +void GRSetBrush( wxDC* DC, const COLOR4D& Color, bool fill = false ); /** * @param flagforce True to force a black pen whenever the asked color. @@ -104,20 +105,20 @@ void GRForceBlackPen( bool flagforce ); bool GetGRForceBlackPenState( void ); void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, - COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); + const COLOR4D& aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); void GRLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, - COLOR4D Color, wxPenStyle aStyle = wxPENSTYLE_SOLID ); + const COLOR4D& Color, wxPenStyle aStyle = wxPENSTYLE_SOLID ); void GRMoveTo( int x, int y ); -void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, COLOR4D Color ); +void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, const COLOR4D& Color ); void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width, - COLOR4D Color, COLOR4D BgColor ); + const COLOR4D& Color, const COLOR4D& BgColor ); /** * Draw cubic (4 points: start control1, control2, end) bezier curve. */ void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aPoints, - int aWidth, COLOR4D aColor ); + int aWidth, const COLOR4D& aColor ); /** * Draw a closed polygon onto the drawing context \a aDC and optionally fills and/or draws @@ -132,7 +133,7 @@ void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aPoints, * @param aFillColor the fill color of the polygon's interior. */ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints, - bool doFill, COLOR4D aPenColor, COLOR4D aFillColor ); + bool doFill, const COLOR4D& aPenColor, const COLOR4D& aFillColor ); // @todo could make these 2 closed polygons calls a single function and default // the aPenWidth argument @@ -151,7 +152,8 @@ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* * @param aFillColor the fill color of the polygon's interior. */ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints, - bool doFill, int aPenWidth, COLOR4D aPenColor, COLOR4D aFillColor ); + bool doFill, int aPenWidth, const COLOR4D& aPenColor, + const COLOR4D& aFillColor ); /** @@ -165,58 +167,59 @@ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* * @param aColor is the color to draw. * @see COLOR4D */ -void GRCircle( EDA_RECT* ClipBox, wxDC* aDC, int x, int y, int aRadius, COLOR4D aColor ); -void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, COLOR4D Color ); +void GRCircle( EDA_RECT* ClipBox, wxDC* aDC, int x, int y, int aRadius, const COLOR4D& aColor ); +void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, const COLOR4D& Color ); void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, - COLOR4D Color, COLOR4D BgColor ); -void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, COLOR4D aColor ); + const COLOR4D& Color, const COLOR4D& BgColor ); +void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, + const COLOR4D& aColor ); void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, - COLOR4D aColor ); + const COLOR4D& aColor ); void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, - double EndAngle, int r, COLOR4D Color ); + double EndAngle, int r, const COLOR4D& Color ); void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, - double EndAngle, int r, int width, COLOR4D Color ); + double EndAngle, int r, int width, const COLOR4D& Color ); void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int xc, int yc, COLOR4D Color ); + int xc, int yc, const COLOR4D& Color ); void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int xc, int yc, int width, COLOR4D Color ); + int xc, int yc, int width, const COLOR4D& Color ); void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - wxPoint aCenter, int aWidth, COLOR4D aColor ); -void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, - double StAngle, double EndAngle, int r, COLOR4D Color, COLOR4D BgColor ); + wxPoint aCenter, int aWidth, const COLOR4D& aColor ); +void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, double EndAngle, + int r, const COLOR4D& Color, const COLOR4D& BgColor ); void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle, - double EndAngle, int r, int width, COLOR4D Color, COLOR4D BgColor ); + double EndAngle, int r, int width, const COLOR4D& Color, const COLOR4D& BgColor ); void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, - COLOR4D Color ); + const COLOR4D& Color ); void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, COLOR4D Color ); + int width, const COLOR4D& Color ); void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - int aWidth, COLOR4D aColor ); + int aWidth, const COLOR4D& aColor ); void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, - int width, int aPenSize, COLOR4D Color ); + int width, int aPenSize, const COLOR4D& Color ); void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, - int aWidth, COLOR4D aColor ); + int aWidth, const COLOR4D& aColor ); -void GRSetColor( COLOR4D Color ); +void GRSetColor( const COLOR4D& Color ); void GRSetDefaultPalette(); COLOR4D GRGetColor(); -void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, COLOR4D color ); +void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, const COLOR4D& color ); void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, - int x2, int y2, COLOR4D Color, COLOR4D BgColor ); + int x2, int y2, const COLOR4D& Color, const COLOR4D& BgColor ); void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, - int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor ); -void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, COLOR4D Color ); -void GRRect( EDA_RECT* ClipBox, wxDC* DC,const EDA_RECT& aRect, int aWidth, COLOR4D Color ); + int x2, int y2, int width, const COLOR4D& Color, const COLOR4D& BgColor ); +void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, const COLOR4D& Color ); +void GRRect( EDA_RECT* ClipBox, wxDC* DC,const EDA_RECT& aRect, int aWidth, const COLOR4D& Color ); void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, - int x2, int y2, int width, COLOR4D Color ); + int x2, int y2, int width, const COLOR4D& Color ); void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC,const EDA_RECT& aRect, - int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); + int aWidth, const COLOR4D& aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID ); void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, - int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor ); + int x2, int y2, int width, const COLOR4D& Color, const COLOR4D& BgColor ); /** * Draw an array of lines (not a polygon). @@ -229,9 +232,9 @@ void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, * @see COLOR4D */ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector& aLines, - int aWidth, COLOR4D aColor ); + int aWidth, const COLOR4D& aColor ); -void GRDrawAnchor( EDA_RECT* aClipBox, wxDC* aDC, int x, int y, int aSize, COLOR4D aColor ); +void GRDrawAnchor( EDA_RECT* aClipBox, wxDC* aDC, int x, int y, int aSize, const COLOR4D& aColor ); /** * Draw text centered on a wxDC with wrapping. diff --git a/include/gr_text.h b/include/gr_text.h index 6352a303a4..605e895289 100644 --- a/include/gr_text.h +++ b/include/gr_text.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009-2014 Jerry Jacobs - * Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 1992-2021 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 @@ -110,7 +110,7 @@ int GraphicTextWidth( const wxString& aText, const wxSize& aSize, bool italic, b * @param aPlotter = a pointer to a PLOTTER instance, when this function is used to plot * the text. NULL to draw this text. */ -void GRText( wxDC* aDC, const wxPoint& aPos, COLOR4D aColor, const wxString& aText, +void GRText( wxDC* aDC, const wxPoint& aPos, const COLOR4D& aColor, const wxString& aText, double aOrient, const wxSize& aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void (*aCallback)( int x0, int y0, int xf, int yf, void* aData ) = nullptr, @@ -123,8 +123,8 @@ void GRText( wxDC* aDC, const wxPoint& aPos, COLOR4D aColor, const wxString& aTe * See GRText for most of the parameters. If \a aBgColor is a dark color text is drawn * in \a aColor2 with \a aColor1 border. Otherwise colors are swapped. */ -void GRHaloText( wxDC* aDC, const wxPoint& aPos, COLOR4D aBgColor, COLOR4D aColor1, - COLOR4D aColor2, const wxString& aText, double aOrient, const wxSize &aSize, +void GRHaloText( wxDC* aDC, const wxPoint& aPos, const COLOR4D& aBgColor, const COLOR4D& aColor1, + const COLOR4D& aColor2, const wxString& aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void (*aCallback)( int x0, int y0, int xf, int yf, void* aData ) = nullptr, diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 40e400ca8a..688a8c23a7 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2016 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2008-2016 Wayne Stambaugh + * Copyright (C) 1992-2021 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 @@ -170,7 +170,7 @@ public: PCBNEW_SETTINGS& Settings() { return *m_settings; } - void SetDrawBgColor( COLOR4D aColor ) override; + void SetDrawBgColor( const COLOR4D& aColor ) override; /** * Display options control the way tracks, vias, outlines and other things are shown @@ -332,7 +332,8 @@ public: * @param aItemsList is the list of items modified by the command to undo. * @param aTypeCommand is the command type (see enum #UNDO_REDO) */ - virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO aTypeCommand ) = 0; + virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, + UNDO_REDO aTypeCommand ) = 0; /** diff --git a/include/preview_items/preview_utils.h b/include/preview_items/preview_utils.h index d1f0f93211..412fbd9e27 100644 --- a/include/preview_items/preview_utils.h +++ b/include/preview_items/preview_utils.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KICAD, a free EDA CAD application. * - * Copyright (C) 2017 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 2017-2021 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 @@ -44,40 +44,37 @@ struct TEXT_DIMS }; /** - * Default alpha of "de-emphasised" features (like previously locked-in - * lines + * Default alpha of "de-emphasised" features (like previously locked-in lines. */ double PreviewOverlayDeemphAlpha( bool aDeemph = true ); /** - * Get a formatted string showing a dimension to a sane precision - * with an optional prefix and unit suffix. + * Get a formatted string showing a dimension to a sane precision with an optional prefix and + * unit suffix. */ wxString DimensionLabel( const wxString& prefix, double aVal, EDA_UNITS aUnits, bool aIncludeUnits = true ); /** - * Set the GAL glyph height to a constant scaled value, so that it - * always looks the same on screen + * Set the GAL glyph height to a constant scaled value, so that it always looks the same on screen. * - * @param aGal the GAL to draw on + * @param aGal the GAL to draw on. * @param aRelativeSize similar to HTML font sizes; 0 will give a standard size while +1 etc. * will give larger and -1 etc. will give smaller. * @returns the text widths for the resulting glyph size. */ TEXT_DIMS SetConstantGlyphHeight( KIGFX::GAL* aGal, int aRelativeSize = 0 ); -COLOR4D GetShadowColor( COLOR4D aColor ); +COLOR4D GetShadowColor( const COLOR4D& aColor ); /** - * Draw strings next to the cursor + * Draw strings next to the cursor. * - * @param aGal the GAL to draw on - * @param aCursorPos the position of the cursor to draw next to - * @param aTextQuadrant a vector pointing to the quadrant to draw the - * text in - * @param aStrings list of strings to draw, top to bottom + * @param aGal the GAL to draw on. + * @param aCursorPos the position of the cursor to draw next to. + * @param aTextQuadrant a vector pointing to the quadrant to draw the text in. + * @param aStrings list of strings to draw, top to bottom. */ void DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& aCursorPos, const VECTOR2D& aTextQuadrant, const std::vector& aStrings, diff --git a/include/settings/color_settings.h b/include/settings/color_settings.h index e87f72fdd7..b0a554d438 100644 --- a/include/settings/color_settings.h +++ b/include/settings/color_settings.h @@ -76,7 +76,7 @@ public: COLOR4D GetDefaultColor( int aLayer ); - void SetColor( int aLayer, COLOR4D aColor ); + void SetColor( int aLayer, const COLOR4D& aColor ); const wxString& GetName() const { return m_displayName; } void SetName( const wxString& aName ) { m_displayName = aName; } diff --git a/include/widgets/layer_box_selector.h b/include/widgets/layer_box_selector.h index 3eb06644aa..4d4c907372 100644 --- a/include/widgets/layer_box_selector.h +++ b/include/widgets/layer_box_selector.h @@ -46,7 +46,8 @@ public: bool SetLayersHotkeys( bool value ); // Fill the layer bitmap aLayerbmp with the layer color - static void DrawColorSwatch( wxBitmap& aLayerbmp, COLOR4D aBackground, COLOR4D aColor ); + static void DrawColorSwatch( wxBitmap& aLayerbmp, const COLOR4D& aBackground, + const COLOR4D& aColor ); protected: // Return a color index from the layer id diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index f25cb0e24d..0f5191188e 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -359,7 +359,7 @@ BOARD_DESIGN_SETTINGS& PCB_BASE_FRAME::GetDesignSettings() const } -void PCB_BASE_FRAME::SetDrawBgColor( COLOR4D aColor ) +void PCB_BASE_FRAME::SetDrawBgColor( const COLOR4D& aColor ) { m_drawBgColor= aColor; m_auimgr.Update(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 9d47481318..fe1ef2e355 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -994,7 +994,7 @@ COLOR4D PCB_EDIT_FRAME::GetGridColor() } -void PCB_EDIT_FRAME::SetGridColor( COLOR4D aColor ) +void PCB_EDIT_FRAME::SetGridColor( const COLOR4D& aColor ) { GetColorSettings()->SetColor( LAYER_GRID, aColor ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 04aa66aedf..48afc18741 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -148,9 +148,9 @@ public: COLOR4D GetGridColor() override; /** - * @param aColor the new color of the grid. + * @param[in] aColor the new color of the grid. */ - void SetGridColor( COLOR4D aColor ) override; + void SetGridColor( const COLOR4D& aColor ) override; // Configurations: void Process_Config( wxCommandEvent& event ); diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index e74e5742c3..e03458d5fb 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -84,7 +84,7 @@ public: void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; } void PlotFootprintGraphicItems( const FOOTPRINT* aFootprint ); void PlotFootprintGraphicItem( const FP_SHAPE* aShape ); - void PlotFootprintTextItem( const FP_TEXT* aText, COLOR4D aColor ); + void PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4D& aColor ); /* * Reference, Value, and other fields are plotted only if the corresponding option is enabled. @@ -104,7 +104,7 @@ public: * Unlike other items, a pad had not a specific color and be drawn as a non filled item * although the plot mode is filled color and plot mode are needed by this function. */ - void PlotPad( const PAD* aPad, COLOR4D aColor, OUTLINE_MODE aPlotMode ); + void PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_MODE aPlotMode ); /** * Plot items like text and graphics but not tracks and footprints. diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 0c576a4e80..8a08ff8904 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -82,7 +82,7 @@ COLOR4D BRDITEMS_PLOTTER::getColor( LAYER_NUM aLayer ) const } -void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, COLOR4D aColor, OUTLINE_MODE aPlotMode ) +void BRDITEMS_PLOTTER::PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_MODE aPlotMode ) { wxPoint shape_pos = aPad->ShapePos(); GBR_METADATA gbr_metadata; @@ -364,12 +364,14 @@ void BRDITEMS_PLOTTER::PlotBoardGraphicItems() } } -void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aTextMod, COLOR4D aColor ) +void BRDITEMS_PLOTTER::PlotFootprintTextItem( const FP_TEXT* aTextMod, const COLOR4D& aColor ) { - if( aColor == COLOR4D::WHITE ) - aColor = COLOR4D( LIGHTGRAY ); + COLOR4D color = aColor; - m_plotter->SetColor( aColor ); + if( aColor == COLOR4D::WHITE ) + color = COLOR4D( LIGHTGRAY ); + + m_plotter->SetColor( color ); // calculate some text parameters : wxSize size = aTextMod->GetTextSize();