25 #include <wx/dcmemory.h> 45 wxSize aCheckerboardSize,
COLOR4D aCheckerboardBackground )
47 wxBitmap bitmap( aSize );
52 iconDC.SelectObject( bitmap );
53 brush.SetStyle( wxBRUSHSTYLE_SOLID );
55 if( aColor == COLOR4D::UNSPECIFIED )
75 for(
int x = 0; x < aSize.x; x += aCheckerboardSize.x )
77 bool colCycle = rowCycle;
79 for(
int y = 0; y < aSize.y; y += aCheckerboardSize.y )
82 brush.SetColour(
color.ToColour() );
83 pen.SetColour(
color.ToColour() );
85 iconDC.SetBrush( brush );
87 iconDC.DrawRectangle( x, y, x + aCheckerboardSize.x, y + aCheckerboardSize.y );
97 brush.SetColour( aBackground.
WithAlpha(1.0).ToColour() );
98 pen.SetColour( aBackground.
WithAlpha(1.0).ToColour() );
100 iconDC.SetBrush( brush );
101 iconDC.SetPen( pen );
102 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
104 brush.SetColour( aColor.ToColour() );
105 pen.SetColour( aColor.ToColour() );
107 iconDC.SetBrush( brush );
108 iconDC.SetPen( pen );
109 iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
118 wxPanel( aParent, aID ),
120 m_background( aBackground ),
121 m_default( aDefault ),
124 wxASSERT_MSG( aSwatchSize !=
SWATCH_EXPAND,
"SWATCH_EXPAND not supported in COLOR_SWATCH" );
126 switch( aSwatchSize )
137 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
142 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
151 const wxSize &aSize,
long aStyle ) :
152 wxPanel( aParent, aID, aPos, aSize, aStyle ),
155 if( aSize == wxDefaultSize )
165 auto sizer =
new wxBoxSizer( wxHORIZONTAL );
170 m_swatch =
new wxStaticBitmap(
this, aID, bitmap );
180 wxWindow* topLevelParent = GetParent();
182 while( topLevelParent && !topLevelParent->IsTopLevel() )
183 topLevelParent = topLevelParent->GetParent();
185 if( topLevelParent && dynamic_cast<DIALOG_SHIM*>( topLevelParent ) )
188 [
this] ( wxMouseEvent& aEvt )
200 [
this] ( wxMouseEvent& aEvt )
207 [
this] ( wxMouseEvent& aEvt )
218 wxPostEvent(
this, aEvent );
224 wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED );
228 changeEvt.SetEventObject( &aSender );
230 wxPostEvent( &aSender, changeEvt );
278 if( dialog.ShowModal() == wxID_OK )
282 if( newColor != COLOR4D::UNSPECIFIED ||
m_default == COLOR4D::UNSPECIFIED )
void SetSwatchColor(KIGFX::COLOR4D aColor, bool aSendEvent)
Set the current swatch color directly.
COLOR4D DisplayColorFrame(wxWindow *aParent, COLOR4D aOldColor)
KIGFX::COLOR4D GetSwatchColor() const
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
COLOR_SWATCH(wxWindow *aParent, KIGFX::COLOR4D aColor, int aID, KIGFX::COLOR4D aBackground, const KIGFX::COLOR4D aDefault, SWATCH_SIZE aSwatchType)
Construct a COLOR_SWATCH.
void SetDefaultColor(KIGFX::COLOR4D aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize, wxSize aCheckerboardSize, KIGFX::COLOR4D aCheckerboardBackground)
Make a simple color swatch bitmap.
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
void SetSwatchBackground(KIGFX::COLOR4D aBackground)
Set the swatch background color.
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
wxSize m_checkerboardSize
KIGFX::COLOR4D m_background
static const wxSize SWATCH_SIZE_MEDIUM_DU(24, 10)
std::function< void()> m_readOnlyCallback
wxStaticBitmap * m_swatch
wxDEFINE_EVENT(COLOR_SWATCH_CHANGED, wxCommandEvent)
KIGFX::COLOR4D m_checkerboardBg
bool m_readOnly
A read-only swatch won't show the color chooser dialog but otherwise works normally.
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
void rePostEvent(wxEvent &aEvent)
Pass unwanted events on to listeners of this object.
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
KIGFX::COLOR4D GetColor()
Class representing a simple color swatch, of the kind used to set layer colors.
static const wxSize SWATCH_SIZE_SMALL_DU(8, 6)
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
A color representation with 4 components: red, green, blue, alpha.