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