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#ifdef __WXMAC__
84 GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
85 nullptr, this );
86#endif
87}
88
89
91{
92#ifdef __WXMAC__
93 GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ),
94 nullptr, this );
95#endif
96}
97
98
100{
101 if( GetSelection() < 0 )
102 return UNDEFINED_LAYER;
103
104 return (int)(intptr_t) GetClientData( GetSelection() );
105}
106
107
109{
110 for( int i = 0; i < (int) GetCount(); i++ )
111 {
112 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
113 {
114 if( GetSelection() != i ) // Element (i) is not selected
115 {
116 SetSelection( i );
117 return i;
118 }
119 else
120 {
121 return i; // If element already selected; do nothing
122 }
123 }
124 }
125
126 // Not Found
127 SetSelection( -1 );
128 return -1;
129}
130
131
132#ifdef __WXMAC__
133
134void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
135{
136 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
137 {
138 Dismiss();
139 return;
140 }
141
142 aEvent.Skip();
143}
144
145
146void LAYER_BOX_SELECTOR::OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags) const
147{
148 if( ( flags & wxODCB_PAINTING_CONTROL ) && !IsEnabled() )
149 {
150 wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
151 wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
152
154 bgCol = bgCol.ChangeLightness( 106 );
155 else
156 bgCol = bgCol.ChangeLightness( 160 );
157
158 dc.SetTextForeground( fgCol );
159 dc.SetBrush( bgCol );
160 dc.SetPen( bgCol );
161 dc.DrawRectangle( rect.Inflate( 1, 1 ) );
162 dc.SetClippingRegion( rect );
163 return;
164 }
165
166 wxBitmapComboBox::OnDrawBackground( dc, rect, item, flags );
167}
168
169#endif
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.
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
bool SetLayersHotkeys(bool value)
@ 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: wxgtk/ui.cpp:48