KiCad PCB EDA Suite
WIDGET_EESCHEMA_COLOR_CONFIG Class Reference

#include <widget_eeschema_color_config.h>

Inheritance diagram for WIDGET_EESCHEMA_COLOR_CONFIG:

Public Member Functions

 WIDGET_EESCHEMA_COLOR_CONFIG (wxWindow *aParent, EDA_DRAW_FRAME *aDrawFrame)
 
bool TransferDataFromControl ()
 
void InstallOnPanel (wxPanel *aPanel)
 Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel. More...
 

Private Member Functions

void CreateControls ()
 
void SetColor (wxCommandEvent &aEvent)
 
virtual EDA_DRAW_FRAMEGetDrawFrame ()
 

Private Attributes

EDA_DRAW_FRAMEm_drawFrame
 
wxColourPickerCtrl * m_SelBgColor
 
wxBoxSizer * m_mainBoxSizer
 

Detailed Description

Definition at line 42 of file widget_eeschema_color_config.h.

Constructor & Destructor Documentation

WIDGET_EESCHEMA_COLOR_CONFIG::WIDGET_EESCHEMA_COLOR_CONFIG ( wxWindow *  aParent,
EDA_DRAW_FRAME aDrawFrame 
)

Definition at line 112 of file widget_eeschema_color_config.cpp.

References CreateControls().

112  :
113  wxPanel( aParent ), m_drawFrame( aDrawFrame )
114 {
115  CreateControls();
116 }

Member Function Documentation

void WIDGET_EESCHEMA_COLOR_CONFIG::CreateControls ( )
private

Definition at line 119 of file widget_eeschema_color_config.cpp.

References BUTT_SIZE_X, BUTT_SIZE_Y, buttonGroups, EDA_DRAW_FRAME::GetDrawBgColor(), GetDrawFrame(), GetLayerColor(), LAYER_BACKGROUND, BUTTONINDEX::m_Buttons, COLORBUTTON::m_Layer, m_mainBoxSizer, COLORBUTTON::m_Name, BUTTONINDEX::m_Name, and SetColor().

Referenced by WIDGET_EESCHEMA_COLOR_CONFIG().

