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-2023 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#include <wx/settings.h>
30
31#include <dpi_scaling_common.h>
32#include <layer_ids.h>
34#include "kiplatform/ui.h"
35
36
38{
39 m_layerhotkeys = true;
40}
41
42
44{
45 m_layerhotkeys = value;
46 return m_layerhotkeys;
47}
48
49
50void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, const COLOR4D& aBackground,
51 const COLOR4D& aColor )
52{
53 wxMemoryDC bmpDC;
54 wxBrush brush;
55
56 // Prepare Bitmap
57 bmpDC.SelectObject( aLayerbmp );
58
59 brush.SetStyle( wxBRUSHSTYLE_SOLID );
60
61 if( aBackground != COLOR4D::UNSPECIFIED )
62 {
63 brush.SetColour( aBackground.WithAlpha( 1.0 ).ToColour() );
64 bmpDC.SetBrush( brush );
65 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
66 }
67
68 brush.SetColour( aColor.ToColour() );
69 bmpDC.SetBrush( brush );
70 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
71
72 bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
73 bmpDC.SetPen( *wxBLACK_PEN );
74 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
75}
76
77
78LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos,
79 const wxSize& size, int n, const wxString choices[] ) :
80 wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
82{
83 if( choices != nullptr )
85
86#ifdef __WXMAC__
87 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
88 nullptr, this );
89#endif
90}
91
92
94{
95#ifdef __WXMAC__
96 GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
97 nullptr, this );
98#endif
99}
100
101
103{
104 if( GetSelection() < 0 )
105 return UNDEFINED_LAYER;
106
107 return (int)(intptr_t) GetClientData( GetSelection() );
108}
109
110
112{
113 for( int i = 0; i < (int) GetCount(); i++ )
114 {
115 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
116 {
117 if( GetSelection() != i ) // Element (i) is not selected
118 {
119 SetSelection( i );
120 return i;
121 }
122 else
123 {
124 return i; // If element already selected; do nothing
125 }
126 }
127 }
128
129 // Not Found
130 SetSelection( -1 );
131 return -1;
132}
133
134
136{
137 DPI_SCALING_COMMON dpi( nullptr, this );
138 int size = static_cast<int>( dpi.GetScaleFactor() * 14 );
139
140 for( int i = 0; i < (int) GetCount(); ++i )
141 {
142 wxBitmap layerbmp( size, size );
144 }
145}
146
147
148#ifdef __WXMAC__
149
150void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
151{
152 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
153 {
154 Dismiss();
155 return;
156 }
157
158 aEvent.Skip();
159}
160
161
162void LAYER_BOX_SELECTOR::OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags) const
163{
164 if( ( flags & wxODCB_PAINTING_CONTROL ) && !IsEnabled() )
165 {
166 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
167 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
168
170 bgCol = bgCol.ChangeLightness( 106 );
171 else
172 bgCol = bgCol.ChangeLightness( 160 );
173
174 dc.SetTextForeground( fgCol );
175 dc.SetBrush( bgCol );
176 dc.SetPen( bgCol );
177 dc.DrawRectangle( rect.Inflate( 1, 1 ) );
178 dc.SetClippingRegion( rect );
179 return;
180 }
181
182 wxBitmapComboBox::OnDrawBackground( dc, rect, item, flags );
183}
184
185#endif
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:311
wxColour ToColour() const
Definition: color4d.cpp:220
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:224
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:48