KiCad PCB EDA Suite
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 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 
26 #include <bitmaps.h>
27 
28 #include <wx/wx.h>
29 #include <wx/odcombo.h>
30 #include <wx/menuitem.h>
31 
33 
35 {
36  m_layerhotkeys = true;
37  m_hotkeys = NULL;
38 }
39 
40 
42 {
43  m_layerhotkeys = value;
44  return m_layerhotkeys;
45 }
46 
47 
48 void LAYER_SELECTOR::DrawColorSwatch( wxBitmap& aLayerbmp, COLOR4D aBackground, COLOR4D aColor )
49 {
50  wxMemoryDC bmpDC;
51  wxBrush brush;
52 
53  // Prepare Bitmap
54  bmpDC.SelectObject( aLayerbmp );
55 
56  brush.SetStyle( wxBRUSHSTYLE_SOLID );
57  if( aBackground != COLOR4D::UNSPECIFIED )
58  {
59  brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
60  bmpDC.SetBrush( brush );
61  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
62  }
63 
64  brush.SetColour( aColor.ToColour() );
65  bmpDC.SetBrush( brush );
66  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
67 
68  bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
69  bmpDC.SetPen( *wxBLACK_PEN );
70  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
71 }
72 
73 
74 /* class to display a layer list in a wxBitmapComboBox.
75  */
76 
77 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
78  const wxPoint& pos, const wxSize& size,
79  int n, const wxString choices[] ) :
80  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
82 {
83  m_hotkeys = NULL;
84 
85  if( choices != NULL )
87 
88  GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ), NULL, this );
89 }
90 
91 
92 LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
93  const wxPoint& pos, const wxSize& size,
94  const wxArrayString& choices ) :
95  wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
97 {
98  m_hotkeys = NULL;
99 
100  if( !choices.IsEmpty() )
102 
103  GetParent()->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ), NULL, this );
104 }
105 
106 
108 {
109  GetParent()->Disconnect( wxEVT_CHAR_HOOK, wxKeyEventHandler( LAYER_BOX_SELECTOR::onKeyDown ), NULL, this );
110 }
111 
112 
113 // Get Current Item #
115 {
116  return GetSelection();
117 }
118 
119 
120 // Get Current Layer
122 {
123  if( GetSelection() < 0 )
124  return UNDEFINED_LAYER;
125 
126  return (LAYER_NUM)(intptr_t) GetClientData( GetSelection() );
127 }
128 
129 
130 // Set Layer #
132 {
133  int elements = GetCount();
134 
135  for( int i = 0; i < elements; i++ )
136  {
137  if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
138  {
139  if( GetSelection() != i ) // Element (i) is not selected
140  {
141  SetSelection( i );
142  return i;
143  }
144  else
145  return i; //If element already selected; do nothing
146  }
147  }
148 
149  // Not Found
150  SetSelection( -1 );
151  return -1;
152 }
153 
154 
156 {
157  int elements = GetCount();
158 
159  for( LAYER_NUM i = 0; i < elements; ++i )
160  {
161  wxBitmap layerbmp( 14, 14 );
163  }
164 }
165 
166 
167 void LAYER_BOX_SELECTOR::onKeyDown( wxKeyEvent& aEvent )
168 {
169 #ifdef __WXOSX_MAC__
170  if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
171  {
172  Dismiss();
173  return;
174  }
175 #endif
176 
177  aEvent.Skip();
178 }
virtual COLOR4D GetLayerColor(LAYER_NUM aLayer) const =0
struct EDA_HOTKEY_CONFIG * m_hotkeys
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL)
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:233
int SetLayerSelection(LAYER_NUM layer)
struct EDA_HOTKEY_CONFIG * m_hotkeys
bool SetLayersHotkeys(bool value)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
Board layer functions and definitions.
size_t i
Definition: json11.cpp:597
LAYER_NUM GetLayerSelection() const
void onKeyDown(wxKeyEvent &aEvent)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39