KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gbr_layer_box_selector.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2016 Jean-Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 1992-2021 KiCad Developers, see change_log.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <gerbview_frame.h>
28
29#ifdef __WXMSW__
30#include <dpi_scaling_common.h>
31#endif
32
34
36{
37 Freeze();
38 Clear();
39
40#ifdef __WXMSW__
41 DPI_SCALING_COMMON dpi( nullptr, this );
42 int size = static_cast<int>( 14 / dpi.GetContentScaleFactor() );
43#else
44 const int size = 14;
45#endif
46
48
49 for( unsigned layerid = 0; layerid < images.ImagesMaxCount(); ++layerid )
50 {
51 if( !isLayerEnabled( layerid ) )
52 continue;
53
54 // Don't show unused layers
55 if ( images.GetGbrImage( layerid ) == nullptr )
56 continue;
57
58 // Prepare Bitmap
59 wxBitmap bmp( size, size );
61
62 Append( getLayerName( layerid ), bmp, (void*)(intptr_t) layerid );
63 }
64
65 // Ensure the size of the widget is enough to show the text and the icon
66 // We have to have a selected item when doing this, because otherwise GTK
67 // will just choose a random size that might not fit the actual data
68 // (such as in cases where the font size is very large). So we select
69 // the first item, get the size of the control and make that the minimum size,
70 // then remove the selection (which was the initial state).
71 if( GetCount() )
72 {
73 SetSelection( 0 );
74
75 SetMinSize( wxSize( -1, -1 ) );
76 wxSize bestSize = GetBestSize();
77
78 bestSize.x = GetBestSize().x + size + 10;
79 SetMinSize( bestSize );
80
81 SetSelection( wxNOT_FOUND );
82 }
83
84 Thaw();
85}
86
87
88// Returns a color index from the layer id
90{
91 GERBVIEW_FRAME* frame = (GERBVIEW_FRAME*) GetParent()->GetParent();
92
93 return frame->GetLayerColor( GERBER_DRAW_LAYER( aLayer ) );
94}
95
96
97// Returns the name of the layer id
98wxString GBR_LAYER_BOX_SELECTOR::getLayerName( int aLayer ) const
99{
101 wxString name = images.GetDisplayName( aLayer );
102
103 return name;
104}
const char * name
Definition: DXF_plotter.cpp:57
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
COLOR4D getLayerColor(int aLayer) const override
bool isLayerEnabled(int aLayer) const override
wxString getLayerName(int aLayer) const override
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
static GERBER_FILE_IMAGE_LIST & GetImagesList()
const wxString GetDisplayName(int aIdx, bool aNameOnly=false, bool aFullName=false)
Get the display name for the layer at aIdx.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
COLOR4D GetLayerColor(int aLayer) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:223
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:437