KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <wx/dcmemory.h>
27#include <wx/odcombo.h>
28#include <wx/menuitem.h>
29
30#include <gal/dpi_scaling.h>
31#include <layer_ids.h>
33
34
36{
37 m_layerhotkeys = true;
38}
39
40
42{
43 m_layerhotkeys = value;
44 return m_layerhotkeys;
45}
46
47
48void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, const COLOR4D& aBackground,
49 const COLOR4D& aColor )
50{
51 wxMemoryDC bmpDC;
52 wxBrush brush;
53
54 // Prepare Bitmap
55 bmpDC.SelectObject( aLayerbmp );
56
57 brush.SetStyle( wxBRUSHSTYLE_SOLID );
58
59 if( aBackground != COLOR4D::UNSPECIFIED )
60 {
61 brush.SetColour( aBackground.WithAlpha( 1.0 ).ToColour() );
62 bmpDC.SetBrush( brush );
63 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
64 }
65
66 brush.SetColour( aColor.ToColour() );
67 bmpDC.SetBrush( brush );
68 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
69
70 bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
71 bmpDC.SetPen( *wxBLACK_PEN );
72 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
73}
74
75
76LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
77 const wxSize& size, int n, const wxString choices[] ) :
78 wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
80{
81 if( choices != nullptr )
83
84 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
85 nullptr, this );
86}
87
88
89LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
90 const wxSize& size, const wxArrayString& choices ) :
91 wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
93{
94 if( !choices.IsEmpty() )
96
97 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
98 nullptr, this );
99}
100
101
103{
104 GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
105 nullptr, this );
106}
107
108
110{
111 if( GetSelection() < 0 )
112 return UNDEFINED_LAYER;
113
114 return (int)(intptr_t) GetClientData( GetSelection() );
115}
116
117
119{
120 for( int i = 0; i < (int) GetCount(); i++ )
121 {
122 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
123 {
124 if( GetSelection() != i ) // Element (i) is not selected
125 {
126 SetSelection( i );
127 return i;
128 }
129 else
130 {
131 return i; // If element already selected; do nothing
132 }
133 }
134 }
135
136 // Not Found
137 SetSelection( -1 );
138 return -1;
139}
140
141
143{
144 DPI_SCALING dpi( nullptr, this );
145 int size = static_cast<int>( dpi.GetScaleFactor() * 14 );
146
147 for( int i = 0; i < (int) GetCount(); ++i )
148 {
149 wxBitmap layerbmp( size, size );
151 }
152}
153
154
155void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
156{
157#ifdef __WXOSX_MAC__
158 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
159 {
160 Dismiss();
161 return;
162 }
163#endif
164
165 aEvent.Skip();
166}
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:37
double GetScaleFactor() const
Get the DPI scale from all known sources in order:
Definition: dpi_scaling.cpp:91
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:310
wxColour ToColour() const
Definition: color4d.cpp:219
void onKeyDown(wxKeyEvent &aEvent)
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr)
int SetLayerSelection(int layer)
Base class to build a layer list.
virtual COLOR4D getLayerColor(int aLayer) const =0
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
bool SetLayersHotkeys(bool value)
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
@ UNDEFINED_LAYER
Definition: layer_ids.h:60