Alpha-blend color with the checkerboard in color swatches.

This commit is contained in:
Alex Shvartzkop 2023-11-29 03:34:08 +03:00
parent daf178b64f
commit bbba7fd4d7
1 changed files with 53 additions and 55 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,10 +33,6 @@ wxDEFINE_EVENT( COLOR_SWATCH_CHANGED, wxCommandEvent );
using KIGFX::COLOR4D; using KIGFX::COLOR4D;
// See selcolor.cpp:
extern COLOR4D DisplayColorFrame( wxWindow* aParent, COLOR4D aOldColor );
wxBitmap COLOR_SWATCH::MakeBitmap( const COLOR4D& aColor, const COLOR4D& aBackground, wxBitmap COLOR_SWATCH::MakeBitmap( const COLOR4D& aColor, const COLOR4D& aBackground,
const wxSize& aSize, const wxSize& aCheckerboardSize, const wxSize& aSize, const wxSize& aCheckerboardSize,
const COLOR4D& aCheckerboardBackground ) const COLOR4D& aCheckerboardBackground )
@ -62,8 +58,6 @@ void COLOR_SWATCH::RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
brush.SetStyle( wxBRUSHSTYLE_SOLID ); brush.SetStyle( wxBRUSHSTYLE_SOLID );
if( aColor == COLOR4D::UNSPECIFIED )
{
// Draw a checkerboard // Draw a checkerboard
COLOR4D white; COLOR4D white;
COLOR4D black; COLOR4D black;
@ -82,11 +76,11 @@ void COLOR_SWATCH::RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
rowCycle = false; rowCycle = false;
} }
for( int x = aRect.GetLeft(); x < aRect.GetRight(); x += aCheckerboardSize.x ) for( int x = aRect.GetLeft(); x <= aRect.GetRight(); x += aCheckerboardSize.x )
{ {
bool colCycle = rowCycle; bool colCycle = rowCycle;
for( int y = aRect.GetTop(); y < aRect.GetBottom(); y += aCheckerboardSize.y ) for( int y = aRect.GetTop(); y <= aRect.GetBottom(); y += aCheckerboardSize.y )
{ {
COLOR4D color = colCycle ? black : white; COLOR4D color = colCycle ? black : white;
brush.SetColour( color.ToColour() ); brush.SetColour( color.ToColour() );
@ -101,22 +95,26 @@ void COLOR_SWATCH::RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
rowCycle = !rowCycle; rowCycle = !rowCycle;
} }
}
else // Blend fg color with the checkerboard
wxColor fg = aColor.ToColour();
for( int y = aRect.GetTop(); y <= aRect.GetBottom(); y++ )
{ {
brush.SetColour( aBackground.WithAlpha(1.0).ToColour() ); for( int x = aRect.GetLeft(); x <= aRect.GetRight(); x++ )
pen.SetColour( aBackground.WithAlpha(1.0).ToColour() ); {
wxColor bg;
aDC->GetPixel( x, y, &bg );
aDC->SetBrush( brush ); unsigned char r = wxColor::AlphaBlend( fg.Red(), bg.Red(), aColor.a );
unsigned char g = wxColor::AlphaBlend( fg.Green(), bg.Green(), aColor.a );
unsigned char b = wxColor::AlphaBlend( fg.Blue(), bg.Blue(), aColor.a );
pen.SetColour( r, g, b );
aDC->SetPen( pen ); aDC->SetPen( pen );
aDC->DrawRectangle( aRect );
brush.SetColour( aColor.ToColour() ); aDC->DrawPoint( x, y );
pen.SetColour( aColor.ToColour() ); }
aDC->SetBrush( brush );
aDC->SetPen( pen );
aDC->DrawRectangle( aRect );
} }
} }