2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Dialog for selecting color from the palette of available colors.
|
2007-09-13 09:24:43 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <colors.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/statline.h>
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
enum colors_id {
|
2016-04-23 15:44:17 +00:00
|
|
|
ID_COLOR_BLACK = 2000 // colors_id = ID_COLOR_BLACK a ID_COLOR_BLACK + NBCOLORS-1
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
class CHOOSE_COLOR_DLG : public wxDialog
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-04-23 15:44:17 +00:00
|
|
|
CHOOSE_COLOR_DLG( wxWindow* aParent, EDA_COLOR_T aOldColor );
|
|
|
|
~CHOOSE_COLOR_DLG() {};
|
|
|
|
|
|
|
|
EDA_COLOR_T GetSelectedColor() { return m_color; }
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2016-04-23 15:44:17 +00:00
|
|
|
void init_Dialog();
|
|
|
|
void selColor( wxCommandEvent& event );
|
|
|
|
|
|
|
|
EDA_COLOR_T m_color;
|
2009-05-01 18:06:03 +00:00
|
|
|
|
2007-10-21 10:01:15 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
2007-09-13 09:24:43 +00:00
|
|
|
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
BEGIN_EVENT_TABLE( CHOOSE_COLOR_DLG, wxDialog )
|
|
|
|
EVT_COMMAND_RANGE( ID_COLOR_BLACK, ID_COLOR_BLACK + NBCOLORS,
|
2007-10-21 10:01:15 +00:00
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED,
|
2016-04-23 15:44:17 +00:00
|
|
|
CHOOSE_COLOR_DLG::selColor )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-09-13 09:24:43 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
EDA_COLOR_T DisplayColorFrame( wxWindow* aParent, EDA_COLOR_T aOldColor )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-04-23 15:44:17 +00:00
|
|
|
CHOOSE_COLOR_DLG dlg( aParent, aOldColor );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
return dlg.GetSelectedColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSPECIFIED_COLOR;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 09:24:43 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
CHOOSE_COLOR_DLG::CHOOSE_COLOR_DLG( wxWindow* aParent, EDA_COLOR_T aOldColor ) :
|
2016-04-26 12:16:16 +00:00
|
|
|
wxDialog( aParent, wxID_ANY, _( "Colors" ), wxDefaultPosition, wxDefaultSize,
|
2013-11-15 09:28:31 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2010-01-23 10:50:05 +00:00
|
|
|
{
|
2016-04-23 15:44:17 +00:00
|
|
|
m_color = aOldColor;
|
2010-01-23 10:50:05 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
init_Dialog();
|
2010-01-23 10:50:05 +00:00
|
|
|
// Resize the dialog
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2016-04-26 12:16:16 +00:00
|
|
|
|
|
|
|
Centre();
|
2010-01-23 10:50:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
void CHOOSE_COLOR_DLG::init_Dialog()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
wxFlexGridSizer* FlexColumnBoxSizer = NULL;
|
2016-04-23 15:44:17 +00:00
|
|
|
wxBitmapButton* focusedButton = NULL;
|
|
|
|
const int w = 20, h = 20;
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxBoxSizer* OuterBoxSizer = new wxBoxSizer( wxVERTICAL );
|
2009-05-01 18:06:03 +00:00
|
|
|
SetSizer( OuterBoxSizer );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxBoxSizer*MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
2009-05-01 18:06:03 +00:00
|
|
|
OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
for( int ii = 0; ii < NBCOLORS; ++ii )
|
2007-10-21 10:01:15 +00:00
|
|
|
{
|
2013-04-05 17:23:56 +00:00
|
|
|
// Provide a separate column for every six buttons (and their
|
2009-05-01 18:06:03 +00:00
|
|
|
// associated text strings), so provide a FlexGrid Sizer with
|
2016-04-23 15:44:17 +00:00
|
|
|
// six rows and two columns.
|
2013-04-05 17:23:56 +00:00
|
|
|
if( ii % 6 == 0 )
|
2007-10-21 10:01:15 +00:00
|
|
|
{
|
2013-04-05 17:23:56 +00:00
|
|
|
FlexColumnBoxSizer = new wxFlexGridSizer( 6, 2, 0, 0 );
|
2007-11-11 09:09:53 +00:00
|
|
|
|
|
|
|
// Specify that all of the rows can be expanded.
|
2016-04-23 15:44:17 +00:00
|
|
|
for( int kk = 0; kk < 6; kk++ )
|
2007-11-11 09:09:53 +00:00
|
|
|
{
|
2016-04-23 15:44:17 +00:00
|
|
|
FlexColumnBoxSizer->AddGrowableRow( kk );
|
2007-11-11 09:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Specify that the second column can also be expanded.
|
2009-05-01 18:06:03 +00:00
|
|
|
FlexColumnBoxSizer->AddGrowableCol( 1 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
MainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 );
|
2007-11-11 09:09:53 +00:00
|
|
|
}
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
int butt_ID = ID_COLOR_BLACK + ii;
|
2007-10-21 10:01:15 +00:00
|
|
|
wxMemoryDC iconDC;
|
2009-05-01 18:06:03 +00:00
|
|
|
wxBitmap ButtBitmap( w, h );
|
2014-01-08 01:34:04 +00:00
|
|
|
wxBrush brush;
|
|
|
|
|
2007-10-21 10:01:15 +00:00
|
|
|
iconDC.SelectObject( ButtBitmap );
|
2014-01-08 01:34:04 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
EDA_COLOR_T buttcolor = g_ColorRefs[ii].m_Numcolor;
|
2014-01-08 01:34:04 +00:00
|
|
|
|
2007-10-21 10:01:15 +00:00
|
|
|
iconDC.SetPen( *wxBLACK_PEN );
|
2014-01-08 01:34:04 +00:00
|
|
|
ColorSetBrush( &brush, buttcolor );
|
|
|
|
brush.SetStyle( wxBRUSHSTYLE_SOLID );
|
|
|
|
|
|
|
|
iconDC.SetBrush( brush );
|
2007-10-21 10:01:15 +00:00
|
|
|
iconDC.SetBackground( *wxGREY_BRUSH );
|
|
|
|
iconDC.Clear();
|
2009-05-01 18:06:03 +00:00
|
|
|
iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxBitmapButton* bitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap,
|
2010-07-27 12:47:08 +00:00
|
|
|
wxDefaultPosition, wxSize( w+8, h+6 ) );
|
2016-04-23 15:44:17 +00:00
|
|
|
FlexColumnBoxSizer->Add( bitmapButton, 0,
|
2009-05-01 18:06:03 +00:00
|
|
|
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxBOTTOM, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
|
|
|
// 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).
|
2016-04-23 15:44:17 +00:00
|
|
|
if( m_color == buttcolor )
|
|
|
|
focusedButton = bitmapButton;
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxStaticText* label = new wxStaticText( this, -1, ColorGetName( buttcolor ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
FlexColumnBoxSizer->Add( label, 1,
|
2009-05-01 18:06:03 +00:00
|
|
|
wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provide a Cancel button as well, so that this dialog
|
2009-05-01 18:06:03 +00:00
|
|
|
// box can also be canceled by pressing the Esc key
|
2007-10-21 10:01:15 +00:00
|
|
|
// (and also provide a horizontal static line to separate
|
|
|
|
// that button from all of the other buttons).
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxStaticLine* sline = new wxStaticLine( this, -1, wxDefaultPosition,
|
2009-05-01 18:06:03 +00:00
|
|
|
wxDefaultSize, wxLI_HORIZONTAL );
|
2016-04-23 15:44:17 +00:00
|
|
|
OuterBoxSizer->Add( sline, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxStdDialogButtonSizer* stdDialogButtonSizer = new wxStdDialogButtonSizer;
|
|
|
|
OuterBoxSizer->Add( stdDialogButtonSizer, 0, wxGROW | wxALL, 10 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
wxButton* cancelButton = new wxButton( this, wxID_CANCEL, _( "Cancel" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
stdDialogButtonSizer->AddButton( cancelButton );
|
2007-11-11 09:09:53 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
stdDialogButtonSizer->Realize();
|
2007-10-21 10:01:15 +00:00
|
|
|
|
|
|
|
// 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.)
|
2016-04-23 15:44:17 +00:00
|
|
|
if( focusedButton )
|
|
|
|
focusedButton->SetFocus();
|
|
|
|
else
|
|
|
|
cancelButton->SetFocus();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
void CHOOSE_COLOR_DLG::selColor( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
int id = event.GetId();
|
2016-04-23 15:44:17 +00:00
|
|
|
m_color = EDA_COLOR_T( id - ID_COLOR_BLACK );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-04-23 15:44:17 +00:00
|
|
|
// Close the dialog by calling the default dialog handler for a wxID_OK event
|
|
|
|
event.SetId( wxID_OK );
|
|
|
|
event.Skip();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|