1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/***************/
/* eelayer.cpp */
/***************/
/* Set up color Layers for EESchema
*/
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "eelayer.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "id.h"
#include "protos.h"
#include "eelayer.h" // Header file associated with this file
// Local variables:
int CurrentColor[NB_BUTT]; // Holds color for each layer while dialog box open
IMPLEMENT_DYNAMIC_CLASS( WinEDA_SetColorsFrame, wxDialog )
// Table of events for WinEDA_SetColorsFrame
BEGIN_EVENT_TABLE( WinEDA_SetColorsFrame, wxDialog )
EVT_COMMAND_RANGE( ID_COLOR_SETUP, ID_COLOR_SETUP + NB_BUTT - 1,
wxEVT_COMMAND_BUTTON_CLICKED,
WinEDA_SetColorsFrame::SetColor )
EVT_BUTTON( wxID_OK, WinEDA_SetColorsFrame::OnOkClick )
EVT_BUTTON( wxID_CANCEL, WinEDA_SetColorsFrame::OnCancelClick )
EVT_BUTTON( wxID_APPLY, WinEDA_SetColorsFrame::OnApplyClick )
END_EVENT_TABLE()
/**************************************************************/
void DisplayColorSetupFrame( WinEDA_DrawFrame* parent,
const wxPoint& framepos )
/**************************************************************/
{
WinEDA_SetColorsFrame* frame =
new WinEDA_SetColorsFrame( parent, framepos );
frame->ShowModal();
frame->Destroy();
}
// Default Constructor (whose provision is mandated by the inclusion
// of DECLARE_DYNAMIC_CLASS( WinEDA_SetColorsFrame ) within eelayer.h)
WinEDA_SetColorsFrame::WinEDA_SetColorsFrame()
{
Init();
}
// Standard Constructor
WinEDA_SetColorsFrame::WinEDA_SetColorsFrame( WinEDA_DrawFrame* parent,
const wxPoint& framepos )
{
m_Parent = parent;
Init();
Create( parent,
SYMBOL_WINEDA_SETCOLORSFRAME_IDNAME,
SYMBOL_WINEDA_SETCOLORSFRAME_TITLE,
framepos,
wxDefaultSize,
SYMBOL_WINEDA_SETCOLORSFRAME_STYLE );
}
// Destructor
WinEDA_SetColorsFrame::~WinEDA_SetColorsFrame() { }
/**********************************************************/
bool WinEDA_SetColorsFrame::Create( wxWindow* parent, wxWindowID id,
const wxString& caption, const wxPoint& pos,
const wxSize& size, long style )
/**********************************************************/
{
SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
wxDialog::Create( parent, id, caption, pos, size, style );
CreateControls();
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
return true;
}
/**********************************************************/
void WinEDA_SetColorsFrame::Init()
/**********************************************************/
{
OuterBoxSizer = NULL;
MainBoxSizer = NULL;
ColumnBoxSizer = NULL;
RowBoxSizer = NULL;
Label = NULL;
BitmapButton = NULL;
m_ShowGrid = NULL;
m_SelBgColor = NULL;
Line = NULL;
StdDialogButtonSizer = NULL;
Button = NULL;
}
/**********************************************************/
void WinEDA_SetColorsFrame::CreateControls()
/**********************************************************/
{
int lyr, grp, butt_ID, buttcolor;
SetFont( *g_DialogFont );
OuterBoxSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(OuterBoxSizer);
MainBoxSizer = new wxBoxSizer(wxHORIZONTAL);
OuterBoxSizer->Add(MainBoxSizer, 1, wxGROW|wxLEFT|wxRIGHT, 5);
// Add various items to the dialog box, as determined by the
// details of each element contained within laytool_list[]
for( lyr = 0, grp = 0; lyr < NB_BUTT; lyr++ )
{
// Look for the initial button of each group of controls.
if( lyr == 0 || lyr == laytool_index[grp]->m_Index + 1 )
{
if( lyr != 0 )
grp++;
// Add another column sizer, unless the current value of
// grp is BUTTON_GROUPS - 1. (The very last group of controls
// differs from the previous groups in that its associated
// controls are located in the same column as the controls
// associated with the preceeding group.)
if( grp < BUTTON_GROUPS - 1 )
{
ColumnBoxSizer = new wxBoxSizer(wxVERTICAL);
MainBoxSizer->Add(ColumnBoxSizer, 1, wxALIGN_TOP|wxLEFT|wxTOP, 5);
}
else
{
// Add a spacer to better separate the text string (which is
// about to be added) from the items located above it.
ColumnBoxSizer->AddSpacer(5);
}
RowBoxSizer = new wxBoxSizer(wxHORIZONTAL);
ColumnBoxSizer->Add(RowBoxSizer, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
// Add a text string to identify the following set of controls
Label = new wxStaticText( this, -1, laytool_index[grp]->m_Name,
wxDefaultPosition, wxDefaultSize, 0 );
// Make this text string bold (so that it stands out better)
Label->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxNORMAL_FONT->GetFamily(),
wxNORMAL, wxBOLD, false, wxNORMAL_FONT->GetFaceName() ) );
RowBoxSizer->Add(Label, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
}
RowBoxSizer = new wxBoxSizer(wxHORIZONTAL);
ColumnBoxSizer->Add(RowBoxSizer, 0, wxGROW|wxALL, 0);
butt_ID = ID_COLOR_SETUP + lyr;
laytool_list[lyr]->m_Id = butt_ID;
wxMemoryDC iconDC;
wxBitmap ButtBitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
iconDC.SelectObject( ButtBitmap );
buttcolor = *laytool_list[lyr]->m_Color;
CurrentColor[lyr] = buttcolor;
wxBrush Brush;
iconDC.SelectObject( ButtBitmap );
iconDC.SetPen( *wxBLACK_PEN );
Brush.SetColour(
ColorRefs[buttcolor].m_Red,
ColorRefs[buttcolor].m_Green,
ColorRefs[buttcolor].m_Blue
);
Brush.SetStyle( wxSOLID );
iconDC.SetBrush( Brush );
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
BitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap, wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y) );
RowBoxSizer->Add(BitmapButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
laytool_list[lyr]->m_Button = BitmapButton;
// Add a text string, unless the current value of lyr is NB_BUTT - 1
if( lyr < NB_BUTT - 1 )
{
Label = new wxStaticText( this, wxID_STATIC, wxGetTranslation( laytool_list[lyr]->m_Name ),
wxDefaultPosition, wxDefaultSize, 0 );
RowBoxSizer->Add(Label, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
}
else
{
// Special case; provide a checkbox instead (rather than a text string).
m_ShowGrid = new wxCheckBox( this, ID_CHECKBOX_SHOW_GRID, _("Grid"), wxDefaultPosition, wxDefaultSize, 0 );
m_ShowGrid->SetValue( m_Parent->m_Draw_Grid );
RowBoxSizer->Add(m_ShowGrid, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
}
}
// Add a spacer to improve appearance.
ColumnBoxSizer->AddSpacer(5);
wxArrayString m_SelBgColorStrings;
m_SelBgColorStrings.Add(_("White"));
m_SelBgColorStrings.Add(_("Black"));
m_SelBgColor = new wxRadioBox( this, ID_RADIOBOX_BACKGROUND_COLOR, _("Background Color:"),
wxDefaultPosition, wxDefaultSize, m_SelBgColorStrings, 1, wxRA_SPECIFY_COLS );
m_SelBgColor->SetSelection( ( g_DrawBgColor == BLACK ) ? 1 : 0 );
ColumnBoxSizer->Add(m_SelBgColor, 1, wxGROW|wxRIGHT|wxTOP|wxBOTTOM, 5);
// Provide a line to separate all of the controls added so far from the
// "OK", "Cancel", and "Apply" buttons (which will be added after that line).
Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
OuterBoxSizer->Add(Line, 0, wxGROW|wxALL, 5);
// Provide a StdDialogButtonSizer to accommodate the OK, Cancel, and Apply
// buttons; using that type of sizer results in those buttons being
// automatically located in positions appropriate for each (OS) version of KiCad.
StdDialogButtonSizer = new wxStdDialogButtonSizer;
OuterBoxSizer->Add(StdDialogButtonSizer, 0, wxGROW|wxALL, 10);
Button = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
Button->SetForegroundColour( *wxRED );
StdDialogButtonSizer->AddButton(Button);
Button = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
Button->SetForegroundColour( *wxBLUE );
StdDialogButtonSizer->AddButton(Button);
Button = new wxButton( this, wxID_APPLY, _("Apply"), wxDefaultPosition, wxDefaultSize, 0 );
StdDialogButtonSizer->AddButton(Button);
StdDialogButtonSizer->Realize();
// (Dialog now needs to be resized, but the associated command is found elsewhere.)
}
/**********************************************************/
bool WinEDA_SetColorsFrame::ShowToolTips()
/**********************************************************/
{
return true;
}
/**********************************************************/
wxBitmap WinEDA_SetColorsFrame::GetBitmapResource( const wxString& name )
/**********************************************************/
{
wxUnusedVar(name);
return wxNullBitmap;
}
/**********************************************************/
wxIcon WinEDA_SetColorsFrame::GetIconResource( const wxString& name )
/**********************************************************/
{
wxUnusedVar(name);
return wxNullIcon;
}
/**********************************************************/
void WinEDA_SetColorsFrame::SetColor( wxCommandEvent& event )
/**********************************************************/
{
int id = event.GetId();
int color;
wxBitmapButton* Button;
color = DisplayColorFrame( this,
CurrentColor[id - ID_COLOR_SETUP] );
if( color < 0 )
return;
if( CurrentColor[id - ID_COLOR_SETUP] == color )
return;
CurrentColor[id - ID_COLOR_SETUP] = color;
wxMemoryDC iconDC;
Button = laytool_list[id - ID_COLOR_SETUP]->m_Button;
wxBitmap ButtBitmap = Button->GetBitmapLabel();
iconDC.SelectObject( ButtBitmap );
wxBrush Brush;
iconDC.SetPen( *wxBLACK_PEN );
Brush.SetColour(
ColorRefs[color].m_Red,
ColorRefs[color].m_Green,
ColorRefs[color].m_Blue
);
Brush.SetStyle( wxSOLID );
iconDC.SetBrush( Brush );
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
Button->SetBitmapLabel( ButtBitmap );
Button->Refresh();
Refresh( FALSE );
}
/******************************************************************/
void WinEDA_SetColorsFrame::UpdateLayerSettings()
/******************************************************************/
{
// Update colors for each layer
for( int lyr = 0; lyr < NB_BUTT; lyr++ )
{
// (As a bitmap button has been provided for *every* layer,
// it is not necessary to check whether it actually has been
// provided for each of those layers.)
*laytool_list[lyr]->m_Color = CurrentColor[lyr];
}
// Update whether grid is actually displayed or otherwise
// m_Parent->m_Draw_Grid = g_ShowGrid = m_ShowGrid->GetValue();
// The previous command compiles OK, but to prevent a warning
// from being generated when the Linux version is being compiled,
// the next two commands are provided instead.
g_ShowGrid = m_ShowGrid->GetValue();
m_Parent->m_Draw_Grid = g_ShowGrid;
// Update color of background
if( m_SelBgColor->GetSelection() == 0 )
g_DrawBgColor = WHITE;
else
g_DrawBgColor = BLACK;
m_Parent->SetDrawBgColor( g_DrawBgColor );
}
/**********************************************************************/
void WinEDA_SetColorsFrame::OnOkClick( wxCommandEvent& WXUNUSED (event) )
/**********************************************************************/
{
UpdateLayerSettings();
m_Parent->ReDrawPanel();
EndModal( 1 );
}
/*******************************************************************/
void WinEDA_SetColorsFrame::OnCancelClick( wxCommandEvent& WXUNUSED (event) )
/*******************************************************************/
{
EndModal( -1 );
}
/*******************************************************************/
void WinEDA_SetColorsFrame::OnApplyClick( wxCommandEvent& WXUNUSED (event) )
/*******************************************************************/
{
UpdateLayerSettings();
m_Parent->ReDrawPanel();
}
/*************************/
void SeedLayers()
/*************************/
{
LayerStruct* LayerPointer = &g_LayerDescr;
int pt;
LayerPointer->CommonColor = WHITE;
LayerPointer->Flags = 0;
pt = 0;
LayerPointer->CurrentWidth = 1;
/* seed Up the Layer colours, set all user layers off */
for( pt = 0; pt < MAX_LAYERS; pt++ )
{
LayerPointer->LayerStatus[pt] = 0;
LayerPointer->LayerColor[pt] = DARKGRAY;
}
LayerPointer->NumberOfLayers = pt - 1;
/* Couleurs specifiques: Mise a jour par la lecture de la config */
}
/*******************************/
int ReturnLayerColor( int Layer )
/*******************************/
{
if( g_LayerDescr.Flags == 0 )
return g_LayerDescr.LayerColor[Layer];
else
return g_LayerDescr.CommonColor;
}