25#include <wx/dcmemory.h>
41 const wxSize& aSize,
const wxSize& aCheckerboardSize,
42 const COLOR4D& aCheckerboardBackground )
44 wxBitmap bitmap( aSize );
47 iconDC.SelectObject( bitmap );
49 RenderToDC( &iconDC, aColor, aBackground, aSize, aCheckerboardSize, aCheckerboardBackground );
57 const wxSize& aCheckerboardSize,
63 brush.SetStyle( wxBRUSHSTYLE_SOLID );
65 if( aColor == COLOR4D::UNSPECIFIED )
74 white = COLOR4D::WHITE;
80 black = COLOR4D::BLACK;
85 for(
int x = aRect.GetLeft(); x < aRect.GetRight(); x += aCheckerboardSize.x )
87 bool colCycle = rowCycle;
89 for(
int y = aRect.GetTop(); y < aRect.GetBottom(); y += aCheckerboardSize.y )
92 brush.SetColour(
color.ToColour() );
93 pen.SetColour(
color.ToColour() );
95 aDC->SetBrush( brush );
97 aDC->DrawRectangle( x, y, aCheckerboardSize.x, aCheckerboardSize.y );
102 rowCycle = !rowCycle;
110 aDC->SetBrush( brush );
112 aDC->DrawRectangle( aRect );
114 brush.SetColour( aColor.
ToColour() );
117 aDC->SetBrush( brush );
119 aDC->DrawRectangle( aRect );
126 SWATCH_SIZE aSwatchSize,
bool aTriggerWithSingleClick ) :
127 wxPanel( aParent, aID ),
129 m_background( aBackground ),
130 m_default( aDefault ),
131 m_userColors( nullptr ),
133 m_supportsOpacity( true )
135 wxASSERT_MSG( aSwatchSize !=
SWATCH_EXPAND, wxS(
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
137 switch( aSwatchSize )
158 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
163 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
172 const wxSize& aSize,
long aStyle ) :
173 wxPanel( aParent, aID, aPos, aSize, aStyle ),
174 m_userColors( nullptr ),
176 m_supportsOpacity( true )
178 if( aSize == wxDefaultSize )
188 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
193 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
203 wxWindow* topLevelParent = wxGetTopLevelParent( GetParent() );
205 if( topLevelParent &&
dynamic_cast<DIALOG_SHIM*
>( topLevelParent ) )
208 [
this] ( wxMouseEvent& aEvt )
220 [
this] ( wxMouseEvent& aEvt )
225 if( aTriggerWithSingleClick )
228 [
this] ( wxMouseEvent& aEvt )
236 [
this] ( wxMouseEvent& aEvt )
247 wxPostEvent(
this, aEvent );
253 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
257 changeEvt.SetEventObject( &aSender );
259 wxPostEvent( &aSender, changeEvt );
308 if( dialog.ShowModal() == wxID_OK )
312 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...
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
A color representation with 4 components: red, green, blue, alpha.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given 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)
COLOR4D DisplayColorFrame(wxWindow *aParent, COLOR4D aOldColor)
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)