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 ) );
 
 
  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__ ) && !wxCHECK_VERSION( 3, 3, 0 ) 
  429    bitmapDC.SetDeviceOrigin( half_size, -half_size );
 
  431    bitmapDC.SetDeviceOrigin( half_size, half_size );
 
  438    wxPen pen( wxColor( 255, 255, 255 ), 2 );       
 
  439    wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
 
  440    bitmapDC.SetPen( pen );
 
  441    bitmapDC.SetBrush( brush );
 
  470    half_size += half_size/5;
 
  471    bitmapDC.DrawLine( 0, 0, 0, half_size );                    
 
  472    bitmapDC.DrawLine( 0, 0, half_size, - half_size*slope );    
 
  473    bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope );   
 
  475    newBm.SetScaleFactor( GetDPIScaleFactor() );
 
  480    bitmapDC.SelectObject( wxNullBitmap );
 
 
  491    int        half_size = std::min( bmsize.x, bmsize.y ) / 2;
 
  494    newBm.SetScaleFactor( 1.0 );
 
  496    bitmapDC.SelectObject( newBm );
 
  499    bitmapDC.SetAxisOrientation( 
true, 
true );
 
  500#if defined( __WXMSW__ ) && !wxCHECK_VERSION(3,3,0) 
  503    bitmapDC.SetDeviceOrigin( half_size, -half_size );
 
  505    bitmapDC.SetDeviceOrigin( half_size, half_size );
 
  515    wxPen pen( wxColor( 0, 0, 0 ), 2 );     
 
  516    wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT );
 
  517    bitmapDC.SetPen( pen );
 
  518    bitmapDC.SetBrush( brush );
 
  524    newBm.SetScaleFactor( GetDPIScaleFactor() );
 
  530    bitmapDC.SelectObject( wxNullBitmap );
 
 
  536    if( aCheckTransparency )
 
 
  600    wxPostEvent( 
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
 
 
  606    int id = 
event.GetId();
 
 
  627    wxPoint mousePos = ToPhys( event.GetPosition() );
 
  629    int     half_size = std::min( bmsize.x, bmsize.y ) / 2;
 
  631    mousePos.x -= half_size;
 
  632    mousePos.y -= half_size;
 
  633    mousePos.y = -mousePos.y;       
 
 
  680    wxPoint mousePos = ToPhys( event.GetPosition() );
 
  682    int     half_size = std::min( bmsize.x, bmsize.y ) / 2;
 
  684    mousePos.x -= half_size;
 
  685    mousePos.y -= half_size;
 
  686    mousePos.y = -mousePos.y;           
 
  693        if( mousePos.y >= 0 && mousePos.y <= half_size )
 
  701        mousePos.x = -mousePos.x;
 
  703        if( mousePos.x >= 0 && mousePos.x <= half_size )
 
  711        if( mousePos.x >= 0 && mousePos.x <= half_size )
 
 
  765    wxPoint mousePos = ToPhys( aMouseCursor );
 
  767    int     half_size = std::min( bmsize.x, bmsize.y ) / 2;
 
  770    mousePos.x -= half_size;
 
  771    mousePos.y -= half_size;
 
  772    mousePos.y = -mousePos.y;   
 
  775    double dist_from_centre = hypot( (
double)mousePos.x, (
double)mousePos.y );
 
  777    if( dist_from_centre > half_size )
 
  787    m_sat = dist_from_centre / half_size;
 
  792    m_hue = atan2( mousePos.y, mousePos.x ) / 
M_PI * 180.0;
 
 
  806    double alpha = (double)event.GetPosition() / 
ALPHA_MAX;
 
 
  818    double val = (double)event.GetPosition() / 255.0;
 
 
  828    double val = (double)event.GetPosition() / 255.0;
 
 
  838    double val = (double)event.GetPosition() / 255.0;
 
 
  848    m_hue = (double)event.GetPosition();
 
 
  860    m_sat = (double)event.GetPosition() / 255.0;
 
 
  872    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 const COLOR4D WHITE
 
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
 
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
 
DIALOG_COLOR_PICKER_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Color Picker"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
 
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.
 
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.