25#include <wx/dcmemory.h>
41 const wxSize& aSize,
const wxSize& aCheckerboardSize,
42 const COLOR4D& aCheckerboardBackground )
44 wxBitmap bitmap( aSize );
49 iconDC.SelectObject( bitmap );
50 brush.SetStyle( wxBRUSHSTYLE_SOLID );
52 if( aColor == COLOR4D::UNSPECIFIED )
61 white = COLOR4D::WHITE;
67 black = COLOR4D::BLACK;
72 for(
int x = 0; x < aSize.x; x += aCheckerboardSize.x )
74 bool colCycle = rowCycle;
76 for(
int y = 0; y < aSize.y; y += aCheckerboardSize.y )
79 brush.SetColour(
color.ToColour() );
80 pen.SetColour(
color.ToColour() );
82 iconDC.SetBrush( brush );
84 iconDC.DrawRectangle( x, y, x + aCheckerboardSize.x, y + aCheckerboardSize.y );
97 iconDC.SetBrush( brush );
99 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
101 brush.SetColour( aColor.
ToColour() );
104 iconDC.SetBrush( brush );
105 iconDC.SetPen( pen );
106 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
116 wxPanel( aParent, aID ),
118 m_background( aBackground ),
119 m_default( aDefault ),
120 m_userColors( nullptr ),
122 m_supportsOpacity( true )
124 wxASSERT_MSG( aSwatchSize !=
SWATCH_EXPAND, wxS(
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
126 switch( aSwatchSize )
147 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
152 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
161 const wxSize& aSize,
long aStyle ) :
162 wxPanel( aParent, aID, aPos, aSize, aStyle ),
163 m_userColors( nullptr ),
165 m_supportsOpacity( true )
167 if( aSize == wxDefaultSize )
177 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
182 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
192 wxWindow* topLevelParent = GetParent();
194 while( topLevelParent && !topLevelParent->IsTopLevel() )
195 topLevelParent = topLevelParent->GetParent();
197 if( topLevelParent &&
dynamic_cast<DIALOG_SHIM*
>( topLevelParent ) )
200 [
this] ( wxMouseEvent& aEvt )
212 [
this] ( wxMouseEvent& aEvt )
219 [
this] ( wxMouseEvent& aEvt )
230 wxPostEvent(
this, aEvent );
236 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
240 changeEvt.SetEventObject( &aSender );
242 wxPostEvent( &aSender, changeEvt );
291 if( dialog.ShowModal() == wxID_OK )
295 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
KIGFX::COLOR4D m_background
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.
COLOR_SWATCH(wxWindow *aParent, const KIGFX::COLOR4D &aColor, int aID, const KIGFX::COLOR4D &aBackground, const KIGFX::COLOR4D &aDefault, SWATCH_SIZE aSwatchType)
Construct a COLOR_SWATCH.
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
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)