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 = 6;
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,
190 if( aPredefinedColors )
192 for(
unsigned jj = 0; jj < aPredefinedColors->size() && jj <
NBCOLORS; ++jj )
205 for(
int jj = 0; jj <
NBCOLORS; ++jj, grid_col++ )
207 if( grid_col*table_row_count >=
NBCOLORS )
213 int ii = grid_row + (grid_col*table_row_count);
217 addSwatch( butt_ID, buttcolor, wxGetTranslation(
colorRefs()[ii].m_ColorName ) );
228 int half_size = std::min( bmsize.x, bmsize.y )/2;
234 wxBrush bgbrush( GetBackgroundColour() );
235 bitmapDC.SetBackground( bgbrush );
239 bitmapDC.SetAxisOrientation(
true,
true );
240 bitmapDC.SetDeviceOrigin( half_size, half_size );
248 double inc = 1.0 / half_size;
249 #define SLOPE_AXIS 50.0 253 for(
int xx = 0; xx < half_size; xx++ )
257 for(
int yy = 0; yy < half_size; yy++ )
261 pen.SetColour(
color.ToColour() );
262 bitmapDC.SetPen( pen );
263 bitmapDC.DrawPoint( xx, yy - (slope*xx) );
269 for(
int xx = 0; xx < half_size; xx++ )
273 for(
int yy = 0; yy < half_size; yy++ )
277 pen.SetColour(
color.ToColour() );
278 bitmapDC.SetPen( pen );
279 bitmapDC.DrawPoint( -xx, yy - (slope*xx) );
285 for(
int xx = 0; xx < half_size; xx++ )
289 for(
int yy = 0; yy < half_size; yy++ )
293 pen.SetColour(
color.ToColour() );
294 bitmapDC.SetPen( pen );
300 int drawX = -xx + yy;
301 int drawY = - std::min( xx,yy ) * 0.9;
302 bitmapDC.DrawPoint( drawX, drawY - std::abs( slope*drawX ) );
312 int half_size = std::min( bmsize.x, bmsize.y )/2;
319 wxBrush bgbrush( GetBackgroundColour() );
320 bitmapDC.SetBackground( bgbrush );
324 bitmapDC.SetAxisOrientation(
true,
true );
325 bitmapDC.SetDeviceOrigin( half_size, half_size );
332 int sq_radius = half_size*half_size;
334 for(
int xx = -half_size; xx < half_size; xx++ )
336 for(
int yy = -half_size; yy < half_size; yy++ )
338 sat = double(xx*xx + yy*yy) / sq_radius;
347 hue = atan2( (
double)yy, (
double)xx ) * 180 / M_PI;
352 color.FromHSV( hue, sat, 1.0 );
354 pen.SetColour(
color.ToColour() );
355 bitmapDC.SetPen( pen );
356 bitmapDC.DrawPoint( xx, yy );
363 bitmapDC.SelectObject( wxNullBitmap );
374 int half_size = std::min( bmsize.x, bmsize.y )/2;
376 bitmapDC.SelectObject( newBm );
379 bitmapDC.SetAxisOrientation(
true,
true );
380 bitmapDC.SetDeviceOrigin( half_size, half_size );
386 wxPen pen( wxColor( 255, 255, 255 ) );
387 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
388 bitmapDC.SetPen( pen );
389 bitmapDC.SetBrush( brush );
392 #define SLOPE_AXIS 50.0 419 half_size += half_size/5;
420 bitmapDC.DrawLine( 0, 0, 0, half_size );
421 bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );
422 bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );
427 bitmapDC.SelectObject( wxNullBitmap );
438 int half_size = std::min( bmsize.x, bmsize.y )/2;
440 bitmapDC.SelectObject( newBm );
443 bitmapDC.SetAxisOrientation(
true,
true );
444 bitmapDC.SetDeviceOrigin( half_size, half_size );
453 wxPen pen( wxColor( 0, 0, 0 ) );
454 wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
455 bitmapDC.SetPen( pen );
456 bitmapDC.SetBrush( brush );
467 bitmapDC.SelectObject( wxNullBitmap );
473 if( aCheckTransparency )
528 int id =
event.GetId();
547 wxPoint mousePos =
event.GetPosition();
551 int half_size = std::min( bmsize.x, bmsize.y )/2;
552 mousePos.x -= half_size;
553 mousePos.y -= half_size;
554 mousePos.y = -mousePos.y;
599 wxPoint mousePos =
event.GetPosition();
601 int half_size = std::min( bmsize.x, bmsize.y )/2;
602 mousePos.x -= half_size;
603 mousePos.y -= half_size;
604 mousePos.y = -mousePos.y;
611 if( mousePos.y >= 0 && mousePos.y <= half_size )
619 mousePos.x = -mousePos.x;
621 if( mousePos.x >= 0 && mousePos.x <= half_size )
629 if( mousePos.x >= 0 && mousePos.x <= half_size )
673 wxPoint mousePos = aMouseCursor;
675 int half_size = std::min( bmsize.x, bmsize.y )/2;
677 mousePos.x -= half_size;
678 mousePos.y -= half_size;
679 mousePos.y = -mousePos.y;
682 double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
684 if( dist_from_centre > half_size )
692 m_sat = dist_from_centre / half_size;
697 m_hue = atan2( mousePos.y, mousePos.x ) / M_PI * 180.0;
711 double alpha = (double)event.GetPosition() /
ALPHA_MAX;
722 double val = (double)event.GetPosition() / 255.0;
732 double val = (double)event.GetPosition() / 255.0;
742 double val = (double)event.GetPosition() / 255.0;
752 m_hue = (double)event.GetPosition();
764 m_sat = (double)event.GetPosition() / 255.0;
776 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
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.
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize, wxSize aCheckerboardSize, KIGFX::COLOR4D aCheckerboardBackground)
Make a simple color swatch bitmap.
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
APP_SETTINGS_BASE * KifaceSettings() const
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
bool setHSvaluesFromCursor(wxPoint aMouseCursor)
Manage the Hue and Saturation settings when the mouse cursor is at aMouseCursor.
void OnChangeBrightness(wxScrollEvent &event) override
Event handler from wxSlider: alpha (transparency) control.
KIGFX::COLOR4D m_newColor4D
the current color4d
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
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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
const StructColors * colorRefs()
Global list of legacy color names, still used all over the place for constructing COLOR4D's.
void buttColorClick(wxMouseEvent &event)
called when creating the dialog
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
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.