26#include <wx/dcmemory.h> 
   38                                   const wxSize& aSize, 
const wxSize& aCheckerboardSize,
 
   39                                   const COLOR4D& aCheckerboardBackground )
 
   41    wxBitmap   bitmap( aSize );
 
   44    iconDC.SelectObject( bitmap );
 
   46    RenderToDC( &iconDC, aColor, aBackground, aSize, aCheckerboardSize, aCheckerboardBackground );
 
 
   58    bitmap.SetScaleFactor( GetDPIScaleFactor() );
 
 
   65                               const wxSize&         aCheckerboardSize,
 
   71    brush.SetStyle( wxBRUSHSTYLE_SOLID );
 
   73    aDC->SetPen( *wxTRANSPARENT_PEN );
 
  111    for( 
int x = aRect.GetLeft(); x <= aRect.GetRight(); x += aCheckerboardSize.x )
 
  113        bool colCycle = rowCycle;
 
  115        for( 
int y = aRect.GetTop(); y <= aRect.GetBottom(); y += aCheckerboardSize.y )
 
  120            unsigned char r = wxColor::AlphaBlend( fg.Red(), bg.Red(), aColor.
a );
 
  121            unsigned char g = wxColor::AlphaBlend( fg.Green(), bg.Green(), aColor.
a );
 
  122            unsigned char b = wxColor::AlphaBlend( fg.Blue(), bg.Blue(), aColor.
a );
 
  124            brush.SetColour( r, g, b );
 
  126            aDC->SetBrush( brush );
 
  127            aDC->DrawRectangle( x, y, aCheckerboardSize.x, aCheckerboardSize.y );
 
  129            colCycle = !colCycle;
 
  132        rowCycle = !rowCycle;
 
 
  139                            SWATCH_SIZE aSwatchSize, 
bool aTriggerWithSingleClick ) :
 
  140        wxPanel( aParent, aID ),
 
  149                  wxS( 
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
 
  151    switch( aSwatchSize )
 
  162    auto sizer = 
new wxBoxSizer( wxHORIZONTAL );
 
 
  174                            const wxSize& aSize, 
long aStyle ) :
 
  175        wxPanel( aParent, aID, aPos, aSize, aStyle ),
 
  180    if( aSize == wxDefaultSize )
 
  196    auto sizer = 
new wxBoxSizer( wxHORIZONTAL );
 
 
  209    if( 
dynamic_cast<DIALOG_SHIM*
>( wxGetTopLevelParent( 
this ) ) )
 
  212                        [
this] ( wxMouseEvent& aEvt )
 
  224                        [
this] ( wxMouseEvent& aEvt )
 
  229        if( aTriggerWithSingleClick )
 
  232                        [
this] ( wxMouseEvent& aEvt )
 
  240                    [
this] ( wxMouseEvent& aEvt )
 
 
  251    wxPostEvent( 
this, aEvent );
 
 
  257    wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
 
  261    changeEvt.SetEventObject( &aSender );
 
  263    wxPostEvent( &aSender, changeEvt );
 
 
  329    wxWindow* parent = GetParent();
 
  330    m_checkerboardBg = parent ? parent->GetBackgroundColour() : wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
 
 
static const COLOR4D WHITE
 
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
 
static const COLOR4D BLACK
 
A simple color swatch of the kind used to set layer colors.
 
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
 
wxSize m_checkerboardSize
 
KIGFX::COLOR4D m_checkerboardBg
 
bool m_supportsOpacity
If opacity is not supported the color chooser dialog will be displayed without it.
 
wxStaticBitmap * m_swatch
 
void OnDarkModeToggle()
Respond to a change in the OS's DarkMode setting.
 
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
 
bool m_readOnly
A read-only swatch won't show the color chooser dialog but otherwise works normally.
 
KIGFX::COLOR4D GetSwatchColor() const
 
COLOR_SWATCH(wxWindow *aParent, const KIGFX::COLOR4D &aColor, int aID, const KIGFX::COLOR4D &aBackground, const KIGFX::COLOR4D &aDefault, SWATCH_SIZE aSwatchType, bool aTriggerWithSingleClick=false)
Construct a COLOR_SWATCH.
 
KIGFX::COLOR4D m_background
 
static void RenderToDC(wxDC *aDC, const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxRect &aRect, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
 
void setupEvents(bool aTriggerWithSingleClick)
 
std::function< void()> m_readOnlyCallback
 
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
 
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
 
CUSTOM_COLORS_LIST * m_userColors
 
void rePostEvent(wxEvent &aEvent)
Pass unwanted events on to listeners of this object.
 
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
 
KIGFX::COLOR4D GetColor()
 
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
 
A color representation with 4 components: red, green, blue, alpha.
 
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
 
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
 
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
 
wxColour ToColour() const
 
wxDEFINE_EVENT(COLOR_SWATCH_CHANGED, wxCommandEvent)
 
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
 
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
 
static const wxSize SWATCH_SIZE_MEDIUM_DU(24, 10)
 
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
 
static const wxSize SWATCH_SIZE_SMALL_DU(8, 6)