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 );
80 if( aColor == COLOR4D::UNSPECIFIED )
84 white = COLOR4D::WHITE;
90 black = COLOR4D::BLACK;
105 black = COLOR4D::BLACK;
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 ),
142 m_background( aBackground ),
143 m_default( aDefault ),
144 m_userColors( nullptr ),
146 m_supportsOpacity( true )
148 wxASSERT_MSG( aSwatchSize !=
SWATCH_EXPAND, wxS(
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
150 switch( aSwatchSize )
161 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
173 const wxSize& aSize,
long aStyle ) :
174 wxPanel( aParent, aID, aPos, aSize, aStyle ),
175 m_userColors( nullptr ),
177 m_supportsOpacity( true )
179 if( aSize == wxDefaultSize )
195 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
208 if(
dynamic_cast<DIALOG_SHIM*
>( wxGetTopLevelParent(
this ) ) )
211 [
this] ( wxMouseEvent& aEvt )
223 [
this] ( wxMouseEvent& aEvt )
228 if( aTriggerWithSingleClick )
231 [
this] ( wxMouseEvent& aEvt )
239 [
this] ( wxMouseEvent& aEvt )
250 wxPostEvent(
this, aEvent );
256 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
260 changeEvt.SetEventObject( &aSender );
262 wxPostEvent( &aSender, changeEvt );
314 if( newColor != COLOR4D::UNSPECIFIED ||
m_default == COLOR4D::UNSPECIFIED )
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)