25#include <wx/dcmemory.h>
40 const wxSize& aSize,
const wxSize& aCheckerboardSize,
41 const COLOR4D& aCheckerboardBackground )
43 wxBitmap bitmap( aSize );
48 iconDC.SelectObject( bitmap );
49 brush.SetStyle( wxBRUSHSTYLE_SOLID );
51 if( aColor == COLOR4D::UNSPECIFIED )
71 for(
int x = 0; x < aSize.x; x += aCheckerboardSize.x )
73 bool colCycle = rowCycle;
75 for(
int y = 0; y < aSize.y; y += aCheckerboardSize.y )
78 brush.SetColour(
color.ToColour() );
79 pen.SetColour(
color.ToColour() );
81 iconDC.SetBrush( brush );
83 iconDC.DrawRectangle( x, y, x + aCheckerboardSize.x, y + aCheckerboardSize.y );
93 brush.SetColour( aBackground.
WithAlpha(1.0).ToColour() );
94 pen.SetColour( aBackground.
WithAlpha(1.0).ToColour() );
96 iconDC.SetBrush( brush );
98 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
100 brush.SetColour( aColor.ToColour() );
101 pen.SetColour( aColor.ToColour() );
103 iconDC.SetBrush( brush );
104 iconDC.SetPen( pen );
105 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
115 wxPanel( aParent, aID ),
117 m_background( aBackground ),
118 m_default( aDefault ),
119 m_userColors( nullptr ),
121 m_supportsOpacity( true )
123 wxASSERT_MSG( aSwatchSize !=
SWATCH_EXPAND, wxS(
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
125 switch( aSwatchSize )
136 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
141 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
150 const wxSize& aSize,
long aStyle ) :
151 wxPanel( aParent, aID, aPos, aSize, aStyle ),
152 m_userColors( nullptr ),
154 m_supportsOpacity( true )
156 if( aSize == wxDefaultSize )
166 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
171 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
181 wxWindow* topLevelParent = GetParent();
183 while( topLevelParent && !topLevelParent->IsTopLevel() )
184 topLevelParent = topLevelParent->GetParent();
186 if( topLevelParent &&
dynamic_cast<DIALOG_SHIM*
>( topLevelParent ) )
189 [
this] ( wxMouseEvent& aEvt )
201 [
this] ( wxMouseEvent& aEvt )
208 [
this] ( wxMouseEvent& aEvt )
219 wxPostEvent(
this, aEvent );
225 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
229 changeEvt.SetEventObject( &aSender );
231 wxPostEvent( &aSender, changeEvt );
280 if( dialog.ShowModal() == wxID_OK )
284 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...
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.
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)