KiCad PCB EDA Suite
color4Dpickerdlg.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software: you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the
12  * Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 
25 #include "math.h"
26 #include "color4Dpickerdlg.h"
27 
28 #define ALPHA_MAX 100 // the max value returned by the alpha (opacity) slider
29 
30 COLOR4D_PICKER_DLG::COLOR4D_PICKER_DLG( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
31  bool aAllowOpacityControl )
32  : COLOR4D_PICKER_DLG_BASE( aParent )
33 {
34  m_allowMouseEvents = false;
35  m_allowOpacityCtrl = aAllowOpacityControl;
36  m_previousColor4D = aCurrentColor;
37  m_newColor4D = aCurrentColor;
38  m_cursorsSize = 8; // Size of square cursors drawn on color bitmaps
39  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
40  m_bitmapRGB = nullptr;
41  m_bitmapHSV = nullptr;
42  m_selectedCursor = nullptr;
43 
44  if( !m_allowOpacityCtrl )
45  {
46  m_SizerTransparency->Show( false );
47  m_previousColor4D.a = 1.0;
48  m_newColor4D.a = 1.0;
49  }
50 
51  if( m_ActivePage >= 0 )
52  m_notebook->SetSelection( (unsigned) m_ActivePage );
53 
54  // Build the defined colors panel:
56 
57  m_sdbSizerOK->SetDefault();
58 }
59 
60 int COLOR4D_PICKER_DLG::m_ActivePage = 0; // the active notebook page, stored during a session
61 
62 
64 {
65  delete m_bitmapRGB;
66  delete m_bitmapHSV;
67 
68  m_ActivePage = m_notebook->GetSelection();
69 
70  for( auto button : m_buttonsColor )
71  button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( COLOR4D_PICKER_DLG::buttColorClick ), NULL, this );
72 }
73 
74 
75 void COLOR4D_PICKER_DLG::setIconColor( wxStaticBitmap* aStaticBitmap, KIGFX::COLOR4D& aColor4D )
76 {
77  // Draw the icon that shows the aColor4D,
78  // with colors according to the color 4D rgb and alpha
79  // for alpha = 1 (no tranparency, the icon is a full rgb color rect
80  // for alpha = 0 (100% tranparency, the icon is a grid of rgb color
81  // and background color small sub rect
82  wxMemoryDC bitmapDC;
83  wxSize size = aStaticBitmap->GetSize();
84  wxBitmap newBm( size );
85  bitmapDC.SelectObject( newBm );
86  wxPen pen( aColor4D.ToColour() );
87  wxBrush brush( aColor4D.ToColour() );
88 
89  // clear background (set bg color to aColor4D )
90  bitmapDC.SetBackground( brush );
91  bitmapDC.Clear();
92 
93 
94  // Draw the alpha subrect
95  int stepx = size.x/8;
96  int stepy = size.y/8;
97 
98  // build the alpha color for icon:
99  // the alpha color is the initial color modified to be
100  // the initial color for transparency = 0 ( alpha = 1 )
101  // and white color for transparency = 1( alpha = 0 )
102  KIGFX::COLOR4D bgcolor( GetBackgroundColour() );
103  KIGFX::COLOR4D alphacolor = aColor4D;
104  alphacolor.r = ( alphacolor.r * aColor4D.a ) + ( bgcolor.r * (1-aColor4D.a) );
105  alphacolor.g = ( alphacolor.g * aColor4D.a ) + ( bgcolor.g * (1-aColor4D.a) );
106  alphacolor.b = ( alphacolor.b * aColor4D.a ) + ( bgcolor.b * (1-aColor4D.a) );
107 
108  pen.SetColour( alphacolor.ToColour() );
109  brush.SetColour( alphacolor.ToColour() );
110  bitmapDC.SetPen( pen );
111  bitmapDC.SetBrush( brush );
112 
113  for( int ii = 0; ii < size.x/stepx; ii+=2 )
114  {
115  for( int jj = 0; jj < size.y/stepy; jj+= 2 )
116  {
117  wxPoint pos( stepx*ii + stepx/2, stepy*jj + stepy/2 );
118  bitmapDC.DrawRectangle( pos, wxSize( stepx, stepy ) );
119  }
120  }
121 
122  aStaticBitmap->SetBitmap( newBm );
123 
124  // Deselect the Tool Bitmap from DC, in order to delete the MemoryDC
125  // safely without deleting the bitmap
126  bitmapDC.SelectObject( wxNullBitmap );
127 }
128 
129 
131 {
132  // Draw all bitmaps, with colors according to the color 4D
135  drawAll();
136 
137  m_notebook->GetPage( 0 )->Layout();
138  m_notebook->GetPage( 1 )->Layout();
139 
141 
142  return true;
143 }
144 
145 
147 {
148  #define ID_COLOR_BLACK 2000 // colors_id = ID_COLOR_BLACK a ID_COLOR_BLACK + NBCOLORS-1
149 
150  // Size of color swatches
151  const int w = 32, h = 32;
152 
153  // Colors are built from the g_ColorRefs table (size NBCOLORS).
154  // The look is better when g_ColorRefs order is displayed in a grid matrix
155  // of 6 row and 5 columns, first filling a row, and after the next column.
156  // But the wxFlexGrid used here must be filled by columns, then next row
157  // the best interval g_ColorRefs from a matrix row to the next row is 6
158  // So when have to reorder the index used to explore g_ColorRefs
159  int grid_col = 0;
160  int grid_row = 0;
161  int table_row_count = 6;
162 
163  for( int jj = 0; jj < NBCOLORS; ++jj, grid_col++ )
164  {
165  if( grid_col*table_row_count >= NBCOLORS )
166  { // the current grid row is filled, and we must fill the next grid row
167  grid_col = 0;
168  grid_row++;
169  }
170 
171  int ii = grid_row + (grid_col*table_row_count); // The index in g_ColorRefs
172 
173  int butt_ID = ID_COLOR_BLACK + ii;
174  wxMemoryDC iconDC;
175  wxBitmap ButtBitmap( w, h );
176  wxBrush brush;
177 
178  iconDC.SelectObject( ButtBitmap );
179 
180  KIGFX::COLOR4D buttcolor = KIGFX::COLOR4D( g_ColorRefs[ii].m_Numcolor );
181 
182  iconDC.SetPen( *wxBLACK_PEN );
183  brush.SetColour( buttcolor.ToColour() );
184  brush.SetStyle( wxBRUSHSTYLE_SOLID );
185 
186  iconDC.SetBrush( brush );
187  iconDC.SetBackground( *wxGREY_BRUSH );
188  iconDC.Clear();
189  iconDC.DrawRoundedRectangle( 0, 0, w, h, (double) h / 3 );
190 
191  wxBitmapButton* bitmapButton = new wxBitmapButton( m_panelDefinedColors, butt_ID, ButtBitmap,
192  wxDefaultPosition, wxSize( w+8, h+6 ) );
193  m_fgridColor->Add( bitmapButton, 0,
194  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
195  wxLEFT | wxBOTTOM, 5 );
196 
197  wxStaticText* label = new wxStaticText( m_panelDefinedColors, -1,
198  wxGetTranslation( g_ColorRefs[ii].m_ColorName ),
199  wxDefaultPosition, wxDefaultSize, 0 );
200  m_fgridColor->Add( label, 1,
201  wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL |
202  wxLEFT | wxRIGHT | wxBOTTOM, 5 );
203  m_buttonsColor.push_back( bitmapButton );
204  bitmapButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( COLOR4D_PICKER_DLG::buttColorClick ), NULL, this );
205  }
206 }
207 
208 
210 {
211  wxMemoryDC bitmapDC;
212  wxSize bmsize = m_RgbBitmap->GetSize();
213  int half_size = std::min( bmsize.x, bmsize.y )/2;
214  m_bitmapRGB = new wxBitmap( bmsize );
215  bitmapDC.SelectObject( *m_bitmapRGB );
216  wxPen pen;
217 
218  // clear background (set the window bg color)
219  wxBrush bgbrush( GetBackgroundColour() );
220  bitmapDC.SetBackground( bgbrush );
221  bitmapDC.Clear();
222 
223  // Use Y axis from bottom to top and origin to center
224  bitmapDC.SetAxisOrientation( true, true );
225  bitmapDC.SetDeviceOrigin( half_size, half_size );
226 
227  // Reserve room to draw cursors inside the bitmap
228  half_size -= m_cursorsSize/2;
229 
231 
232  // Red blue area in X Z 3d axis
233  double inc = 1.0 / half_size;
234  #define SLOPE_AXIS 50.0
235  double slope = SLOPE_AXIS/half_size;
236  color.g = 0.0;
237 
238  for( int xx = 0; xx < half_size; xx++ ) // blue axis
239  {
240  color.b = inc * xx;
241 
242  for( int yy = 0; yy < half_size; yy++ ) // Red axis
243  {
244  color.r = inc * yy;
245 
246  pen.SetColour( color.ToColour() );
247  bitmapDC.SetPen( pen );
248  bitmapDC.DrawPoint( xx, yy - (slope*xx) );
249  }
250  }
251 
252  // Red green area in y Z 3d axis
253  color.b = 0.0;
254  for( int xx = 0; xx < half_size; xx++ ) // green axis
255  {
256  color.g = inc * xx;
257 
258  for( int yy = 0; yy < half_size; yy++ ) // Red axis
259  {
260  color.r = inc * yy;
261 
262  pen.SetColour( color.ToColour() );
263  bitmapDC.SetPen( pen );
264  bitmapDC.DrawPoint( -xx, yy - (slope*xx) );
265  }
266  }
267 
268  // Blue green area in x y 3d axis
269  color.r = 0.0;
270  for( int xx = 0; xx < half_size; xx++ ) // green axis
271  {
272  color.g = inc * xx;
273 
274  for( int yy = 0; yy < half_size; yy++ ) // blue axis
275  {
276  color.b = inc * yy;
277 
278  pen.SetColour( color.ToColour() );
279  bitmapDC.SetPen( pen );
280 
281  // Mapping the xx, yy color axis to draw coordinates is more tricky than previously
282  // in DC coordinates:
283  // the blue axis is the (0, 0) to half_size, (-yy - SLOPE_AXIS)
284  // the green axis is the (0, 0) to - half_size, (-yy - SLOPE_AXIS)
285  int drawX = -xx + yy;
286  int drawY = - std::min( xx,yy ) * 0.9;
287  bitmapDC.DrawPoint( drawX, drawY - std::abs( slope*drawX ) );
288  }
289  }
290 }
291 
292 
294 {
295  wxMemoryDC bitmapDC;
296  wxSize bmsize = m_HsvBitmap->GetSize();
297  int half_size = std::min( bmsize.x, bmsize.y )/2;
298  delete m_bitmapHSV;
299  m_bitmapHSV = new wxBitmap( bmsize );
300  bitmapDC.SelectObject( *m_bitmapHSV );
301  wxPen pen;
302 
303  // clear background (set the window bd color)
304  wxBrush bgbrush( GetBackgroundColour() );
305  bitmapDC.SetBackground( bgbrush );
306  bitmapDC.Clear();
307 
308  // Use Y axis from bottom to top and origin to center
309  bitmapDC.SetAxisOrientation( true, true );
310  bitmapDC.SetDeviceOrigin( half_size, half_size );
311 
312  // Reserve room to draw cursors inside the bitmap
313  half_size -= m_cursorsSize/2;
314 
315  double hue, sat;
317  int sq_radius = half_size*half_size;
318 
319  for( int xx = -half_size; xx < half_size; xx++ )
320  {
321  for( int yy = -half_size; yy < half_size; yy++ )
322  {
323  sat = double(xx*xx + yy*yy) / sq_radius;
324 
325  // sat is <= 1.0
326  // any value > 1.0 is not a valid HSB color:
327  if( sat > 1.0 )
328  continue;
329 
330  // sat is the distance from center
331  sat = sqrt( sat );
332  hue = atan2( (double)yy, (double)xx ) * 180 / M_PI;
333 
334  if( hue < 0.0 )
335  hue += 360.0;
336 
337  color.FromHSV( hue, sat, 1.0 );
338 
339  pen.SetColour( color.ToColour() );
340  bitmapDC.SetPen( pen );
341  bitmapDC.DrawPoint( xx, yy );
342  }
343  }
344 
345  /* Deselect the Tool Bitmap from DC,
346  * in order to delete the MemoryDC safely without deleting the bitmap
347  */
348  bitmapDC.SelectObject( wxNullBitmap );
349 }
350 
351 
353 {
354  if( !m_bitmapRGB || m_bitmapRGB->GetSize() != m_RgbBitmap->GetSize() )
355  createRGBBitmap();
356 
357  wxMemoryDC bitmapDC;
358  wxSize bmsize = m_bitmapRGB->GetSize();
359  int half_size = std::min( bmsize.x, bmsize.y )/2;
360  wxBitmap newBm( *m_bitmapRGB );
361  bitmapDC.SelectObject( newBm );
362 
363  // Use Y axis from bottom to top and origin to center
364  bitmapDC.SetAxisOrientation( true, true );
365  bitmapDC.SetDeviceOrigin( half_size, half_size );
366 
367  // Reserve room to draw cursors inside the bitmap
368  half_size -= m_cursorsSize/2;
369 
370  // Draw the 3 RGB cursors, usiing white color to make them always visible:
371  wxPen pen( wxColor( 255, 255, 255 ) );
372  wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
373  bitmapDC.SetPen( pen );
374  bitmapDC.SetBrush( brush );
375  int half_csize = m_cursorsSize/2;
376 
377  #define SLOPE_AXIS 50.0
378  double slope = SLOPE_AXIS/half_size;
379 
380  // Red axis cursor (Z 3Daxis):
381  m_cursorBitmapRed.x = 0;
382  m_cursorBitmapRed.y = m_newColor4D.r * half_size;
383  bitmapDC.DrawRectangle( m_cursorBitmapRed.x - half_csize,
384  m_cursorBitmapRed.y - half_csize,
386 
387  // Blue axis cursor (X 3Daxis):
388  m_cursorBitmapBlue.x = m_newColor4D.b * half_size;
390  bitmapDC.DrawRectangle( m_cursorBitmapBlue.x - half_csize,
391  m_cursorBitmapBlue.y - half_csize,
393 
394  // Green axis cursor (Y 3Daxis):
395  m_cursorBitmapGreen.x = m_newColor4D.g * half_size;
398 
399  bitmapDC.DrawRectangle( m_cursorBitmapGreen.x - half_csize,
400  m_cursorBitmapGreen.y - half_csize,
402 
403  // Draw the 3 RGB axis:
404  half_size += half_size/5;
405  bitmapDC.DrawLine( 0, 0, 0, half_size ); // Red axis (Z 3D axis)
406  bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope ); // Blue axis (X 3D axis)
407  bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope ); // green axis (Y 3D axis)
408 
409  m_RgbBitmap->SetBitmap( newBm );
410  /* Deselect the Tool Bitmap from DC,
411  * in order to delete the MemoryDC safely without deleting the bitmap */
412  bitmapDC.SelectObject( wxNullBitmap );
413 }
414 
415 
417 {
418  if( !m_bitmapHSV || m_bitmapHSV->GetSize() != m_HsvBitmap->GetSize() )
419  createHSVBitmap();
420 
421  wxMemoryDC bitmapDC;
422  wxSize bmsize = m_bitmapHSV->GetSize();
423  int half_size = std::min( bmsize.x, bmsize.y )/2;
424  wxBitmap newBm( *m_bitmapHSV );
425  bitmapDC.SelectObject( newBm );
426 
427  // Use Y axis from bottom to top and origin to center
428  bitmapDC.SetAxisOrientation( true, true );
429  bitmapDC.SetDeviceOrigin( half_size, half_size );
430 
431  // Reserve room to draw cursors inside the bitmap
432  half_size -= m_cursorsSize/2;
433 
434  // Draw the HSB cursor:
435  m_cursorBitmapHSV.x = cos( m_hue * M_PI / 180.0 ) * half_size * m_sat;
436  m_cursorBitmapHSV.y = sin( m_hue * M_PI / 180.0 ) * half_size * m_sat;
437 
438  wxPen pen( wxColor( 0, 0, 0 ) );
439  wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
440  bitmapDC.SetPen( pen );
441  bitmapDC.SetBrush( brush );
442 
443  int half_csize = m_cursorsSize/2;
444  bitmapDC.DrawRectangle( m_cursorBitmapHSV.x- half_csize,
445  m_cursorBitmapHSV.y-half_csize,
447 
448  m_HsvBitmap->SetBitmap( newBm );
449  /* Deselect the Tool Bitmap from DC,
450  * in order to delete the MemoryDC safely without deleting the bitmap
451  */
452  bitmapDC.SelectObject( wxNullBitmap );
453 }
454 
455 
457 {
459 
460  if( aChanged == RED_CHANGED || aChanged == GREEN_CHANGED || aChanged == BLUE_CHANGED )
461  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
462 
463  if( aChanged != RED_CHANGED )
464  m_spinCtrlRed->SetValue( normalizeToInt( m_newColor4D.r ) );
465 
466  if( aChanged != GREEN_CHANGED )
468 
469  if( aChanged != BLUE_CHANGED )
471 
472  if( aChanged != HUE_CHANGED )
473  m_spinCtrlHue->SetValue( (int)m_hue );
474 
475  if( aChanged != SAT_CHANGED )
476  m_spinCtrlSaturation->SetValue( m_sat * 255 );
477 
478  if( aChanged != VAL_CHANGED )
479  {
480  m_sliderBrightness->SetValue(normalizeToInt( m_val ) );
481  }
482 }
483 
484 
486 {
487  m_NewColorRect->Freeze(); // Avoid flicker
488  m_HsvBitmap->Freeze();
489  m_RgbBitmap->Freeze();
491  drawHSVPalette();
492  drawRGBPalette();
493  m_NewColorRect->Thaw();
494  m_HsvBitmap->Thaw();
495  m_RgbBitmap->Thaw();
496  m_NewColorRect->Refresh();
497  m_HsvBitmap->Refresh();
498  m_RgbBitmap->Refresh();
499 }
500 
501 
502 void COLOR4D_PICKER_DLG::buttColorClick( wxCommandEvent& event )
503 {
504  int id = event.GetId();
506  m_newColor4D.r = color.r;
507  m_newColor4D.g = color.g;
508  m_newColor4D.b = color.b;
509 
510  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
512 
513  drawAll();
514 
515  event.Skip();
516 }
517 
518 
519 void COLOR4D_PICKER_DLG::onRGBMouseClick( wxMouseEvent& event )
520 {
521  m_allowMouseEvents = true;
522  wxPoint mousePos = event.GetPosition();
523 
524  // The cursor position is relative to the m_bitmapHSV wxBitmap center
525  wxSize bmsize = m_bitmapRGB->GetSize();
526  int half_size = std::min( bmsize.x, bmsize.y )/2;
527  mousePos.x -= half_size;
528  mousePos.y -= half_size;
529  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
530 
531  wxPoint dist = m_cursorBitmapRed - mousePos;
532 
533  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
534  {
536  return;
537  }
538 
539  dist = m_cursorBitmapGreen - mousePos;
540 
541  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
542  {
544  return;
545  }
546 
547  dist = m_cursorBitmapBlue - mousePos;
548 
549  if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 )
550  {
552  return;
553  }
554 
555  m_selectedCursor = nullptr;
556 }
557 
558 
559 void COLOR4D_PICKER_DLG::onRGBMouseDrag( wxMouseEvent& event )
560 {
561  if( !event.Dragging() || !m_allowMouseEvents )
562  {
563  m_selectedCursor = nullptr;
564  return;
565  }
566 
570  return;
571 
572  // Adjust the HSV cursor position to follow the mouse cursor
573  // The cursor position is relative to the m_bitmapHSV wxBitmap center
574  wxPoint mousePos = event.GetPosition();
575  wxSize bmsize = m_bitmapRGB->GetSize();
576  int half_size = std::min( bmsize.x, bmsize.y )/2;
577  mousePos.x -= half_size;
578  mousePos.y -= half_size;
579  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
580 
581  half_size -= m_cursorsSize/2; // the actual half_size of the palette area
582 
583  // Change colors according to the selected cursor:
585  {
586  if( mousePos.y >= 0 && mousePos.y <= half_size )
587  m_newColor4D.r = (double)mousePos.y / half_size;
588  else
589  return;
590  }
591 
593  {
594  mousePos.x = -mousePos.x;
595 
596  if( mousePos.x >= 0 && mousePos.x <= half_size )
597  m_newColor4D.g = (double)mousePos.x / half_size;
598  else
599  return;
600  }
601 
603  {
604  if( mousePos.x >= 0 && mousePos.x <= half_size )
605  m_newColor4D.b = (double)mousePos.x / half_size;
606  else
607  return;
608  }
609 
610  m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
612 
613  drawAll();
614 }
615 
616 
617 void COLOR4D_PICKER_DLG::onHSVMouseClick( wxMouseEvent& event )
618 {
619  m_allowMouseEvents = true;
620 
621  if( setHSvaluesFromCursor( event.GetPosition() ) )
622  drawAll();
623 }
624 
625 
626 void COLOR4D_PICKER_DLG::onHSVMouseDrag( wxMouseEvent& event )
627 {
628  if( !event.Dragging() || !m_allowMouseEvents )
629  return;
630 
631  if( setHSvaluesFromCursor( event.GetPosition() ) )
632  drawAll();
633 }
634 
635 
637 {
638  wxPoint mousePos = aMouseCursor;
639  wxSize bmsize = m_bitmapHSV->GetSize();
640  int half_size = std::min( bmsize.x, bmsize.y )/2;
641  // Make the cursor position relative to the m_bitmapHSV wxBitmap center
642  mousePos.x -= half_size;
643  mousePos.y -= half_size;
644  mousePos.y = -mousePos.y; // Use the bottom to top vertical axis
645 
646  // The HS cursor position is restricted to a circle of radius half_size
647  double dist_from_centre = hypot( (double)mousePos.x, (double)mousePos.y );
648 
649  if( dist_from_centre > half_size )
650  // Saturation cannot be calculated:
651  return false;
652 
653  m_cursorBitmapHSV = mousePos;
654 
655  // Set saturation and hue from new cursor position:
656  half_size -= m_cursorsSize/2; // the actual half_size of the palette area
657  m_sat = dist_from_centre / half_size;
658 
659  if( m_sat > 1.0 )
660  m_sat = 1.0;
661 
662  m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
663 
664  if( m_hue < 0 )
665  m_hue += 360.0;
666 
669 
670  return true;
671 }
672 
673 
674 void COLOR4D_PICKER_DLG::OnChangeAlpha( wxScrollEvent& event )
675 {
676  double alpha = (double)event.GetPosition() / ALPHA_MAX;
677  m_newColor4D.a = alpha;
678  m_NewColorRect->Freeze(); // Avoid flicker
680  m_NewColorRect->Thaw();
681  m_NewColorRect->Refresh();
682 }
683 
684 
685 void COLOR4D_PICKER_DLG::OnChangeEditRed( wxSpinEvent& event )
686 {
687  double val = (double)event.GetPosition() / 255.0;
688  m_newColor4D.r = val;
690 
691  drawAll();
692 }
693 
694 
695 void COLOR4D_PICKER_DLG::OnChangeEditGreen( wxSpinEvent& event )
696 {
697  double val = (double)event.GetPosition() / 255.0;
698  m_newColor4D.g = val;
700 
701  drawAll();
702 }
703 
704 
705 void COLOR4D_PICKER_DLG::OnChangeEditBlue( wxSpinEvent& event )
706 {
707  double val = (double)event.GetPosition() / 255.0;
708  m_newColor4D.b = val;
710 
711  drawAll();
712 }
713 
714 
715 void COLOR4D_PICKER_DLG::OnChangeEditHue( wxSpinEvent& event )
716 {
717  m_hue = (double)event.GetPosition();
718 
720 
722 
723  drawAll();
724 }
725 
726 
727 void COLOR4D_PICKER_DLG::OnChangeEditSat( wxSpinEvent& event )
728 {
729  m_sat = (double)event.GetPosition() / 255.0;
730 
732 
734 
735  drawAll();
736 }
737 
738 
739 void COLOR4D_PICKER_DLG::OnChangeBrightness( wxScrollEvent& event )
740 {
741  m_val = (double)event.GetPosition() / 255.0;
742 
744 
746 
747  drawAll();
748 }
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)
static const int dist[10][10]
Definition: ar_matrix.cpp:320
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...
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