KiCad PCB EDA Suite
CHOOSE_COLOR_DLG Class Reference
Inheritance diagram for CHOOSE_COLOR_DLG:

Public Member Functions

 CHOOSE_COLOR_DLG (wxWindow *aParent, COLOR4D aOldColor)
 
 ~CHOOSE_COLOR_DLG ()
 
COLOR4D GetSelectedColor ()
 

Private Member Functions

void init_Dialog ()
 
void selColor (wxCommandEvent &event)
 

Private Attributes

COLOR4D m_color
 

Detailed Description

Definition at line 46 of file selcolor.cpp.

Constructor & Destructor Documentation

CHOOSE_COLOR_DLG::CHOOSE_COLOR_DLG ( wxWindow *  aParent,
COLOR4D  aOldColor 
)

Definition at line 84 of file selcolor.cpp.

References aOldColor, init_Dialog(), and m_color.

84  :
85  wxDialog( aParent, wxID_ANY, _( "Colors" ), wxDefaultPosition, wxDefaultSize,
86  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
87 {
89 
90  init_Dialog();
91  // Resize the dialog
92  GetSizer()->SetSizeHints( this );
93 
94  Centre();
95 }
COLOR4D aOldColor
Definition: selcolor.cpp:72
void init_Dialog()
Definition: selcolor.cpp:97
COLOR4D m_color
Definition: selcolor.cpp:58
CHOOSE_COLOR_DLG::~CHOOSE_COLOR_DLG ( )
inline

Definition at line 50 of file selcolor.cpp.

50 {};

Member Function Documentation

COLOR4D CHOOSE_COLOR_DLG::GetSelectedColor ( )
inline

Definition at line 52 of file selcolor.cpp.

References m_color.

Referenced by if().

52 { return m_color; }
COLOR4D m_color
Definition: selcolor.cpp:58
void CHOOSE_COLOR_DLG::init_Dialog ( )
private

Definition at line 97 of file selcolor.cpp.

References ColorFindNearest(), ColorGetName(), g_ColorRefs, m_color, and NBCOLORS.

Referenced by CHOOSE_COLOR_DLG().

98 {
99  wxFlexGridSizer* FlexColumnBoxSizer = NULL;
100  wxBitmapButton* focusedButton = NULL;
101  const int w = 20, h = 20;
102 
103  wxBoxSizer* OuterBoxSizer = new wxBoxSizer( wxVERTICAL );
104  SetSizer( OuterBoxSizer );
105 
106  wxBoxSizer*MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
107  OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
108 
109  for( int ii = 0; ii < NBCOLORS; ++ii )
110  {
111  // Provide a separate column for every six buttons (and their
112  // associated text strings), so provide a FlexGrid Sizer with
113  // six rows and two columns.
114  if( ii % 6 == 0 )
115  {
116  FlexColumnBoxSizer = new wxFlexGridSizer( 6, 2, 0, 0 );
117 
118  // Specify that all of the rows can be expanded.
119  for( int kk = 0; kk < 6; kk++ )
120  {
121  FlexColumnBoxSizer->AddGrowableRow( kk );
122  }
123 
124  // Specify that the second column can also be expanded.
125  FlexColumnBoxSizer->AddGrowableCol( 1 );
126 
127  MainBoxSizer->Add( FlexColumnBoxSizer, 1, wxGROW | wxTOP, 5 );
128  }
129 
130  int butt_ID = ID_COLOR_BLACK + ii;
131  wxMemoryDC iconDC;
132  wxBitmap ButtBitmap( w, h );
133  wxBrush brush;
134 
135  iconDC.SelectObject( ButtBitmap );
136 
137  COLOR4D buttcolor = COLOR4D( g_ColorRefs[ii].m_Numcolor );
138 
139  iconDC.SetPen( *wxBLACK_PEN );
140  brush.SetColour( buttcolor.ToColour() );
141  brush.SetStyle( wxBRUSHSTYLE_SOLID );
142 
143  iconDC.SetBrush( brush );
144  iconDC.SetBackground( *wxGREY_BRUSH );
145  iconDC.Clear();
146  iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
147 
148  wxBitmapButton* bitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap,
149  wxDefaultPosition, wxSize( w+8, h+6 ) );
150  FlexColumnBoxSizer->Add( bitmapButton, 0,
151  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
152  wxLEFT | wxBOTTOM, 5 );
153 
154  // Set focus to this button if its color matches the
155  // color which had been selected previously (for
156  // whichever layer's color is currently being edited).
157  if( m_color == buttcolor )
158  focusedButton = bitmapButton;
159 
160  EDA_COLOR_T edaColor = ColorFindNearest( buttcolor.ToColour() );
161  wxStaticText* label = new wxStaticText( this, -1, wxGetTranslation( ColorGetName( edaColor ) ),
162  wxDefaultPosition, wxDefaultSize, 0 );
163  FlexColumnBoxSizer->Add( label, 1,
164  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
165  wxLEFT | wxRIGHT | wxBOTTOM, 5 );
166  }
167 
168  // Provide a Cancel button as well, so that this dialog
169  // box can also be canceled by pressing the Esc key
170  // (and also provide a horizontal static line to separate
171  // that button from all of the other buttons).
172 
173  wxStaticLine* sline = new wxStaticLine( this, -1, wxDefaultPosition,
174  wxDefaultSize, wxLI_HORIZONTAL );
175  OuterBoxSizer->Add( sline, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
176 
177  wxStdDialogButtonSizer* stdDialogButtonSizer = new wxStdDialogButtonSizer;
178  OuterBoxSizer->Add( stdDialogButtonSizer, 0, wxGROW | wxALL, 10 );
179 
180  wxButton* cancelButton = new wxButton( this, wxID_CANCEL, _( "Cancel" ),
181  wxDefaultPosition, wxDefaultSize, 0 );
182  stdDialogButtonSizer->AddButton( cancelButton );
183 
184  stdDialogButtonSizer->Realize();
185 
186  // Set focus to the Cancel button if the currently selected color
187  // does not match any of the colors provided by this dialog box.
188  // (That shouldn't ever happen in practice though.)
189  if( focusedButton )
190  focusedButton->SetFocus();
191  else
192  cancelButton->SetFocus();
193 }
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
EDA_COLOR_T ColorFindNearest(const wxColour &aColor)
Find the nearest color match.
Definition: colors.cpp:96
const wxChar * ColorGetName(EDA_COLOR_T aColor)
Definition: colors.h:185
const StructColors g_ColorRefs[NBCOLORS]
The predefined colors used in KiCad.
Definition: colors.cpp:37
COLOR4D m_color
Definition: selcolor.cpp:58
Number of colors.
Definition: colors.h:75
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void CHOOSE_COLOR_DLG::selColor ( wxCommandEvent &  event)
private

Definition at line 196 of file selcolor.cpp.

References m_color.

197 {
198  int id = event.GetId();
200 
201  // Close the dialog by calling the default dialog handler for a wxID_OK event
202  event.SetId( wxID_OK );
203  event.Skip();
204 }
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
COLOR4D m_color
Definition: selcolor.cpp:58

Member Data Documentation

COLOR4D CHOOSE_COLOR_DLG::m_color
private

Definition at line 58 of file selcolor.cpp.

Referenced by CHOOSE_COLOR_DLG(), GetSelectedColor(), init_Dialog(), and selColor().


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