KiCad PCB EDA Suite
indicator_icon.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) 2017 KiCad Developers, see AUTHORS.TXT for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <widgets/indicator_icon.h>
25 
26 
27 INDICATOR_ICON::INDICATOR_ICON( wxWindow* aParent,
28  ICON_PROVIDER& aIconProvider,
29  ICON_ID aInitialIcon, int aID ):
30  wxPanel( aParent, aID ),
31  m_iconProvider( aIconProvider ),
32  m_currentId( aInitialIcon )
33 {
34  auto sizer = new wxBoxSizer( wxHORIZONTAL );
35  SetSizer( sizer );
36 
37  const wxBitmap& initBitmap = m_iconProvider.GetIndicatorIcon( m_currentId );
38 
39  m_bitmap = new wxStaticBitmap( this, aID,
40  initBitmap, wxDefaultPosition,
41  initBitmap.GetSize() );
42 
43  sizer->Add( m_bitmap, 0, 0 );
44 
45  auto evtSkipper = [this] ( wxEvent& aEvent ) {
46  wxPostEvent( this, aEvent );
47  };
48 
49  m_bitmap->Bind( wxEVT_LEFT_DOWN, evtSkipper );
50 }
51 
52 
54 {
55  if( aIconId == m_currentId )
56  return;
57 
58  m_currentId = aIconId;
59 
61 }
62 
63 
65 {
66  return m_currentId;
67 }
68 
69 // ====================================================================
70 // Common icon providers
71 
72 /* XPM
73  * This bitmap is used for not selected layers
74  */
75 static const char * clear_xpm[] = {
76 "10 14 1 1",
77 " c None",
78 " ",
79 " ",
80 " ",
81 " ",
82 " ",
83 " ",
84 " ",
85 " ",
86 " ",
87 " ",
88 " ",
89 " ",
90 " ",
91 " "};
92 
93 /* XPM
94  * This bitmap can be used to show a not selected layer
95  * with special property (mainly not selected layers not in use in GerbView)
96  */
97 static const char * clear_alternate_xpm[] = {
98 "10 14 4 1",
99 " c None",
100 "X c #008080",
101 "o c GREEN",
102 "O c #00B080",
103 " ",
104 " ",
105 " ",
106 " ",
107 " X ",
108 " XXX ",
109 " XXXXX ",
110 " OOOOOOO ",
111 " ooooo ",
112 " ooo ",
113 " o ",
114 " ",
115 " ",
116 " "};
117 
118 
119 /* XPM
120  * This bitmap is used for a normale selected layer
121  */
122 static const char * rightarrow_xpm[] = {
123 "10 14 4 1",
124 " c None",
125 "X c #8080ff",
126 "o c BLUE",
127 "O c gray56",
128 " X ",
129 " XX ",
130 " XXX ",
131 " XXXX ",
132 " XXXXX ",
133 " XXXXXX ",
134 " XXXXXXX ",
135 " oooooooO",
136 " ooooooO ",
137 " oooooO ",
138 " ooooO ",
139 " oooO ",
140 " ooO ",
141 " oO "};
142 
143 /* XPM
144  * This bitmap can be used to show the selected layer
145  * with special property (mainly a layer in use in GerbView)
146  */
147 static const char * rightarrow_alternate_xpm[] = {
148 "10 14 5 1",
149 " c None",
150 ". c #00B000",
151 "X c #8080ff",
152 "o c BLUE",
153 "O c gray56",
154 "..X ",
155 "..XX ",
156 "..XXX ",
157 "..XXXX ",
158 "..XXXXX ",
159 "..XXXXXX ",
160 "..XXXXXXX ",
161 "..oooooooO",
162 "..ooooooO ",
163 "..oooooO ",
164 "..ooooO ",
165 "..oooO ",
166 "..ooO ",
167 "..oO "};
168 
169 
171  m_alt( aAlt )
172 {}
173 
174 
176  INDICATOR_ICON::ICON_ID aIconId ) const
177 {
178  // need to wait until UI is ready before construction
179  // so can't go in the global scope
180  static const wxBitmap rightArrowBitmap( rightarrow_xpm );
181  static const wxBitmap rightArrowAlternateBitmap( rightarrow_alternate_xpm );
182  static const wxBitmap blankBitmap( clear_xpm );
183  static const wxBitmap blankAlternateBitmap( clear_alternate_xpm );
184 
185  const bool on = ( aIconId == STATE::ON );
186 
187  if( m_alt )
188  return ( on ? rightArrowAlternateBitmap : blankAlternateBitmap );
189 
190  return ( on ? rightArrowBitmap : blankBitmap );
191 }
static const char * clear_xpm[]
void SetIndicatorState(ICON_ID aIconId)
Sets the row indiciator to the given state.
virtual const wxBitmap & GetIndicatorIcon(ICON_ID aIconId) const =0
Gets a reference to the row icon in the given mode.
static const char * clear_alternate_xpm[]
wxStaticBitmap * m_bitmap
Handle on the bitmap widget
int ICON_ID
An id that refers to a certain icon state.
INDICATOR_ICON(wxWindow *aParent, ICON_PROVIDER &aIconProvider, ICON_ID aInitialIcon, int aID)
ICON_ID GetIndicatorState() const
ICON_PROVIDER & m_iconProvider
An class that delivers icons for the indictor (currently just uses a default implementation).
static const char * rightarrow_alternate_xpm[]
static const char * rightarrow_xpm[]
const wxBitmap & GetIndicatorIcon(INDICATOR_ICON::ICON_ID aIconId) const override
>
A simple object that can provide fixed bitmaps for use as row indicators.
ICON_ID m_currentId
Is the icon currently "on"
ROW_ICON_PROVIDER(bool aAlt)
#define ON