120 {
121  wxStaticText* label;
122  int buttonId = 1800;
123 
124  m_mainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
125  SetSizer( m_mainBoxSizer );
126 
127  BUTTONINDEX* groups = buttonGroups;
128  wxBoxSizer* columnBoxSizer = NULL;
129 
130  while( groups->m_Buttons != NULL )
131  {
132  COLORBUTTON* buttons = groups->m_Buttons;
133 
134  columnBoxSizer = new wxBoxSizer( wxVERTICAL );
135  m_mainBoxSizer->Add( columnBoxSizer, 1, wxALIGN_TOP | wxLEFT | wxTOP, 5 );
136  wxBoxSizer* rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
137  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
138 
139  // Add a text string to identify the column of color select buttons.
140  label = new wxStaticText( this, wxID_ANY, groups->m_Name );
141 
142  // Make the column label font bold.
143  wxFont font( label->GetFont() );
144  font.SetWeight( wxFONTWEIGHT_BOLD );
145  label->SetFont( font );
146 
147  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
148 
149  while( buttons->m_Layer >= 0 )
150  {
151  rowBoxSizer = new wxBoxSizer( wxHORIZONTAL );
152  columnBoxSizer->Add( rowBoxSizer, 0, wxGROW | wxALL, 0 );
153 
154  COLOR4D color = GetLayerColor( LAYERSCH_ID( buttons->m_Layer ) );
155  currentColors[ buttons->m_Layer ] = color;
156 
157  wxMemoryDC iconDC;
158  wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
159 
160  iconDC.SelectObject( bitmap );
161  iconDC.SetPen( *wxBLACK_PEN );
162 
163  wxBrush brush;
164  brush.SetColour( color.ToColour() );
165  brush.SetStyle( wxBRUSHSTYLE_SOLID );
166  iconDC.SetBrush( brush );
167  iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
168 
169  wxBitmapButton* bitmapButton = new wxBitmapButton(
170  this, buttonId, bitmap, wxDefaultPosition,
171  wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) );
172  bitmapButton->SetClientData( (void*) buttons );
173 
174  rowBoxSizer->Add( bitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
175 
176  label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) );
177  rowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
178  buttonId += 1;
179  buttons++;
180  }
181 
182  groups++;
183  }
184 
185  COLOR4D bgColor = GetDrawFrame()->GetDrawBgColor();
186  wxMemoryDC iconDC;
187  wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
188 
189  iconDC.SelectObject( bitmap );
190  iconDC.SetPen( *wxBLACK_PEN );
191 
192  wxBrush brush;
193  brush.SetColour( bgColor.ToColour() );
194  brush.SetStyle( wxBRUSHSTYLE_SOLID );
195  iconDC.SetBrush( brush );
196  iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
197 
198  buttonId++;
199  wxBitmapButton* selBgColorBtn = new wxBitmapButton(
200  this, buttonId, bitmap, wxDefaultPosition,
201  wxSize( BUTT_SIZE_X + 8, BUTT_SIZE_Y + 6 ) );
202  selBgColorBtn->SetClientData( (void*) &bgColorButton );
203 
204  Connect( 1800, buttonId, wxEVT_COMMAND_BUTTON_CLICKED,
205  wxCommandEventHandler( WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ) );
206 
207  wxStaticText* bgColorLabel = new wxStaticText( this, wxID_ANY, _( "Background Color" ) );
208  wxFont font( bgColorLabel->GetFont() );
209  font.SetWeight( wxFONTWEIGHT_BOLD );
210  bgColorLabel->SetFont( font );
211 
212  if( columnBoxSizer )
213  {
214  // Add a spacer to improve appearance.
215  columnBoxSizer->AddSpacer( 5 );
216  columnBoxSizer->Add( bgColorLabel, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
217  columnBoxSizer->Add( selBgColorBtn, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 );
218  }
219 
220  currentColors[ LAYER_BACKGROUND ] = bgColor;
221 
222  // Dialog now needs to be resized, but the associated command is found elsewhere.
223 }
static BUTTONINDEX buttonGroups[]
static COLORBUTTON bgColorButton
static COLOR4D currentColors[LAYERSCH_ID_COUNT]
COLOR4D GetLayerColor(LAYERSCH_ID aLayer)
Definition: eeschema.cpp:166
LAYERSCH_ID
Definition: general.h:75
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:286
const int BUTT_SIZE_Y
const int BUTT_SIZE_X
virtual EDA_DRAW_FRAME * GetDrawFrame()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
virtual EDA_DRAW_FRAME* WIDGET_EESCHEMA_COLOR_CONFIG::GetDrawFrame ( )
inlineprivatevirtual

Definition at line 54 of file widget_eeschema_color_config.h.

References m_drawFrame.

Referenced by CreateControls(), and TransferDataFromControl().

54 { return m_drawFrame; }
void WIDGET_EESCHEMA_COLOR_CONFIG::InstallOnPanel ( wxPanel *  aPanel)

Method InstallOnPanel Install this WIDGET_EESCHEMA_COLOR_CONFIG onto an empty panel.

This is useful when combining with wxFormBuilder, as an empty panel can be left as a placeholder in the layout.

Definition at line 318 of file widget_eeschema_color_config.cpp.

Referenced by DIALOG_EESCHEMA_OPTIONS::DIALOG_EESCHEMA_OPTIONS().

319 {
320  wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
321 
322  sizer->Add( this, 1, wxALL | wxEXPAND, 0 );
323  aPanel->SetSizer( sizer );
324 }
void WIDGET_EESCHEMA_COLOR_CONFIG::SetColor ( wxCommandEvent &  aEvent)
private

Definition at line 226 of file widget_eeschema_color_config.cpp.

References BUTT_SIZE_X, BUTT_SIZE_Y, COLORBUTTON::m_Layer, and Refresh().

Referenced by CreateControls().

