22#include <wx/dcmemory.h>
23#include <wx/weakref.h>
35 const wxSize& aCheckerboardSize,
const COLOR4D& aCheckerboardBackground,
36 const std::vector<int>& aMargins )
38 wxBitmap bitmap( aSize );
41 iconDC.SelectObject( bitmap );
43 RenderToDC( &iconDC, aColor, aBackground, aSize, aCheckerboardSize, aCheckerboardBackground, aMargins );
54 bitmap.SetScaleFactor( GetDPIScaleFactor() );
60 const wxRect& aRect,
const wxSize& aCheckerboardSize,
61 const KIGFX::COLOR4D& aCheckerboardBackground,
const std::vector<int>& aMargins )
66 brush.SetStyle( wxBRUSHSTYLE_SOLID );
68 aDC->SetPen( *wxTRANSPARENT_PEN );
106 for(
int x = aRect.GetLeft(); x <= aRect.GetRight(); x += aCheckerboardSize.x )
108 bool colCycle = rowCycle;
110 for(
int y = aRect.GetTop(); y <= aRect.GetBottom(); y += aCheckerboardSize.y )
115 double alpha = (double)fg.Alpha() / 255.0;
116 unsigned char r = wxColor::AlphaBlend( fg.Red(), bg.Red(), alpha );
117 unsigned char g = wxColor::AlphaBlend( fg.Green(), bg.Green(), alpha );
118 unsigned char b = wxColor::AlphaBlend( fg.Blue(), bg.Blue(), alpha );
120 brush.SetColour( r, g, b );
122 aDC->SetBrush( brush );
123 aDC->DrawRectangle( x, y, aCheckerboardSize.x, aCheckerboardSize.y );
125 colCycle = !colCycle;
128 rowCycle = !rowCycle;
131 aDC->SetBrush( *wxWHITE_BRUSH );
134 aDC->DrawRectangle( 0, 0, aMargins[0], aRect.GetHeight() );
137 aDC->DrawRectangle( 0, 0, aRect.GetWidth(), aMargins[1] );
140 aDC->DrawRectangle( aRect.GetWidth() - aMargins[2], 0, aMargins[2], aRect.GetHeight() );
143 aDC->DrawRectangle( 0, aRect.GetHeight() - aMargins[3], aRect.GetWidth(), aMargins[3] );
149 wxPanel( aParent, aID ),
158 wxS(
"SWATCH_EXPAND not supported in COLOR_SWATCH" ) );
160 switch( aSwatchSize )
171 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
184 wxPanel( aParent, aID, aPos, aSize, aStyle ),
189 if( aSize == wxDefaultSize )
205 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
218 if(
dynamic_cast<DIALOG_SHIM*
>( wxGetTopLevelParent(
this ) ) )
230 if( aTriggerWithSingleClick )
244 wxPostEvent(
this, aEvent );
256 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED, aSender.GetId() );
260 changeEvt.SetEventObject( &aSender );
262 wxPostEvent( &aSender, changeEvt );
310 wxWeakRef<COLOR_SWATCH> self(
this );
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
static void RenderToDC(wxDC *aDC, const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxRect &aRect, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground, const std::vector< int > &aMargins={ 0, 0, 0, 0 })
void OnDarkModeToggle()
Respond to a change in the OS's DarkMode setting.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground, const std::vector< int > &aMargins={ 0, 0, 0, 0 })
bool m_readOnly
A read-only swatch won't show the color chooser dialog but otherwise works normally.
KIGFX::COLOR4D GetSwatchColor() const
void onMouseEvent(wxEvent &aEvent)
Handle mouse events on the swatch, and trigger the color picker dialog if appropriate.
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
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.
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.
std::shared_ptr< wxString > m_text
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)
wxString result
Test unit parsing edge cases and error handling.