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 47 of file selcolor.cpp.

Constructor & Destructor Documentation

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

Definition at line 85 of file selcolor.cpp.

References aOldColor, init_Dialog(), and m_color.

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

Definition at line 51 of file selcolor.cpp.

51 {};

Member Function Documentation

COLOR4D CHOOSE_COLOR_DLG::GetSelectedColor ( )
inline

Definition at line 53 of file selcolor.cpp.

References init_Dialog(), m_color, and selColor().

Referenced by if().

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

Definition at line 98 of file selcolor.cpp.

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

Referenced by CHOOSE_COLOR_DLG(), and GetSelectedColor().

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

References m_color.

Referenced by GetSelectedColor().

198 {
199  int id = event.GetId();
201 
202  // Close the dialog by calling the default dialog handler for a wxID_OK event
203  event.SetId( wxID_OK );
204  event.Skip();
205 }
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:59

Member Data Documentation

COLOR4D CHOOSE_COLOR_DLG::m_color
private

Definition at line 59 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: