KiCad PCB EDA Suite
color4Dpickerdlg.cpp
Go to the documentation of this file.
1 
5 #include "math.h"
6 #include "color4Dpickerdlg.h"
7 
8 #define ALPHA_MAX 100 // the max value returned by the alpha (opacity) slider
9 
10 COLOR4D_PICKER_DLG::COLOR4D_PICKER_DLG( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
11  bool aAllowOpacityControl )
12  : COLOR4D_PICKER_DLG_BASE( aParent )
13 {
14  m_allowMouseEvents = false;
15  m_allowOpacityCtrl = aAllowOpacityControl;
16  m_previousColor4D = aCurrentColor;
17  m_newColor4D = aCurrentColor;
18  m_cursorsSize = 8; // Size of square cursors drawn on color bitmaps
19  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
20  m_bitmapRGB = nullptr;
21  m_bitmapHSV = nullptr;
22  m_selectedCursor = nullptr;
23 
24  if( !m_allowOpacityCtrl )
25  {
26  m_SizerTransparency->Show( false );
27  m_previousColor4D.a = 1.0;
28  m_newColor4D.a = 1.0;
29  }
30 
31  m_notebook->SetSelection( m_ActivePage );
32 
33  // Build the defined colors panel:
35 
36  m_sdbSizerOK->SetDefault();
37 
39 }
40 
41 int COLOR4D_PICKER_DLG::m_ActivePage = 0; // the active notebook page, stored during a session
42 
43 
45 {
46  delete m_bitmapRGB;
47  delete m_bitmapHSV;
48 
49  m_ActivePage = m_notebook->GetSelection();
50 
51  for( auto button : m_buttonsColor )
52  button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( COLOR4D_PICKER_DLG::buttColorClick ), NULL, this );
53 }
54 
55 
56 void COLOR4D_PICKER_DLG::setIconColor( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D )
57 {
58  // Draw the icon that shows the aColor4D,
59  // with colors according to the color 4D rgb and alpha
60  // for alpha = 1 (no tranparency, the icon is a full rgb color rect
61  // for alpha = 0 (100% tranparency, the icon is a grid of rgb color
62  // and background color small sub rect
63  wxMemoryDC bitmapDC;
64  wxSize size = aStaticBitmap->GetSize();
65  wxBitmap newBm( size );
66  bitmapDC.SelectObject( newBm );
67  wxPen pen( aColor4D.ToColour() );
68  wxBrush brush( aColor4D.ToColour() );
69 
70  // clear background (set bg color to aColor4D )
71  bitmapDC.SetBackground( brush );
72  bitmapDC.Clear();
73 
74 
75  // Draw the alpha subrect
76  int stepx = size.x/8;
77  int stepy = size.y/8;
78 
79  // build the alpha color for icon:
80  // the alpha color is the initial color modified to be
81  // the initial color for transparency = 0 ( alpha = 1 )
82  // and white color for transparency = 1( alpha = 0 )
83  KIGFX::COLOR4D bgcolor( GetBackgroundColour() );
84  KIGFX::COLOR4D alphacolor = aColor4D;
85  alphacolor.r = ( alphacolor.r * aColor4D.a ) + ( bgcolor.r * (1-aColor4D.a) );
86  alphacolor.g = ( alphacolor.g * aColor4D.a ) + ( bgcolor.g * (1-aColor4D.a) );
87  alphacolor.b = ( alphacolor.b * aColor4D.a ) + ( bgcolor.b * (1-aColor4D.a) );
88 
89  pen.SetColour( alphacolor.ToColour() );
90  brush.SetColour( alphacolor.ToColour() );
91  bitmapDC.SetPen( pen );
92  bitmapDC.SetBrush( brush );
93 
94  for( int ii = 0; ii < size.x/stepx; ii+=2 )
95  {
96  for( int jj = 0; jj < size.y/stepy; jj+= 2 )
97  {
98  wxPoint pos( stepx*ii + stepx/2, stepy*jj + stepy/2 );
99  bitmapDC.DrawRectangle( pos, wxSize( stepx, stepy ) );
100  }
101  }
102 
103  aStaticBitmap->SetBitmap( newBm );
104 
105  // Deselect the Tool Bitmap from DC, in order to delete the MemoryDC
106  // safely without deleting the bitmap
107  bitmapDC.SelectObject( wxNullBitmap );
108 }
109 
110 
112 {
113  // Draw all bitmaps, with colors according to the color 4D
116  drawAll();
117 
118  // Now the bitmaps are built, fix the minsizes:
119  GetSizer()->SetSizeHints( this );
120 
121  return true;
122 }
123 
124 
126 {
127  #define ID_COLOR_BLACK 2000 // colors_id = ID_COLOR_BLACK a ID_COLOR_BLACK + NBCOLORS-1
128 
129  // Size of color swatches
130  const int w = 32, h = 32;
131 
132  // Colors are built from the g_ColorRefs table (size NBCOLORS).
133  // The look is better when g_ColorRefs order is displayed in a grid matrix
134  // of 6 row and 5 columns, first filling a row, and after the next column.
135  // But the wxFlexGrid used here must be filled by columns, then next row
136  // the best interval g_ColorRefs from a matrix row to the next row is 6
137  // So when have to reorder the index used to explore g_ColorRefs
138  int grid_col = 0;
139  int grid_row = 0;
140  int table_row_count = 6;
141 
142  for( int jj = 0; jj < NBCOLORS; ++jj, grid_col++ )
143  {
144  if( grid_col*table_row_count >= NBCOLORS )
145  { // the current grid row is filled, and we must fill the next grid row
146  grid_col = 0;
147  grid_row++;
148  }
149 
150  int ii = grid_row + (grid_col*table_row_count); // The index in g_ColorRefs
151 
152  int butt_ID = ID_COLOR_BLACK + ii;
153  wxMemoryDC iconDC;
154  wxBitmap ButtBitmap( w, h );
155  wxBrush brush;
156 
157  iconDC.SelectObject( ButtBitmap );
158 
159  KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( g_ColorRefs[ii].m_Numcolor );
160 
161  iconDC.SetPen( *wxBLACK_PEN );
162  brush.SetColour( buttcolor.ToColour() );
163  brush.SetStyle( wxBRUSHSTYLE_SOLID );
164 
165  iconDC.SetBrush( brush );
166  iconDC.SetBackground( *wxGREY_BRUSH );
167  iconDC.Clear();
168  iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
169 
170  wxBitmapButton* bitmapButton = new wxBitmapButton( m_panelDefinedColors, butt_ID, ButtBitmap,
171  wxDefaultPosition, wxSize( w+8, h+6 ) );
172  m_fgridColor->Add( bitmapButton, 0,
173  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
174  wxLEFT | wxBOTTOM, 5 );
175 
176  wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
177  wxGetTranslation( g_ColorRefs[ii].m_ColorName ),
178  wxDefaultPosition, wxDefaultSize, 0 );
179  m_fgridColor->Add( label, 1,
180  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
181  wxLEFT | wxRIGHT | wxBOTTOM, 5 );
182  m_buttonsColor.push_back( bitmapButton );
183  bitmapButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( COLOR4D_PICKER_DLG::buttColorClick ), NULL, this );
184  }
185 }
186 
187 
189 {
190  wxMemoryDC bitmapDC;
191  wxSize bmsize = m_RgbBitmap->GetSize();
192  int half_size = std::min( bmsize.x, bmsize.y )/2;
193  m_bitmapRGB = new wxBitmap( bmsize );
194  bitmapDC.SelectObject( *m_bitmapRGB );
195  wxPen pen;
196 
197  // clear background (set the window bg color)
198  wxBrush bgbrush( GetBackgroundColour() );
199  bitmapDC.SetBackground( bgbrush );
200  bitmapDC.Clear();
201 
202  // Use Y axis from bottom to top and origin to center
203  bitmapDC.SetAxisOrientation( true, true );
204  bitmapDC.SetDeviceOrigin( half_size, half_size );
205 
206  // Reserve room to draw cursors inside the bitmap
207  half_size -= m_cursorsSize/2;
208 
210 
211  // Red blue area in X Z 3d axis
212  double inc = 1.0 / half_size;
213  #define SLOPE_AXIS 50.0
214  double slope = SLOPE_AXIS/half_size;
215  color.g = 0.0;
216 
217  for( int xx = 0; xx < half_size; xx++ ) // blue axis
218  {
219  color.b = inc * xx;
220 
221  for( int yy = 0; yy < half_size; yy++ ) // Red axis
222  {
223  color.r = inc * yy;
224 
225  pen.SetColour( color.ToColour() );
226  bitmapDC.SetPen( pen );
227  bitmapDC.DrawPoint( xx, yy - (slope*xx) );
228  }
229  }
230 
231  // Red green area in y Z 3d axis
232  color.b = 0.0;
233  for( int xx = 0; xx < half_size; xx++ ) // green axis
234  {
235  color.g = inc * xx;
236 
237  for( int yy = 0; yy < half_size; yy++ ) // Red axis
238  {
239  color.r = inc * yy;
240 
241  pen.SetColour( color.ToColour() );
242  bitmapDC.SetPen( pen );
243  bitmapDC.DrawPoint( -xx, yy - (slope*xx) );
244  }
245  }
246 
247  // Blue green area in x y 3d axis
248  color.r = 0.0;
249  for( int xx = 0; xx < half_size; xx++ ) // green axis
250  {
251  color.g = inc * xx;
252 
253  for( int yy = 0; yy < half_size; yy++ ) // blue axis
254  {
255  color.b = inc * yy;
256 
257  pen.SetColour( color.ToColour() );
258  bitmapDC.SetPen( pen );
259 
260  // Mapping the xx, yy color axis to draw coordinates is more tricky than previously
261  // in DC coordinates:
262  // the blue axis is the (0, 0) to half_size, (-yy - SLOPE_AXIS)
263  // the green axis is the (0, 0) to - half_size, (-yy - SLOPE_AXIS)
264  int drawX = -xx + yy;
265  int drawY = - std::min( xx,yy ) * 0.9;
266  bitmapDC.DrawPoint( drawX, drawY - std::abs( slope*drawX ) );
267  }
268  }
269 }
270 
271 
273 {
274  wxMemoryDC bitmapDC;
275  wxSize bmsize = m_HsvBitmap->GetSize();
276  int half_size = std::min( bmsize.x, bmsize.y )/2;
277  delete m_bitmapHSV;
278  m_bitmapHSV = new wxBitmap( bmsize );
279  bitmapDC.SelectObject( *m_bitmapHSV );
280  wxPen pen;
281 
282  // clear background (set the window bd color)
283  wxBrush bgbrush( GetBackgroundColour() );
284  bitmapDC.SetBackground( bgbrush );
285  bitmapDC.Clear();
286 
287  // Use Y axis from bottom to top and origin to center
288  bitmapDC.SetAxisOrientation( true, true );
289  bitmapDC.SetDeviceOrigin( half_size, half_size );
290 
291  // Reserve room to draw cursors inside the bitmap
292  half_size -= m_cursorsSize/2;
293 
294  double hue, sat;
296  int sq_radius = half_size*half_size;
297 
298  for( int xx = -half_size; xx < half_size; xx++ )
299  {
300  for( int yy = -half_size; yy < half_size; yy++ )
301  {
302  sat = double(xx*xx + yy*yy) / sq_radius;
303 
304  // sat is <= 1.0
305  // any value > 1.0 is not a valid HSB color:
306  if( sat > 1.0 )
307  continue;
308 
309  // sat is the distance from center
310  sat = sqrt( sat );
311  hue = atan2( (double)yy, (double)xx ) * 180 / M_PI;
312 
313  if( hue < 0.0 )
314  hue += 360.0;
315 
316  color.FromHSV( hue, sat, 1.0 );
317 
318  pen.SetColour( color.ToColour() );
319  bitmapDC.SetPen( pen );
320  bitmapDC.DrawPoint( xx, yy );
321  }
322  }
323 
324  /* Deselect the Tool Bitmap from DC,
325  * in order to delete the MemoryDC safely without deleting the bitmap
326  */
327  bitmapDC.SelectObject( wxNullBitmap );
328 }
329 
330 
332 {
333  if( !m_bitmapRGB || m_bitmapRGB->GetSize() != m_RgbBitmap->GetSize() )
334  createRGBBitmap();
335 
336  wxMemoryDC bitmapDC;
337  wxSize bmsize = m_bitmapRGB->GetSize();
338  int half_size = std::min( bmsize.x, bmsize.y )/2;
339  wxBitmap newBm( *m_bitmapRGB );
340  bitmapDC.SelectObject( newBm );
341 
342  // Use Y axis from bottom to top and origin to center
343  bitmapDC.SetAxisOrientation( true, true );
344  bitmapDC.SetDeviceOrigin( half_size, half_size );
345 
346  // Reserve room to draw cursors inside the bitmap
347  half_size -= m_cursorsSize/2;
348 
349  // Draw the 3 RGB cursors, usiing white color to make them always visible:
350  wxPen pen( wxColor( 255, 255, 255 ) );
351  wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
352  bitmapDC.SetPen( pen );
353  bitmapDC.SetBrush( brush );
354  int half_csize = m_cursorsSize/2;
355 
356  #define SLOPE_AXIS 50.0
357  double slope = SLOPE_AXIS/half_size;
358 
359  // Red axis cursor (Z 3Daxis):
360  m_cursorBitmapRed.x = 0;
361  m_cursorBitmapRed.y = m_newColor4D.r * half_size;
362  bitmapDC.DrawRectangle( m_cursorBitmapRed.x - half_csize,
363  m_cursorBitmapRed.y - half_csize,
365 
366  // Blue axis cursor (X 3Daxis):
367  m_cursorBitmapBlue.x = m_newColor4D.b * half_size;
369  bitmapDC.DrawRectangle( m_cursorBitmapBlue.x - half_csize,
370  m_cursorBitmapBlue.y - half_csize,
372 
373  // Green axis cursor (Y 3Daxis):
374  m_cursorBitmapGreen.x = m_newColor4D.g * half_size;
377 
378  bitmapDC.DrawRectangle( m_cursorBitmapGreen.x - half_csize,
379  m_cursorBitmapGreen.y - half_csize,
381 
382  // Draw the 3 RGB axis:
383  half_size += half_size/5;
384  bitmapDC.DrawLine( 0, 0, 0, half_size ); // Red axis (Z 3D axis)
385  bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope ); // Blue axis (X 3D axis)
386  bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope ); // green axis (Y 3D axis)
387 
388  m_RgbBitmap->SetBitmap( newBm );
389  /* Deselect the Tool Bitmap from DC,
390  * in order to delete the MemoryDC safely without deleting the bitmap */
391  bitmapDC.SelectObject( wxNullBitmap );
392 }
393 
394 
396 {
397  if( !m_bitmapHSV || m_bitmapHSV->GetSize() != m_HsvBitmap->GetSize() )
398  createHSVBitmap();
399 
400  wxMemoryDC bitmapDC;
401  wxSize bmsize = m_bitmapHSV->GetSize();
402  int half_size = std::min( bmsize.x, bmsize.y )/2;
403  wxBitmap newBm( *m_bitmapHSV );
404  bitmapDC.SelectObject( newBm );
405 
406  // Use Y axis from bottom to top and origin to center
407  bitmapDC.SetAxisOrientation( true, true );
408  bitmapDC.SetDeviceOrigin( half_size, half_size );
409 
410  // Reserve room to draw cursors inside the bitmap
411  half_size -= m_cursorsSize/2;
412 
413  // Draw the HSB cursor:
414  m_cursorBitmapHSV.x = cos( m_hue * M_PI / 180.0 ) * half_size * m_sat;
415  m_cursorBitmapHSV.y = sin( m_hue * M_PI / 180.0 ) * half_size * m_sat;
416 
417  wxPen pen( wxColor( 0, 0, 0 ) );
418  wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
419  bitmapDC.SetPen( pen );
420  bitmapDC.SetBrush( brush );
421 
422  int half_csize = m_cursorsSize/2;
423  bitmapDC.DrawRectangle( m_cursorBitmapHSV.x- half_csize,
424  m_cursorBitmapHSV.y-half_csize,
426 
427  m_HsvBitmap->SetBitmap( newBm );
428  /* Deselect the Tool Bitmap from DC,
429  * in order to delete the MemoryDC safely without deleting the bitmap
430  */
431  bitmapDC.SelectObject( wxNullBitmap );
432 }
433 
434 
436 {
438 
439  if( aChanged == RED_CHANGED || aChanged == GREEN_CHANGED || aChanged == BLUE_CHANGED )
440  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
441 
442  if( aChanged != RED_CHANGED )
443  m_spinCtrlRed->SetValue( normalizeToInt( m_newColor4D.r ) );
444 
445  if( aChanged != GREEN_CHANGED )
447 
448  if( aChanged != BLUE_CHANGED )
450 
451  if( aChanged != HUE_CHANGED )
452  m_spinCtrlHue->SetValue( (int)m_hue );
453 
454  if( aChanged != SAT_CHANGED )
455  m_spinCtrlSaturation->SetValue( m_sat * 255 );
456 
457  if( aChanged != VAL_CHANGED )
458  {
459  m_sliderBrightness->SetValue(normalizeToInt( m_val ) );
460  }
461 }
462 
463 
465 {
466  m_NewColorRect->Freeze(); // Avoid flicker
467  m_HsvBitmap->Freeze();
468  m_RgbBitmap->Freeze();
470  drawHSVPalette();
471  drawRGBPalette();
472  m_NewColorRect->Thaw();
473  m_HsvBitmap->Thaw();
474  m_RgbBitmap->Thaw();
475  m_NewColorRect->Refresh();
476  m_HsvBitmap->Refresh();
477  m_RgbBitmap->Refresh();
478 }
479 
480 
481 void COLOR4D_PICKER_DLG::buttColorClick( wxCommandEvent& event )
482 {
483  int id = event.GetId();
485  m_newColor4D.r = color.r;
486  m_newColor4D.g = color.g;
487  m_newColor4D.b = color.b;
488 
489  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
491 
492  drawAll();
493 
494  event.Skip();
495 }
496 
497 
498 void COLOR4D_PICKER_DLG::onRGBMouseClick( wxMouseEvent& event )
499 {
500  m_allowMouseEvents = true;
501  wxPoint mousePos = event.GetPosition();
502 
503  // The cursor position is relative to the m_bitmapHSV wxBitmap center
504  wxSize bmsize = m_bitmapRGB->GetSize();
505  int half_size = std::min( bmsize.x, bmsize.y )/2;
506  mousePos.x -= half_size;
507  mousePos.y -= half_size;
508  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
509 
510  wxPoint dist = m_cursorBitmapRed - mousePos;
511 
512  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
513  {
515  return;
516  }
517 
518  dist = m_cursorBitmapGreen - mousePos;
519 
520  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
521  {
523  return;
524  }
525 
526  dist = m_cursorBitmapBlue - mousePos;
527 
528  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
529  {
531  return;
532  }
533 
534  m_selectedCursor = nullptr;
535 }
536 
537 
538 void COLOR4D_PICKER_DLG::onRGBMouseDrag( wxMouseEvent& event )
539 {
540  if( !event.Dragging() || !m_allowMouseEvents )
541  {
542  m_selectedCursor = nullptr;
543  return;
544  }
545 
549  return;
550 
551  // Adjust the HSV cursor position to follow the mouse cursor
552  // The cursor position is relative to the m_bitmapHSV wxBitmap center
553  wxPoint mousePos = event.GetPosition();
554  wxSize bmsize = m_bitmapRGB->GetSize();
555  int half_size = std::min( bmsize.x, bmsize.y )/2;
556  mousePos.x -= half_size;
557  mousePos.y -= half_size;
558  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
559 
560  half_size -= m_cursorsSize/2; // the actual half_size of the palette area
561 
562  // Change colors according to the selected cursor:
564  {
565  if( mousePos.y >= 0 && mousePos.y <= half_size )
566  m_newColor4D.r = (double)mousePos.y / half_size;
567  else
568  return;
569  }
570 
572  {
573  mousePos.x = -mousePos.x;
574 
575  if( mousePos.x >= 0 && mousePos.x <= half_size )
576  m_newColor4D.g = (double)mousePos.x / half_size;
577  else
578  return;
579  }
580 
582  {
583  if( mousePos.x >= 0 && mousePos.x <= half_size )
584  m_newColor4D.b = (double)mousePos.x / half_size;
585  else
586  return;
587  }
588 
589  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
591 
592  drawAll();
593 }
594 
595 
596 void COLOR4D_PICKER_DLG::onHSVMouseClick( wxMouseEvent& event )
597 {
598  m_allowMouseEvents = true;
599 
600  if( setHSvaluesFromCursor( event.GetPosition() ) )
601  drawAll();
602 }
603 
604 
605 void COLOR4D_PICKER_DLG::onHSVMouseDrag( wxMouseEvent& event )
606 {
607  if( !event.Dragging() || !m_allowMouseEvents )
608  return;
609 
610  if( setHSvaluesFromCursor( event.GetPosition() ) )
611  drawAll();
612 }
613 
614 
616 {
617  wxPoint mousePos = aMouseCursor;
618  wxSize bmsize = m_bitmapHSV->GetSize();
619  int half_size = std::min( bmsize.x, bmsize.y )/2;
620  // Make the cursor position relative to the m_bitmapHSV wxBitmap center
621  mousePos.x -= half_size;
622  mousePos.y -= half_size;
623  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
624 
625  // The HS cursor position is restricted to a circle of radius half_size
626  double dist_from_centre = hypot( (double)mousePos.x, (double)mousePos.y );
627 
628  if( dist_from_centre > half_size )
629  // Saturation cannot be calculated:
630  return false;
631 
632  m_cursorBitmapHSV = mousePos;
633 
634  // Set saturation and hue from new cursor position:
635  half_size -= m_cursorsSize/2; // the actual half_size of the palette area
636  m_sat = dist_from_centre / half_size;
637 
638  if( m_sat > 1.0 )
639  m_sat = 1.0;
640 
641  m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
642 
643  if( m_hue < 0 )
644  m_hue += 360.0;
645 
648 
649  return true;
650 }
651 
652 
653 void COLOR4D_PICKER_DLG::OnChangeAlpha( wxScrollEvent& event )
654 {
655  double alpha = (double)event.GetPosition() / ALPHA_MAX;
656  m_newColor4D.a = alpha;
657  m_NewColorRect->Freeze(); // Avoid flicker
659  m_NewColorRect->Thaw();
660  m_NewColorRect->Refresh();
661 }
662 
663 
664 void COLOR4D_PICKER_DLG::OnChangeEditRed( wxSpinEvent& event )
665 {
666  double val = (double)event.GetPosition() / 255.0;
667  m_newColor4D.r = val;
669 
670  drawAll();
671 }
672 
673 
674 void COLOR4D_PICKER_DLG::OnChangeEditGreen( wxSpinEvent& event )
675 {
676  double val = (double)event.GetPosition() / 255.0;
677  m_newColor4D.g = val;
679 
680  drawAll();
681 }
682 
683 
684 void COLOR4D_PICKER_DLG::OnChangeEditBlue( wxSpinEvent& event )
685 {
686  double val = (double)event.GetPosition() / 255.0;
687  m_newColor4D.b = val;
689 
690  drawAll();
691 }
692 
693 
694 void COLOR4D_PICKER_DLG::OnChangeEditHue( wxSpinEvent& event )
695 {
696  m_hue = (double)event.GetPosition();
697 
699 
701 
702  drawAll();
703 }
704 
705 
706 void COLOR4D_PICKER_DLG::OnChangeEditSat( wxSpinEvent& event )
707 {
708  m_sat = (double)event.GetPosition() / 255.0;
709 
711 
713 
714  drawAll();
715 }
716 
717 
718 void COLOR4D_PICKER_DLG::OnChangeBrightness( wxScrollEvent& event )
719 {
720  m_val = (double)event.GetPosition() / 255.0;
721 
723 
725 
726  drawAll();
727 }
void initDefinedColors()
creates the bitmap buttons for each defined colors
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
void OnChangeEditSat(wxSpinEvent &event) override
void createRGBBitmap()
generate the bitmap that shows the RVB color space
void SetEditVals(CHANGED_COLOR aChanged)
int normalizeToInt(double aValue, int aValMax=255)
int color
Definition: DXF_plotter.cpp:62
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
static const int dist[10][10]
Definition: dist.cpp:57
double m_hue
the current hue, in degrees (0 ... 360)
double g
Green component.
Definition: color4d.h:292
wxPoint m_cursorBitmapBlue
the blue cursor on the RGB bitmap palette.
double m_sat
the current saturation (0 ... 1.0)
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
#define abs(a)
Definition: auxiliary.h:84
wxPoint * m_selectedCursor
the ref cursor to the selected curor, if any, or null.
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Function ToHSV() Converts current color (stored in RGB) to HSV format.
Definition: color4d.cpp:272
double b
Blue component.
Definition: color4d.h:293
std::vector< wxBitmapButton * > m_buttonsColor
list of defined colors buttons
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
#define SLOPE_AXIS
void onRGBMouseClick(wxMouseEvent &event) override
mouse handlers, when clicking on a palette bitmap
void OnChangeEditGreen(wxSpinEvent &event) override
Class COLOR4D_PICKER_DLG_BASE.
wxPoint m_cursorBitmapRed
the red cursor on the RGB bitmap palette.
void createHSVBitmap()
generate the bitmap that shows the HSV color circle
#define ALPHA_MAX
double a
Alpha component.
Definition: color4d.h:294
wxBitmap * m_bitmapRGB
the basic RGB palette
void drawHSVPalette()
draws the HSV color circle
CHANGED_COLOR
void setIconColor(wxStaticBitmap *aStaticBitmap, KIGFX::COLOR4D &aColor4D)
repaint a static bitmap with the aColor4D color
KIGFX::COLOR4D m_previousColor4D
the inital color4d
void onHSVMouseClick(wxMouseEvent &event) override
void OnChangeEditBlue(wxSpinEvent &event) override
COLOR4D_PICKER_DLG(wxWindow *aParent, KIGFX::COLOR4D &aCurrentColor, bool aAllowOpacityControl)
Dialog constructor.
const StructColors g_ColorRefs[NBCOLORS]
The predefined colors used in KiCad.
Definition: colors.cpp:37
void drawRGBPalette()
draws the RVB color space
void OnChangeEditRed(wxSpinEvent &event) override
void OnChangeAlpha(wxScrollEvent &event) override
Event handlers from wxSpinControl.
bool m_allowOpacityCtrl
true to show the widget, false to keep alpha channel = 1.0
void FromHSV(double aInH, double aInS, double aInV)
Function FromHSV() Changes currently used color to the one given by hue, saturation and value paramet...
Definition: color4d.cpp:325
wxFlexGridSizer * m_fgridColor
KIGFX::COLOR4D m_newColor4D
the current color4d
void OnChangeEditHue(wxSpinEvent &event) override
static int m_ActivePage
the active notebook page, stored during a session
double m_val
the current value (0 ... 1.0)
void buttColorClick(wxCommandEvent &event)
Event handler for defined color buttons
double r
Red component.
Definition: color4d.h:291
wxBitmap * m_bitmapHSV
the basic HUV palette
Number of colors.
Definition: colors.h:75
bool TransferDataToWindow() override
called when creating the dialog
#define ID_COLOR_BLACK
#define min(a, b)
Definition: auxiliary.h:85
bool setHSvaluesFromCursor(wxPoint aMouseCursor)
manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
void onHSVMouseDrag(wxMouseEvent &event) override
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void onRGBMouseDrag(wxMouseEvent &event) override