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 )
120 swatch->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
129 wxSize swatchSize = aStaticBitmap->GetSize();
133 ToPhys( swatchSize ),
134 ToPhys( checkerboardSize ),
135 aStaticBitmap->GetParent()->GetBackgroundColour() );
137 newBm.SetScaleFactor( GetDPIScaleFactor() );
138 aStaticBitmap->SetBitmap( newBm );
168 #define ID_COLOR_BLACK 2000
178 int table_row_count = 7;
185 [&](
int aId,
COLOR4D aColor,
const wxString& aColorName )
188 ToPhys( swatchSize ),
189 ToPhys( checkerboardSize ),
190 checkboardBackground );
192 bm.SetScaleFactor( GetDPIScaleFactor() );
195 m_fgridColor->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 5 );
198 wxDefaultPosition, wxDefaultSize, 0 );
199 m_fgridColor->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, 15 );
203 swatch->Connect( wxEVT_LEFT_DOWN,
206 swatch->Connect( wxEVT_LEFT_DCLICK,
212 if( aPredefinedColors )
214 for(
unsigned jj = 0; jj < aPredefinedColors->size() && jj <
NBCOLORS; ++jj )
227 for(
int jj = 0; jj <
NBCOLORS; ++jj, grid_col++ )
229 if( grid_col * table_row_count >=
NBCOLORS )
236 int ii = grid_row + ( grid_col * table_row_count );
240 addSwatch( butt_ID, buttcolor, wxGetTranslation(
colorRefs()[ii].m_ColorName ) );
250 int half_size = std::min( bmsize.x, bmsize.y )/2;
257#define MAPX( xx ) bmsize.x / 2 + ( xx )
258#define MAPY( yy ) bmsize.y / 2 - ( yy )
266 double inc = 255.0 / half_size;
270 wxImage img( bmsize );
273 wxColor bg = GetBackgroundColour();
276 wxColourBase::ChannelType bgR = bg.Red();
277 wxColourBase::ChannelType bgG = bg.Green();
278 wxColourBase::ChannelType bgB = bg.Blue();
280 for(
int xx = 0; xx < bmsize.x; xx++ )
282 for(
int yy = 0; yy < bmsize.y; yy++ )
283 img.SetRGB( xx, yy, bgR, bgG, bgB );
287 for(
int xx = 0; xx < half_size; xx++ )
291 for(
int yy = 0; yy < half_size; yy++ )
301 for(
int xx = 0; xx < half_size; xx++ )
305 for(
int yy = 0; yy < half_size; yy++ )
315 for(
int xx = 0; xx < half_size; xx++ )
319 for(
int yy = 0; yy < half_size; yy++ )
327 int drawX = -xx + yy;
328 int drawY = - std::min( xx,yy ) * 0.9;
337 m_bitmapRGB->SetScaleFactor( GetDPIScaleFactor() );
345 int half_size = std::min( bmsize.x, bmsize.y )/2;
349 #define MAPX( xx ) bmsize.x / 2 + ( xx )
350 #define MAPY( yy ) bmsize.y / 2 - ( yy )
352 wxImage img( bmsize );
355 wxColor bg = GetBackgroundColour();
358 wxColourBase::ChannelType bgR = bg.Red();
359 wxColourBase::ChannelType bgG = bg.Green();
360 wxColourBase::ChannelType bgB = bg.Blue();
362 for(
int xx = 0; xx < bmsize.x; xx++ )
364 for(
int yy = 0; yy < bmsize.y; yy++ )
365 img.SetRGB( xx, yy, bgR, bgG, bgB );
373 int sq_radius = half_size*half_size;
376 for(
int xx = -half_size; xx < half_size; xx++ )
378 for(
int yy = -half_size; yy < half_size; yy++ )
380 sat = double(xx*xx + yy*yy) / sq_radius;
389 hue = atan2( (
double)yy, (
double)xx ) * 180 / M_PI;
394 color.FromHSV( hue, sat, 1.0 );
403 m_bitmapHSV->SetScaleFactor( GetDPIScaleFactor() );
415 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
418 newBm.SetScaleFactor( 1.0 );
420 bitmapDC.SelectObject( newBm );
423 bitmapDC.SetAxisOrientation(
true,
true );
424#if defined( __WXMSW__)
426 bitmapDC.SetDeviceOrigin( half_size, -half_size );
428 bitmapDC.SetDeviceOrigin( half_size, half_size );
435 wxPen pen( wxColor( 255, 255, 255 ), 2 );
436 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
437 bitmapDC.SetPen( pen );
438 bitmapDC.SetBrush( brush );
467 half_size += half_size/5;
468 bitmapDC.DrawLine( 0, 0, 0, half_size );
469 bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );
470 bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );
472 newBm.SetScaleFactor( GetDPIScaleFactor() );
477 bitmapDC.SelectObject( wxNullBitmap );
488 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
491 newBm.SetScaleFactor( 1.0 );
493 bitmapDC.SelectObject( newBm );
496 bitmapDC.SetAxisOrientation(
true,
true );
497#if defined( __WXMSW__)
499 bitmapDC.SetDeviceOrigin( half_size, -half_size );
501 bitmapDC.SetDeviceOrigin( half_size, half_size );
511 wxPen pen( wxColor( 0, 0, 0 ), 2 );
512 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
513 bitmapDC.SetPen( pen );
514 bitmapDC.SetBrush( brush );
520 newBm.SetScaleFactor( GetDPIScaleFactor() );
526 bitmapDC.SelectObject( wxNullBitmap );
532 if( aCheckTransparency )
596 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
602 int id =
event.GetId();
623 wxPoint mousePos = ToPhys( event.GetPosition() );
625 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
627 mousePos.x -= half_size;
628 mousePos.y -= half_size;
629 mousePos.y = -mousePos.y;
676 wxPoint mousePos = ToPhys( event.GetPosition() );
678 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
680 mousePos.x -= half_size;
681 mousePos.y -= half_size;
682 mousePos.y = -mousePos.y;
689 if( mousePos.y >= 0 && mousePos.y <= half_size )
697 mousePos.x = -mousePos.x;
699 if( mousePos.x >= 0 && mousePos.x <= half_size )
707 if( mousePos.x >= 0 && mousePos.x <= half_size )
761 wxPoint mousePos = ToPhys( aMouseCursor );
763 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
766 mousePos.x -= half_size;
767 mousePos.y -= half_size;
768 mousePos.y = -mousePos.y;
771 double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
773 if( dist_from_centre > half_size )
783 m_sat = dist_from_centre / half_size;
788 m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
802 double alpha = (double)event.GetPosition() /
ALPHA_MAX;
814 double val = (double)event.GetPosition() / 255.0;
824 double val = (double)event.GetPosition() / 255.0;
834 double val = (double)event.GetPosition() / 255.0;
844 m_hue = (double)event.GetPosition();
856 m_sat = (double)event.GetPosition() / 255.0;
868 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.