227 {
228  wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject();
229 
230  wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) );
231 
232  COLORBUTTON* colorButton = (COLORBUTTON*) button->GetClientData();
233 
234  wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) );
235 
236  wxColourData colourData;
237  colourData.SetColour( currentColors[ colorButton->m_Layer ].ToColour() );
238  wxColourDialog *dialog = new wxColourDialog( this, &colourData );
239 
240  COLOR4D newColor = COLOR4D::UNSPECIFIED;
241 
242  if( dialog->ShowModal() == wxID_OK )
243  {
244  newColor = COLOR4D( dialog->GetColourData().GetColour() );
245  }
246 
247  if( newColor == COLOR4D::UNSPECIFIED || currentColors[ colorButton->m_Layer ] == newColor )
248  return;
249 
250  currentColors[ colorButton->m_Layer ] = newColor;
251 
252  wxMemoryDC iconDC;
253 
254  wxBitmap bitmap = button->GetBitmapLabel();
255  iconDC.SelectObject( bitmap );
256  iconDC.SetPen( *wxBLACK_PEN );
257 
258  wxBrush brush;
259  brush.SetColour( newColor.ToColour() );
260  brush.SetStyle( wxBRUSHSTYLE_SOLID );
261 
262  iconDC.SetBrush( brush );
263  iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
264  button->SetBitmapLabel( bitmap );
265  button->Refresh();
266 
267  Refresh( false );
268 }
static COLOR4D currentColors[LAYERSCH_ID_COUNT]
void Refresh()
const int BUTT_SIZE_Y
const int BUTT_SIZE_X
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
bool WIDGET_EESCHEMA_COLOR_CONFIG::TransferDataFromControl ( )

Definition at line 271 of file widget_eeschema_color_config.cpp.

References EDA_DRAW_FRAME::GetCanvas(), GetDrawFrame(), GetLayerColor(), LAYER_BACKGROUND, LAYER_GRID, LAYER_WIRE, LAYERSCH_ID_COUNT, EDA_DRAW_PANEL::Refresh(), EDA_DRAW_FRAME::SetDrawBgColor(), EDA_DRAW_FRAME::SetGridColor(), and SetLayerColor().

Referenced by DIALOG_EESCHEMA_OPTIONS::TransferDataFromWindow().

272 {
273  bool warning = false;
274 
275  // Check for color conflicts with background color to give user a chance to bail
276  // out before making changes.
277 
279 
280  for( LAYERSCH_ID clyr = LAYER_WIRE; clyr < LAYERSCH_ID_COUNT; ++clyr )
281  {
282  if( bgcolor == currentColors[ clyr ] && clyr != LAYER_BACKGROUND )
283  {
284  warning = true;
285  break;
286  }
287  }
288 
289  // Prompt the user if an item has the same color as the background
290  // because this item cannot be seen:
291  if( warning )
292  {
293  if( wxMessageBox( _( "Some items have the same color as the background\n"
294  "and they will not be seen on the screen. Are you\n"
295  "sure you want to use these colors?" ),
296  _( "Warning" ),
297  wxYES_NO | wxICON_QUESTION, this ) == wxNO )
298  return false;
299  }
300 
301  // Update color of background
302  GetDrawFrame()->SetDrawBgColor( bgcolor );
303  currentColors[ LAYER_BACKGROUND ] = bgcolor;
304 
305 
306  for( LAYERSCH_ID clyr = LAYER_WIRE; clyr < LAYERSCH_ID_COUNT; ++clyr )
307  {
308  SetLayerColor( currentColors[ clyr ], clyr );
309  }
310 
313 
314  return true;
315 }
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
virtual void SetDrawBgColor(COLOR4D aColor)
Definition: draw_frame.h:291
virtual void SetGridColor(COLOR4D aColor)
Function SetGridColor() , virtual.
Definition: draw_frame.h:444
static COLOR4D currentColors[LAYERSCH_ID_COUNT]
COLOR4D GetLayerColor(LAYERSCH_ID aLayer)
Definition: eeschema.cpp:166
LAYERSCH_ID
Definition: general.h:75
void SetLayerColor(COLOR4D aColor, LAYERSCH_ID aLayer)
Definition: eeschema.cpp:172
virtual EDA_DRAW_FRAME * GetDrawFrame()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

Member Data Documentation

EDA_DRAW_FRAME* WIDGET_EESCHEMA_COLOR_CONFIG::m_drawFrame
private

Definition at line 45 of file widget_eeschema_color_config.h.

Referenced by GetDrawFrame().

wxBoxSizer* WIDGET_EESCHEMA_COLOR_CONFIG::m_mainBoxSizer
private

Definition at line 47 of file widget_eeschema_color_config.h.

Referenced by CreateControls().

wxColourPickerCtrl* WIDGET_EESCHEMA_COLOR_CONFIG::m_SelBgColor
private

Definition at line 46 of file widget_eeschema_color_config.h.


The documentation for this class was generated from the following files: