29#include <wx/dcmemory.h>
32#define SLOPE_AXIS ( bmsize.y / 5.28 )
39 wxSize textLength = aCtrl->GetTextExtent(
"999" );
40 wxSize ctrlSize = aCtrl->GetSizeFromTextSize( textLength );
42 aCtrl->SetMinSize( ctrlSize );
43 aCtrl->SetSize( ctrlSize );
48 bool aAllowOpacityControl,
50 const COLOR4D& aDefaultColor ) :
68 m_colorValue->SetMinSize( wxSize( GetTextExtent( wxS(
"#DDDDDDDD" ) ).x + FromDIP( 8 ), -1 ) );
74 if( aCurrentColor != COLOR4D::UNSPECIFIED )
83 if( aCurrentColor == COLOR4D::UNSPECIFIED )
101 if( aDefaultColor == COLOR4D::UNSPECIFIED )
121 swatch->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
130 wxSize swatchSize = aStaticBitmap->GetSize();
134 ToPhys( swatchSize ),
135 ToPhys( checkerboardSize ),
136 aStaticBitmap->GetParent()->GetBackgroundColour() );
138 newBm.SetScaleFactor( GetDPIScaleFactor() );
139 aStaticBitmap->SetBitmap( newBm );
169 #define ID_COLOR_BLACK 2000
179 int table_row_count = 7;
186 [&](
int aId,
COLOR4D aColor,
const wxString& aColorName )
189 ToPhys( swatchSize ),
190 ToPhys( checkerboardSize ),
191 checkboardBackground );
193 bm.SetScaleFactor( GetDPIScaleFactor() );
196 m_fgridColor->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 5 );
199 wxDefaultPosition, wxDefaultSize, 0 );
200 m_fgridColor->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 15 );
204 swatch->Connect( wxEVT_LEFT_DOWN,
207 swatch->Connect( wxEVT_LEFT_DCLICK,
213 if( aPredefinedColors )
215 for(
unsigned jj = 0; jj < aPredefinedColors->size() && jj <
NBCOLORS; ++jj )
228 for(
int jj = 0; jj <
NBCOLORS; ++jj, grid_col++ )
230 if( grid_col * table_row_count >=
NBCOLORS )
237 int ii = grid_row + ( grid_col * table_row_count );
241 addSwatch( butt_ID, buttcolor, wxGetTranslation(
colorRefs()[ii].m_ColorName ) );
251 int half_size = std::min( bmsize.x, bmsize.y )/2;
258#define MAPX( xx ) bmsize.x / 2 + ( xx )
259#define MAPY( yy ) bmsize.y / 2 - ( yy )
267 double inc = 255.0 / half_size;
271 wxImage img( bmsize );
274 wxColor bg = GetBackgroundColour();
277 wxColourBase::ChannelType bgR = bg.Red();
278 wxColourBase::ChannelType bgG = bg.Green();
279 wxColourBase::ChannelType bgB = bg.Blue();
281 for(
int xx = 0; xx < bmsize.x; xx++ )
283 for(
int yy = 0; yy < bmsize.y; yy++ )
284 img.SetRGB( xx, yy, bgR, bgG, bgB );
288 for(
int xx = 0; xx < half_size; xx++ )
292 for(
int yy = 0; yy < half_size; yy++ )
302 for(
int xx = 0; xx < half_size; xx++ )
306 for(
int yy = 0; yy < half_size; yy++ )
316 for(
int xx = 0; xx < half_size; xx++ )
320 for(
int yy = 0; yy < half_size; yy++ )
328 int drawX = -xx + yy;
329 int drawY = - std::min( xx,yy ) * 0.9;
338 m_bitmapRGB->SetScaleFactor( GetDPIScaleFactor() );
346 int half_size = std::min( bmsize.x, bmsize.y )/2;
350 #define MAPX( xx ) bmsize.x / 2 + ( xx )
351 #define MAPY( yy ) bmsize.y / 2 - ( yy )
353 wxImage img( bmsize );
356 wxColor bg = GetBackgroundColour();
359 wxColourBase::ChannelType bgR = bg.Red();
360 wxColourBase::ChannelType bgG = bg.Green();
361 wxColourBase::ChannelType bgB = bg.Blue();
363 for(
int xx = 0; xx < bmsize.x; xx++ )
365 for(
int yy = 0; yy < bmsize.y; yy++ )
366 img.SetRGB( xx, yy, bgR, bgG, bgB );
374 int sq_radius = half_size*half_size;
377 for(
int xx = -half_size; xx < half_size; xx++ )
379 for(
int yy = -half_size; yy < half_size; yy++ )
381 sat = double(xx*xx + yy*yy) / sq_radius;
390 hue = atan2( (
double)yy, (
double)xx ) * 180 / M_PI;
395 color.FromHSV( hue, sat, 1.0 );
404 m_bitmapHSV->SetScaleFactor( GetDPIScaleFactor() );
416 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
419 newBm.SetScaleFactor( 1.0 );
421 bitmapDC.SelectObject( newBm );
424 bitmapDC.SetAxisOrientation(
true,
true );
426#if defined( __WXMSW__ )
428 bitmapDC.SetDeviceOrigin( half_size, -half_size );
430 bitmapDC.SetDeviceOrigin( half_size, half_size );
437 wxPen pen( wxColor( 255, 255, 255 ), 2 );
438 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
439 bitmapDC.SetPen( pen );
440 bitmapDC.SetBrush( brush );
469 half_size += half_size/5;
470 bitmapDC.DrawLine( 0, 0, 0, half_size );
471 bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );
472 bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );
474 newBm.SetScaleFactor( GetDPIScaleFactor() );
479 bitmapDC.SelectObject( wxNullBitmap );
490 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
493 newBm.SetScaleFactor( 1.0 );
495 bitmapDC.SelectObject( newBm );
498 bitmapDC.SetAxisOrientation(
true,
true );
499#if defined( __WXMSW__)
501 bitmapDC.SetDeviceOrigin( half_size, -half_size );
503 bitmapDC.SetDeviceOrigin( half_size, half_size );
513 wxPen pen( wxColor( 0, 0, 0 ), 2 );
514 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
515 bitmapDC.SetPen( pen );
516 bitmapDC.SetBrush( brush );
522 newBm.SetScaleFactor( GetDPIScaleFactor() );
528 bitmapDC.SelectObject( wxNullBitmap );
534 if( aCheckTransparency )
598 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
604 int id =
event.GetId();
625 wxPoint mousePos = ToPhys( event.GetPosition() );
627 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
629 mousePos.x -= half_size;
630 mousePos.y -= half_size;
631 mousePos.y = -mousePos.y;
678 wxPoint mousePos = ToPhys( event.GetPosition() );
680 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
682 mousePos.x -= half_size;
683 mousePos.y -= half_size;
684 mousePos.y = -mousePos.y;
691 if( mousePos.y >= 0 && mousePos.y <= half_size )
699 mousePos.x = -mousePos.x;
701 if( mousePos.x >= 0 && mousePos.x <= half_size )
709 if( mousePos.x >= 0 && mousePos.x <= half_size )
763 wxPoint mousePos = ToPhys( aMouseCursor );
765 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
768 mousePos.x -= half_size;
769 mousePos.y -= half_size;
770 mousePos.y = -mousePos.y;
773 double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
775 if( dist_from_centre > half_size )
785 m_sat = dist_from_centre / half_size;
790 m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
804 double alpha = (double)event.GetPosition() /
ALPHA_MAX;
816 double val = (double)event.GetPosition() / 255.0;
826 double val = (double)event.GetPosition() / 255.0;
836 double val = (double)event.GetPosition() / 255.0;
846 m_hue = (double)event.GetPosition();
858 m_sat = (double)event.GetPosition() / 255.0;
870 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.
void onSize(wxSizeEvent &event) override
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.
bool SetFromHexString(const wxString &aColorString)
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
wxString ToHexString() const
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.