27 #include <wx/bitmap.h> 28 #include <wx/dcmemory.h> 30 #define ALPHA_MAX 100 // the max value returned by the alpha (opacity) slider 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 // colors_id = ID_COLOR_BLACK a ID_COLOR_BLACK + NBCOLORS-1 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;
311 img.SetRGB(
MAPX( drawX ),
MAPY( drawY - std::abs( slope*drawX ) ),
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 bitmapDC.SetDeviceOrigin( half_size, half_size );
405 wxPen pen( wxColor( 255, 255, 255 ) );
406 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
407 bitmapDC.SetPen( pen );
408 bitmapDC.SetBrush( brush );
411 #define SLOPE_AXIS 50.0 438 half_size += half_size/5;
439 bitmapDC.DrawLine( 0, 0, 0, half_size );
440 bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );
441 bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );
447 bitmapDC.SelectObject( wxNullBitmap );
458 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
460 bitmapDC.SelectObject( newBm );
463 bitmapDC.SetAxisOrientation(
true,
true );
464 bitmapDC.SetDeviceOrigin( half_size, half_size );
473 wxPen pen( wxColor( 0, 0, 0 ) );
474 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
475 bitmapDC.SetPen( pen );
476 bitmapDC.SetBrush( brush );
488 bitmapDC.SelectObject( wxNullBitmap );
494 if( aCheckTransparency )
551 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
557 int id =
event.GetId();
576 wxPoint mousePos =
event.GetPosition();
580 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
581 mousePos.x -= half_size;
582 mousePos.y -= half_size;
583 mousePos.y = -mousePos.y;
630 wxPoint mousePos =
event.GetPosition();
632 int half_size = std::min( bmsize.x, bmsize.y ) / 2;
633 mousePos.x -= half_size;
634 mousePos.y -= half_size;
635 mousePos.y = -mousePos.y;
642 if( mousePos.y >= 0 && mousePos.y <= half_size )
650 mousePos.x = -mousePos.x;
652 if( mousePos.x >= 0 && mousePos.x <= half_size )
660 if( mousePos.x >= 0 && mousePos.x <= half_size )
704 wxPoint mousePos = aMouseCursor;
706 int half_size = std::min( bmsize.x, bmsize.y )/2;
709 mousePos.x -= half_size;
710 mousePos.y -= half_size;
711 mousePos.y = -mousePos.y;
714 double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
716 if( dist_from_centre > half_size )
726 m_sat = dist_from_centre / half_size;
731 m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
745 double alpha = (double)event.GetPosition() /
ALPHA_MAX;
757 double val = (double)event.GetPosition() / 255.0;
767 double val = (double)event.GetPosition() / 255.0;
777 double val = (double)event.GetPosition() / 255.0;
787 m_hue = (double)event.GetPosition();
799 m_sat = (double)event.GetPosition() / 255.0;
811 m_val = (double)event.GetPosition() / 255.0;
double m_hue
the current hue, in degrees (0 ... 360)
wxStaticBitmap * m_RgbBitmap
bool m_allowOpacityCtrl
true to show the widget, false to keep alpha channel = 1.0
double m_sat
the current saturation (0 ... 1.0)
void ToHSV(double &aOutHue, double &aOutSaturation, double &aOutValue, bool aAlwaysDefineHue=false) const
Convert current color (stored in RGB) to HSV format.
void drawRGBPalette()
draws the RVB color space
wxButton * m_resetToDefault
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxPanel * m_panelDefinedColors
wxSpinCtrl * m_spinCtrlSaturation
void configureSpinCtrl(wxSpinCtrl *aCtrl)
void OnChangeEditGreen(wxSpinEvent &event) override
std::vector< KIGFX::COLOR4D > m_Color4DList
the list of color4d ordered by button ID, for predefined colors
wxStaticBitmap * m_HsvBitmap
void OnChangeAlpha(wxScrollEvent &event) override
Event handlers from wxSpinControl.
int normalizeToInt(double aValue, int aValMax=255)
wxSpinCtrl * m_spinCtrlRed
wxSpinCtrl * m_spinCtrlBlue
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
void onHSVMouseDrag(wxMouseEvent &event) override
void OnColorValueText(wxCommandEvent &event) override
Event handler for the reset button press.
void drawHSVPalette()
draws the HSV color circle
A class to handle a custom color (predefined color) for the color picker dialog.
wxStaticBitmap * m_OldColorRect
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
void createHSVBitmap()
generate the bitmap that shows the HSV color circle
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
KIGFX::COLOR4D m_newColor4D
the current color4d
bool setHSvaluesFromCursor(const wxPoint &aMouseCursor)
Manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
wxBoxSizer * m_SizerTransparency
void onHSVMouseClick(wxMouseEvent &event) override
wxPoint m_cursorBitmapHSV
the cursor on the HSV bitmap palette.
wxTextCtrl * m_colorValue
void SetEditVals(CHANGED_COLOR aChanged, bool aCheckTransparency)
wxFlexGridSizer * m_fgridColor
void onRGBMouseClick(wxMouseEvent &event) override
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
KIGFX::COLOR4D m_previousColor4D
the initial color4d
void createRGBBitmap()
generate the bitmap that shows the RVB color space
wxBitmap * m_bitmapHSV
the basic HUV palette
void OnChangeEditHue(wxSpinEvent &event) override
Class DIALOG_COLOR_PICKER_BASE.
std::vector< wxStaticBitmap * > m_colorSwatches
list of defined colors buttons
wxStaticBitmap * m_NewColorRect
wxSpinCtrl * m_spinCtrlGreen
void colorDClick(wxMouseEvent &event)
called when creating the dialog
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
void buttColorClick(wxMouseEvent &event)
Event handler for double click on color buttons.
void onRGBMouseDrag(wxMouseEvent &event) override
void OnResetButton(wxCommandEvent &aEvent) override
wxSlider * m_sliderBrightness
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
double m_val
the current value (0 ... 1.0)
KIGFX::COLOR4D m_defaultColor
The default color4d.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxPoint m_cursorBitmapRed
the red cursor on the RGB bitmap palette.
wxSlider * m_sliderTransparency
wxPoint m_cursorBitmapBlue
the blue cursor on the RGB bitmap palette.
wxSpinCtrl * m_spinCtrlHue
void OnChangeEditBlue(wxSpinEvent &event) override
bool TransferDataToWindow() override
void initDefinedColors(CUSTOM_COLORS_LIST *aPredefinedColors)
Create the bitmap buttons for each defined colors.
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
void updatePreview(wxStaticBitmap *aStaticBitmap, KIGFX::COLOR4D &aColor4D)
Event handler from wxSlider: brightness (value) control.
void OnChangeEditRed(wxSpinEvent &event) override
APP_SETTINGS_BASE * KifaceSettings() const
wxBitmap * m_bitmapRGB
the basic RGB palette
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.
COLOR_PICKER m_ColorPicker
void OnChangeEditSat(wxSpinEvent &event) override
mouse handlers, when clicking on a palette bitmap
wxPoint m_cursorBitmapGreen
the green cursor on the RGB bitmap palette.
A color representation with 4 components: red, green, blue, alpha.
wxPoint * m_selectedCursor
the ref cursor to the selected cursor, if any, or null.