2007-10-21 10:01:15 +00:00
|
|
|
/****************/
|
2007-11-11 09:09:53 +00:00
|
|
|
/* SELCOLOR.CPP */
|
2007-10-21 10:01:15 +00:00
|
|
|
/****************/
|
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 {
|
2007-11-11 09:09:53 +00:00
|
|
|
ID_COLOR_BLACK = 2000 // ID_COLOR_ = ID_COLOR_BLACK a ID_COLOR_BLACK + 31
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
class WinEDA_SelColorFrame : public wxDialog
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
2009-05-01 18:06:03 +00:00
|
|
|
WinEDA_SelColorFrame( wxWindow* parent,
|
2007-10-21 10:01:15 +00:00
|
|
|
const wxPoint& framepos, int OldColor );
|
|
|
|
~WinEDA_SelColorFrame() {};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2010-01-23 10:50:05 +00:00
|
|
|
void Init_Dialog( int aOldColor );
|
2009-05-01 18:06:03 +00:00
|
|
|
void OnCancel( wxCommandEvent& event );
|
|
|
|
void SelColor( wxCommandEvent& event );
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_SelColorFrame, wxDialog )
|
2007-10-21 10:01:15 +00:00
|
|
|
EVT_BUTTON( wxID_CANCEL, WinEDA_SelColorFrame::OnCancel )
|
|
|
|
EVT_COMMAND_RANGE( ID_COLOR_BLACK, ID_COLOR_BLACK + 31,
|
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED,
|
|
|
|
WinEDA_SelColorFrame::SelColor )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-09-13 09:24:43 +00:00
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T DisplayColorFrame( wxWindow* parent, int OldColor )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
wxPoint framepos;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
wxGetMousePosition( &framepos.x, &framepos.y );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
WinEDA_SelColorFrame* frame = new WinEDA_SelColorFrame( parent,
|
|
|
|
framepos, OldColor );
|
2012-09-02 12:06:47 +00:00
|
|
|
color = static_cast<EDA_COLOR_T>( frame->ShowModal() );
|
2007-10-21 10:01:15 +00:00
|
|
|
frame->Destroy();
|
2013-04-04 21:35:01 +00:00
|
|
|
if( color > NBCOLORS )
|
2012-09-02 12:06:47 +00:00
|
|
|
color = UNSPECIFIED_COLOR;
|
2007-10-21 10:01:15 +00:00
|
|
|
return color;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-13 09:24:43 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
WinEDA_SelColorFrame::WinEDA_SelColorFrame( wxWindow* parent,
|
|
|
|
const wxPoint& framepos,
|
|
|
|
int OldColor ) :
|
|
|
|
wxDialog( parent, -1, _( "Colors" ), framepos, wxDefaultSize,
|
2013-11-15 09:28:31 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2010-01-23 10:50:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
Init_Dialog( OldColor );
|
|
|
|
// Resize the dialog
|
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
// Ensure the whole frame is visible, whenever the asked position.
|
2010-11-04 18:51:18 +00:00
|
|
|
// 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.
|
2010-01-23 10:50:05 +00:00
|
|
|
// Give also a small margin.
|
|
|
|
int margin = 10;
|
2010-11-04 18:51:18 +00:00
|
|
|
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
|
2012-09-22 11:19:37 +00:00
|
|
|
int v_margin = std::max(20, margin);
|
2010-11-04 18:51:18 +00:00
|
|
|
if( windowPosition.y < v_margin )
|
|
|
|
windowPosition.y = v_margin;
|
|
|
|
if( windowPosition != framepos )
|
|
|
|
SetPosition(windowPosition);
|
|
|
|
}
|
|
|
|
wxPoint endCornerPosition = GetPosition();
|
2010-01-23 10:50:05 +00:00
|
|
|
endCornerPosition.x += GetSize().x + margin;
|
|
|
|
endCornerPosition.y += GetSize().y + margin;
|
|
|
|
|
2010-11-04 18:51:18 +00:00
|
|
|
windowPosition = GetPosition();
|
2010-01-23 10:50:05 +00:00
|
|
|
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 )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
wxBoxSizer* OuterBoxSizer = NULL;
|
|
|
|
wxBoxSizer* MainBoxSizer = NULL;
|
|
|
|
wxFlexGridSizer* FlexColumnBoxSizer = NULL;
|
|
|
|
wxBitmapButton* BitmapButton = NULL;
|
|
|
|
wxStaticText* Label = NULL;
|
|
|
|
wxStaticLine* Line = NULL;
|
2007-11-11 09:09:53 +00:00
|
|
|
wxStdDialogButtonSizer* StdDialogButtonSizer = NULL;
|
2009-05-01 18:06:03 +00:00
|
|
|
wxButton* Button = NULL;
|
2007-11-11 09:09:53 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
int ii, butt_ID;
|
2009-05-01 18:06:03 +00:00
|
|
|
int w = 20, h = 20;
|
|
|
|
bool ColorFound = false;
|
2007-10-21 10:01:15 +00:00
|
|
|
|
|
|
|
SetReturnCode( -1 );
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
OuterBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
SetSizer( OuterBoxSizer );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
for( 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
|
|
|
|
// eight 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.
|
2013-04-05 17:23:56 +00:00
|
|
|
for( int ii = 0; ii < 6; ii++ )
|
2007-11-11 09:09:53 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
FlexColumnBoxSizer->AddGrowableRow( ii );
|
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
|
|
|
|
|
|
|
butt_ID = ID_COLOR_BLACK + ii;
|
|
|
|
wxMemoryDC iconDC;
|
2009-05-01 18:06:03 +00:00
|
|
|
wxBitmap ButtBitmap( w, h );
|
|
|
|
wxBrush Brush;
|
2007-10-21 10:01:15 +00:00
|
|
|
iconDC.SelectObject( ButtBitmap );
|
2013-04-04 21:35:01 +00:00
|
|
|
EDA_COLOR_T buttcolor = g_ColorRefs[ii].m_Numcolor;
|
2007-10-21 10:01:15 +00:00
|
|
|
iconDC.SetPen( *wxBLACK_PEN );
|
2013-04-04 21:35:01 +00:00
|
|
|
ColorSetBrush( &Brush, buttcolor );
|
2007-10-21 10:01:15 +00:00
|
|
|
Brush.SetStyle( wxSOLID );
|
|
|
|
|
|
|
|
iconDC.SetBrush( Brush );
|
|
|
|
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
|
|
|
|
|
|
|
BitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap,
|
2010-07-27 12:47:08 +00:00
|
|
|
wxDefaultPosition, wxSize( w+8, h+6 ) );
|
2009-05-01 18:06:03 +00:00
|
|
|
FlexColumnBoxSizer->Add( BitmapButton, 0,
|
|
|
|
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).
|
2010-01-23 10:50:05 +00:00
|
|
|
if( aOldColor == buttcolor )
|
2007-10-21 10:01:15 +00:00
|
|
|
{
|
|
|
|
ColorFound = true;
|
|
|
|
BitmapButton->SetFocus();
|
|
|
|
}
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
Label = new wxStaticText( this, -1, ColorGetName( buttcolor ),
|
2007-11-11 09:09:53 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
2009-05-01 18:06:03 +00:00
|
|
|
FlexColumnBoxSizer->Add( Label, 1,
|
|
|
|
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).
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
Line = new wxStaticLine( this, -1, wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxLI_HORIZONTAL );
|
|
|
|
OuterBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2007-11-11 09:09:53 +00:00
|
|
|
StdDialogButtonSizer = new wxStdDialogButtonSizer;
|
2009-05-01 18:06:03 +00:00
|
|
|
OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 );
|
2007-10-21 10:01:15 +00:00
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, 0 );
|
|
|
|
StdDialogButtonSizer->AddButton( Button );
|
2007-11-11 09:09:53 +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.)
|
|
|
|
if( !ColorFound )
|
|
|
|
Button->SetFocus();
|
2007-09-13 09:24:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
void WinEDA_SelColorFrame::OnCancel( wxCommandEvent& WXUNUSED( event ) )
|
2007-09-13 09:24:43 +00:00
|
|
|
{
|
2007-10-21 10:01:15 +00:00
|
|
|
// Setting the return value to -1 indicates that the
|
2009-05-01 18:06:03 +00:00
|
|
|
// dialog box has been canceled (and thus that the
|
2007-10-21 10:01:15 +00:00
|
|
|
// previously selected color is to be retained).
|
2007-11-11 09:09:53 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-01 18:06:03 +00:00
|
|
|
void WinEDA_SelColorFrame::SelColor( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-01 18:06:03 +00:00
|
|
|
int id = event.GetId();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-21 10:01:15 +00:00
|
|
|
EndModal( id - ID_COLOR_BLACK );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|