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
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Dialog for selecting color from the palette of available colors.
*/
#include <fctsys.h>
#include <common.h>
#include <colors.h>
#include <wx/statline.h>
enum colors_id {
ID_COLOR_BLACK = 2000 // ID_COLOR_ = ID_COLOR_BLACK a ID_COLOR_BLACK + 31
};
class WinEDA_SelColorFrame : public wxDialog
{
public:
WinEDA_SelColorFrame( wxWindow* parent,
const wxPoint& framepos, int OldColor );
~WinEDA_SelColorFrame() {};
private:
void Init_Dialog( int aOldColor );
void OnCancel( wxCommandEvent& event );
void SelColor( wxCommandEvent& event );
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE( WinEDA_SelColorFrame, wxDialog )
EVT_BUTTON( wxID_CANCEL, WinEDA_SelColorFrame::OnCancel )
EVT_COMMAND_RANGE( ID_COLOR_BLACK, ID_COLOR_BLACK + 31,
wxEVT_COMMAND_BUTTON_CLICKED,
WinEDA_SelColorFrame::SelColor )
END_EVENT_TABLE()
EDA_COLOR_T DisplayColorFrame( wxWindow* parent, int OldColor )
{
wxPoint framepos;
EDA_COLOR_T color;
wxGetMousePosition( &framepos.x, &framepos.y );
WinEDA_SelColorFrame* frame = new WinEDA_SelColorFrame( parent,
framepos, OldColor );
color = static_cast<EDA_COLOR_T>( frame->ShowModal() );
frame->Destroy();
if( color > NBCOLORS )
color = UNSPECIFIED_COLOR;
return color;
}
WinEDA_SelColorFrame::WinEDA_SelColorFrame( wxWindow* parent,
const wxPoint& framepos,
int OldColor ) :
wxDialog( parent, -1, _( "Colors" ), framepos, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
{
Init_Dialog( OldColor );
// Resize the dialog
GetSizer()->SetSizeHints( this );
// Ensure the whole frame is visible, whenever the asked position.
// Moreover with a work station having dual monitors, the asked position can be relative to a monitor
// and this frame can be displayed on the other monitor, with an "out of screen" position.
// Give also a small margin.
int margin = 10;
wxPoint windowPosition = GetPosition();
if( framepos != wxDefaultPosition )
{
if( windowPosition.x < margin )
windowPosition.x = margin;
// Under MACOS, a vertical margin >= 20 is needed by the system menubar
int v_margin = std::max(20, margin);
if( windowPosition.y < v_margin )
windowPosition.y = v_margin;
if( windowPosition != framepos )
SetPosition(windowPosition);
}
wxPoint endCornerPosition = GetPosition();
endCornerPosition.x += GetSize().x + margin;
endCornerPosition.y += GetSize().y + margin;
windowPosition = GetPosition();
wxRect freeScreenArea( wxGetClientDisplayRect( ) );
if( freeScreenArea.GetRight() < endCornerPosition.x )
{
windowPosition.x += freeScreenArea.GetRight() - endCornerPosition.x;
if( windowPosition.x < freeScreenArea.x )
windowPosition.x = freeScreenArea.x;
// Sligly modify the vertical position to avoid the mouse to be
// exactly on the upper side of the window
windowPosition.y +=5;
endCornerPosition.y += 5;
}
if( freeScreenArea.GetBottom() < endCornerPosition.y )
{
windowPosition.y += freeScreenArea.GetBottom() - endCornerPosition.y;
if( windowPosition.y < freeScreenArea.y )
windowPosition.y = freeScreenArea.y;
}
SetPosition(windowPosition);
}
void WinEDA_SelColorFrame::Init_Dialog( int aOldColor )
{
wxBoxSizer* OuterBoxSizer = NULL;
wxBoxSizer* MainBoxSizer = NULL;
wxFlexGridSizer* FlexColumnBoxSizer = NULL;
wxBitmapButton* BitmapButton = NULL;
wxStaticLine* Line = NULL;
wxStdDialogButtonSizer* StdDialogButtonSizer = NULL;
wxButton* Button = NULL;
int ii, butt_ID;
int w = 20, h = 20;
bool ColorFound = false;
SetReturnCode( -1 );
OuterBoxSizer = new wxBoxSizer( wxVERTICAL );
SetSizer( OuterBoxSizer );
MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
for( ii = 0; ii < NBCOLORS; ++ii )
{
// Provide a separate column for every six buttons (and their
// associated text strings), so provide a FlexGrid Sizer with
// eight rows and two columns.
if( ii % 6 == 0 )
{
FlexColumnBoxSizer = new wxFlexGridSizer( 6, 2, 0, 0 );
// Specify that all of the rows can be expanded.
for( int ii = 0; ii < 6; ii++ )
{
FlexColumnBoxSizer->AddGrowableRow( ii );
}
// Specify that the second column can also be expanded.
FlexColumnBoxSizer->AddGrowableCol( 1 );
MainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 );
}
butt_ID = ID_COLOR_BLACK + ii;
wxMemoryDC iconDC;
wxBitmap ButtBitmap( w, h );
wxBrush brush;
iconDC.SelectObject( ButtBitmap );
EDA_COLOR_T buttcolor = g_ColorRefs[ii].m_Numcolor;
iconDC.SetPen( *wxBLACK_PEN );
ColorSetBrush( &brush, buttcolor );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
iconDC.SetBrush( brush );
iconDC.SetBackground( *wxGREY_BRUSH );
iconDC.Clear();
iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
BitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap,
wxDefaultPosition, wxSize( w+8, h+6 ) );
FlexColumnBoxSizer->Add( BitmapButton, 0,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxBOTTOM, 5 );
// Set focus to this button if its color matches the
// color which had been selected previously (for
// whichever layer's color is currently being edited).
if( aOldColor == buttcolor )
{
ColorFound = true;
BitmapButton->SetFocus();
}
wxStaticText* label = new wxStaticText( this, -1,
wxGetTranslation( ColorGetName( buttcolor ) ),
wxDefaultPosition, wxDefaultSize, 0 );
FlexColumnBoxSizer->Add( label, 1,
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
wxLEFT | wxRIGHT | wxBOTTOM, 5 );
}
// Provide a Cancel button as well, so that this dialog
// box can also be canceled by pressing the Esc key
// (and also provide a horizontal static line to separate
// that button from all of the other buttons).
Line = new wxStaticLine( this, -1, wxDefaultPosition,
wxDefaultSize, wxLI_HORIZONTAL );
OuterBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
StdDialogButtonSizer = new wxStdDialogButtonSizer;
OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 );
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), wxDefaultPosition,
wxDefaultSize, 0 );
StdDialogButtonSizer->AddButton( Button );
StdDialogButtonSizer->Realize();
// Set focus to the Cancel button if the currently selected color
// does not match any of the colors provided by this dialog box.
// (That shouldn't ever happen in practice though.)
if( !ColorFound )
Button->SetFocus();
}
void WinEDA_SelColorFrame::OnCancel( wxCommandEvent& WXUNUSED( event ) )
{
// Setting the return value to -1 indicates that the
// dialog box has been canceled (and thus that the
// previously selected color is to be retained).
EndModal( -1 );
}
void WinEDA_SelColorFrame::SelColor( wxCommandEvent& event )
{
int id = event.GetId();
EndModal( id - ID_COLOR_BLACK );
}
|