28#include <wx/dcmemory.h>
37 wxSize textLength = aCtrl->GetTextExtent(
"999" );
38 wxSize ctrlSize = aCtrl->GetSizeFromTextSize( textLength );
40 aCtrl->SetMinSize( ctrlSize );
41 aCtrl->SetSize( ctrlSize );
46 bool aAllowOpacityControl,
48 const COLOR4D& aDefaultColor ) :
66 if( aCurrentColor != COLOR4D::UNSPECIFIED )
75 if( aCurrentColor == COLOR4D::UNSPECIFIED )
93 if( aDefaultColor == COLOR4D::UNSPECIFIED )
112 swatch->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
123 aStaticBitmap->GetParent()->GetBackgroundColour() );
124 aStaticBitmap->SetBitmap( newBm );
153 #define ID_COLOR_BLACK 2000
163 int table_row_count = 7;
170 [&](
int aId,
COLOR4D aColor,
const wxString& aColorName )
173 checkerboardSize, checkboardBackground );
176 m_fgridColor->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 5 );
179 wxDefaultPosition, wxDefaultSize, 0 );
180 m_fgridColor->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 15 );
184 swatch->Connect( wxEVT_LEFT_DOWN,
187 swatch->Connect( wxEVT_LEFT_DCLICK,
193 if( aPredefinedColors )
195 for(
unsigned jj = 0; jj < aPredefinedColors->size() && jj <
NBCOLORS; ++jj )
208 for(
int jj = 0; jj <
NBCOLORS; ++jj, grid_col++ )
210 if( grid_col * table_row_count >=
NBCOLORS )
217 int ii = grid_row + ( grid_col * table_row_count );
221 addSwatch( butt_ID, buttcolor, wxGetTranslation(
colorRefs()[ii].m_ColorName ) );
231 int half_size = std::min( bmsize.x, bmsize.y )/2;
238#define MAPX( xx ) bmsize.x / 2 + ( xx )
239#define MAPY( yy ) bmsize.y / 2 - ( yy )
247 double inc = 255.0 / half_size;
248 #define SLOPE_AXIS 50.0
252 wxImage img( bmsize );
255 wxColor bg = GetBackgroundColour();
258 wxColourBase::ChannelType bgR = bg.Red();
259 wxColourBase::ChannelType bgG = bg.Green();
260 wxColourBase::ChannelType bgB = bg.Blue();
262 for(
int xx = 0; xx < bmsize.x; xx++ )
264 for(
int yy = 0; yy < bmsize.y; yy++ )
265 img.SetRGB( xx, yy, bgR, bgG, bgB );
269 for(
int xx = 0; xx < half_size; xx++ )
273 for(
int yy = 0; yy < half_size; yy++ )
283 for(
int xx = 0; xx < half_size; xx++ )
287 for(
int yy = 0; yy < half_size; yy++ )
297 for(
int xx = 0; xx < half_size; xx++ )
301 for(
int yy = 0; yy < half_size; yy++ )
309 int drawX = -xx + yy;
310 int drawY = - std::min( xx,yy ) * 0.9;
325 int half_size = std::min( bmsize.x, bmsize.y )/2;
329 #define MAPX( xx ) bmsize.x / 2 + ( xx )
330 #define MAPY( yy ) bmsize.y / 2 - ( yy )
332 wxImage img( bmsize );
335 wxColor bg = GetBackgroundColour();
338 wxColourBase::ChannelType bgR = bg.Red();
339 wxColourBase::ChannelType bgG = bg.Green();
340 wxColourBase::ChannelType bgB = bg.Blue();
342 for(
int xx = 0; xx < bmsize.x; xx++ )
344 for(
int yy = 0; yy < bmsize.y; yy++ )
345 img.SetRGB( xx, yy, bgR, bgG, bgB );
353 int sq_radius = half_size*half_size;
356 for(
int xx = -half_size; xx < half_size; xx++ )
358 for(
int yy = -half_size; yy < half_size; yy++ )
360 sat = double(xx*xx + yy*yy) / sq_radius;
369 hue = atan2( (
double)yy, (
double)xx ) * 180 / M_PI;
374 color.FromHSV( hue, sat, 1.0 );
393 int half_size = std::min( bmsize.x, bmsize.y )/2;
395 bitmapDC.SelectObject( newBm );
398 bitmapDC.SetAxisOrientation(
true,
true );
399 #if wxCHECK_VERSION( 3, 1, 7 )
401 bitmapDC.SetDeviceOrigin( half_size, -half_size );
403 bitmapDC.SetDeviceOrigin( half_size, half_size );
410 wxPen pen( wxColor( 255, 255, 255 ), 2 );
411 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
412 bitmapDC.SetPen( pen );
413 bitmapDC.SetBrush( brush );
416 #define SLOPE_AXIS 50.0
443 half_size += half_size/5;
444 bitmapDC.DrawLine( 0, 0, 0, half_size );
445 bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );
446 bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );
452 bitmapDC.SelectObject( wxNullBitmap );
463 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
465 bitmapDC.SelectObject( newBm );
468 bitmapDC.SetAxisOrientation(
true,
true );
469 #if wxCHECK_VERSION( 3, 1, 7 )
471 bitmapDC.SetDeviceOrigin( half_size, -half_size );
473 bitmapDC.SetDeviceOrigin( half_size, half_size );
483 wxPen pen( wxColor( 0, 0, 0 ), 2 );
484 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
485 bitmapDC.SetPen( pen );
486 bitmapDC.SetBrush( brush );
498 bitmapDC.SelectObject( wxNullBitmap );
504 if( aCheckTransparency )
561 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
567 int id =
event.GetId();
586 wxPoint mousePos =
event.GetPosition();
590 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
591 mousePos.x -= half_size;
592 mousePos.y -= half_size;
593 mousePos.y = -mousePos.y;
640 wxPoint mousePos =
event.GetPosition();
642 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
643 mousePos.x -= half_size;
644 mousePos.y -= half_size;
645 mousePos.y = -mousePos.y;
652 if( mousePos.y >= 0 && mousePos.y <= half_size )
660 mousePos.x = -mousePos.x;
662 if( mousePos.x >= 0 && mousePos.x <= half_size )
670 if( mousePos.x >= 0 && mousePos.x <= half_size )
714 wxPoint mousePos = aMouseCursor;
716 int half_size = std::min( bmsize.x, bmsize.y )/2;
719 mousePos.x -= half_size;
720 mousePos.y -= half_size;
721 mousePos.y = -mousePos.y;
724 double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
726 if( dist_from_centre > half_size )
736 m_sat = dist_from_centre / half_size;
741 m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
755 double alpha = (double)event.GetPosition() /
ALPHA_MAX;
767 double val = (double)event.GetPosition() / 255.0;
777 double val = (double)event.GetPosition() / 255.0;
787 double val = (double)event.GetPosition() / 255.0;
797 m_hue = (double)event.GetPosition();
809 m_sat = (double)event.GetPosition() / 255.0;
821 m_val = (double)event.GetPosition() / 255.0;
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
COLOR_PICKER m_ColorPicker
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
Class DIALOG_COLOR_PICKER_BASE.
wxSpinCtrl * m_spinCtrlRed
wxSpinCtrl * m_spinCtrlHue
wxStaticBitmap * m_NewColorRect
wxSpinCtrl * m_spinCtrlBlue
wxBoxSizer * m_SizerTransparency
wxStaticBitmap * m_RgbBitmap
wxSlider * m_sliderBrightness
wxSlider * m_sliderTransparency
wxTextCtrl * m_colorValue
wxStaticBitmap * m_HsvBitmap
wxPanel * m_panelDefinedColors
wxStaticBitmap * m_OldColorRect
wxSpinCtrl * m_spinCtrlSaturation
wxButton * m_resetToDefault
wxFlexGridSizer * m_fgridColor
wxSpinCtrl * m_spinCtrlGreen
KIGFX::COLOR4D m_previousColor4D
the initial color4d
void buttColorClick(wxMouseEvent &event)
Event handler for double click on color buttons.
void OnResetButton(wxCommandEvent &aEvent) override
void initDefinedColors(CUSTOM_COLORS_LIST *aPredefinedColors)
Create the bitmap buttons for each defined colors.
void colorDClick(wxMouseEvent &event)
called when creating the dialog
void OnChangeAlpha(wxScrollEvent &event) override
Event handlers from wxSpinControl.
void onRGBMouseDrag(wxMouseEvent &event) override
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
KIGFX::COLOR4D m_newColor4D
the current color4d
double m_val
the current value (0 ... 1.0)
void OnChangeEditGreen(wxSpinEvent &event) override
void createRGBBitmap()
generate the bitmap that shows the RVB color space
DIALOG_COLOR_PICKER(wxWindow *aParent, const KIGFX::COLOR4D &aCurrentColor, bool aAllowOpacityControl, CUSTOM_COLORS_LIST *aUserColors=nullptr, const KIGFX::COLOR4D &aDefaultColor=KIGFX::COLOR4D::UNSPECIFIED)
Dialog constructor.
std::vector< wxStaticBitmap * > m_colorSwatches
list of defined colors buttons
wxBitmap * m_bitmapRGB
the basic RGB palette
void OnChangeEditBlue(wxSpinEvent &event) override
wxPoint m_cursorBitmapBlue
the blue cursor on the RGB bitmap palette.
wxBitmap * m_bitmapHSV
the basic HUV palette
void OnColorValueText(wxCommandEvent &event) override
Event handler for the reset button press.
void createHSVBitmap()
generate the bitmap that shows the HSV color circle
std::vector< KIGFX::COLOR4D > m_Color4DList
the list of color4d ordered by button ID, for predefined colors
void onRGBMouseClick(wxMouseEvent &event) override
wxPoint m_cursorBitmapRed
the red cursor on the RGB bitmap palette.
double m_hue
the current hue, in degrees (0 ... 360)
bool setHSvaluesFromCursor(const wxPoint &aMouseCursor)
Manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
void OnChangeEditSat(wxSpinEvent &event) override
mouse handlers, when clicking on a palette bitmap
double m_sat
the current saturation (0 ... 1.0)
bool m_allowOpacityCtrl
true to show the widget, false to keep alpha channel = 1.0
bool TransferDataToWindow() override
void drawHSVPalette()
draws the HSV color circle
void onHSVMouseClick(wxMouseEvent &event) override
void onHSVMouseDrag(wxMouseEvent &event) override
void updatePreview(wxStaticBitmap *aStaticBitmap, KIGFX::COLOR4D &aColor4D)
Event handler from wxSlider: brightness (value) control.
KIGFX::COLOR4D m_defaultColor
The default color4d.
void OnChangeEditRed(wxSpinEvent &event) override
void OnChangeEditHue(wxSpinEvent &event) override
int normalizeToInt(double aValue, int aValMax=255)
void SetEditVals(CHANGED_COLOR aChanged, bool aCheckTransparency)
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
void drawRGBPalette()
draws the RVB color space
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
wxPoint * m_selectedCursor
the ref cursor to the selected cursor, if any, or null.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
APP_SETTINGS_BASE * KifaceSettings() const
A color representation with 4 components: red, green, blue, alpha.
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
@ NBCOLORS
Number of colors.
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
void configureSpinCtrl(wxSpinCtrl *aCtrl)
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
A class to handle a custom color (predefined color) for the color picker dialog.