1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The 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 Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "widgets/layer_presentation.h"
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
#include <gal/color4d.h>
using namespace KIGFX;
void LAYER_PRESENTATION::DrawColorSwatch( wxBitmap& aLayerbmp, const COLOR4D& aBackground,
const COLOR4D& aColor )
{
wxMemoryDC bmpDC;
wxBrush brush;
// Prepare Bitmap
bmpDC.SelectObject( aLayerbmp );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
if( aBackground != COLOR4D::UNSPECIFIED )
{
brush.SetColour( aBackground.WithAlpha( 1.0 ).ToColour() );
bmpDC.SetBrush( brush );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
}
brush.SetColour( aColor.ToColour() );
bmpDC.SetBrush( brush );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
bmpDC.SetPen( *wxBLACK_PEN );
bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
}
void LAYER_PRESENTATION::DrawColorSwatch( wxBitmap& aLayerbmp, int aLayer ) const
{
const COLOR4D bgColor = getLayerColor( LAYER_PCB_BACKGROUND );
const COLOR4D color = getLayerColor( aLayer );
DrawColorSwatch( aLayerbmp, bgColor, color );
}
static constexpr unsigned BM_LAYERICON_SIZE = 24;
static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE] = {
// 0 = draw pixel with white
// 1 = draw pixel with black
// 2 = draw pixel with top layer from router pair
// 3 = draw pixel with bottom layer from router pair
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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3, 3 },
{ 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
{ 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
};
static COLOR4D ICON_WHITE{ 0.86, 0.86, 0.86, 1.0 };
static COLOR4D ICON_BLACK{ 0.28, 0.28, 0.28, 1.0 };
std::unique_ptr<wxBitmap> LAYER_PRESENTATION::CreateLayerPairIcon( const COLOR4D& aBgColor,
const COLOR4D& aTopColor,
const COLOR4D& aBottomColor,
int aScale )
{
auto layerPairBitmap = std::make_unique<wxBitmap>( BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
// Draw the icon, with colors according to the router's layer pair
wxMemoryDC iconDC;
iconDC.SelectObject( *layerPairBitmap );
wxBrush brush;
wxPen pen;
int buttonColor = -1;
brush.SetStyle( wxBRUSHSTYLE_SOLID );
brush.SetColour( aBgColor.WithAlpha( 1.0 ).ToColour() );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
for( unsigned ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
{
for( unsigned jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
{
if( s_BitmapLayerIcon[ii][jj] != buttonColor )
{
switch( s_BitmapLayerIcon[ii][jj] )
{
default:
case 0: pen.SetColour( ICON_WHITE.ToColour() ); break;
case 1: pen.SetColour( ICON_BLACK.ToColour() ); break;
case 2: pen.SetColour( aTopColor.ToColour() ); break;
case 3: pen.SetColour( aBottomColor.ToColour() ); break;
}
buttonColor = s_BitmapLayerIcon[ii][jj];
iconDC.SetPen( pen );
}
iconDC.DrawPoint( jj, ii );
}
}
// Deselect the bitmap from the DC in order to delete the MemoryDC safely without
// deleting the bitmap
iconDC.SelectObject( wxNullBitmap );
// Scale the bitmap
wxImage image = layerPairBitmap->ConvertToImage();
// "NEAREST" causes less mixing of colors
image.Rescale( aScale * image.GetWidth() / 4, aScale * image.GetHeight() / 4,
wxIMAGE_QUALITY_NEAREST );
return std::make_unique<wxBitmap>( image );
}
std::unique_ptr<wxBitmap> LAYER_PRESENTATION::CreateLayerPairIcon( int aLeftLayer, int aRightLayer,
int aScale ) const
{
const COLOR4D bgColor = getLayerColor( LAYER_PCB_BACKGROUND );
const COLOR4D topColor = getLayerColor( aLeftLayer );
const COLOR4D bottomColor = getLayerColor( aRightLayer );
return CreateLayerPairIcon( bgColor, topColor, bottomColor, aScale );
}
|