From 619771725196b931af0744767b6e2ce7d298632b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 16 Sep 2021 11:14:43 +0100 Subject: [PATCH] Avoid poor choices for point colors. Also adjusts the point size to account for the fact that it now has a border. --- common/gal/color4d.cpp | 8 ++++++++ common/tool/edit_points.cpp | 19 +++++++++++++++++-- include/gal/color4d.h | 5 +++++ include/tool/edit_points.h | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index 09af279352..c9980ecc64 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -503,6 +503,14 @@ const COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 ); const COLOR4D COLOR4D::CLEAR( 1, 0, 1, 0 ); +int COLOR4D::Distance( const COLOR4D& other ) const +{ + return ( r - other.r ) * ( r - other.r ) + + ( g - other.g ) * ( g - other.g ) + + ( b - other.b ) * ( b - other.b ); +} + + EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB ) { EDA_COLOR_T candidate = EDA_COLOR_T::BLACK; diff --git a/common/tool/edit_points.cpp b/common/tool/edit_points.cpp index f98ce05f6b..a1b8889f2f 100644 --- a/common/tool/edit_points.cpp +++ b/common/tool/edit_points.cpp @@ -247,9 +247,24 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const auto gal = aView->GetGAL(); KIGFX::RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings(); + KIGFX::COLOR4D drawColor = settings->GetLayerColor( LAYER_AUX_ITEMS ); + + // Don't assume LAYER_AUX_ITEMS is always a good choice. Compare with background. + if( aView->GetGAL()->GetClearColor().Distance( drawColor ) < 0.5 ) + drawColor.Invert(); + + // Linear darkening doesn't fit well with human color perception, and there's no guarantee + // that there's enough room for contrast either. + KIGFX::COLOR4D bgColor; + double brightness = drawColor.GetBrightness(); + + if( brightness > 0.5 ) + bgColor = drawColor.Darkened( 0.3 ).WithAlpha( 0.8 ); + else if( brightness > 0.2 ) + bgColor = drawColor.Darkened( 0.6 ).WithAlpha( 0.8 ); + else + bgColor = drawColor.Brightened( 0.3 ).WithAlpha( 0.8 ); - KIGFX::COLOR4D drawColor = settings->GetLayerColor( LAYER_AUX_ITEMS ); - KIGFX::COLOR4D bgColor = drawColor.Darkened( 0.3 ).WithAlpha( 0.8 ); KIGFX::COLOR4D highlightColor = settings->GetLayerColor( LAYER_SELECT_OVERLAY ); gal->SetFillColor( drawColor ); diff --git a/include/gal/color4d.h b/include/gal/color4d.h index 6d733b463b..1b4cf6e9b9 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -357,6 +357,11 @@ public: */ void FromHSV( double aInH, double aInS, double aInV ); + /** + * Returns the distance (in RGB space) between two colors. + */ + int Distance( const COLOR4D& other ) const; + /** * Returns a legacy color ID that is closest to the given 8-bit RGB values. */ diff --git a/include/tool/edit_points.h b/include/tool/edit_points.h index bcfdf98330..6e9af7ce2f 100644 --- a/include/tool/edit_points.h +++ b/include/tool/edit_points.h @@ -183,7 +183,7 @@ public: } ///< Single point size in pixels - static const int POINT_SIZE = 10; + static const int POINT_SIZE = 8; ///< Border size when not hovering static const int BORDER_SIZE = 2;