KiCad PCB EDA Suite
COLOR_SWATCH Class Reference

Class representing a simple color swatch, of the kind used to set layer colors. More...

#include <color_swatch.h>

Inheritance diagram for COLOR_SWATCH:

Public Member Functions

 COLOR_SWATCH (wxWindow *aParent, KIGFX::COLOR4D aColor, int aID, bool aArbitraryColors, KIGFX::COLOR4D aBackground)
 Construct a COLOR_SWATCH. More...
 
void SetSwatchColor (KIGFX::COLOR4D aColor, bool sendEvent)
 Set the current swatch color directly. More...
 
void SetSwatchBackground (KIGFX::COLOR4D aBackground)
 Set the swatch background color. More...
 
KIGFX::COLOR4D GetSwatchColor () const
 
void GetNewSwatchColor ()
 Prompt for a new colour, using the colour picker dialog. More...
 

Static Public Member Functions

static wxBitmap MakeBitmap (KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
 Make a simple color swatch bitmap. More...
 

Private Member Functions

void rePostEvent (wxEvent &aEvt)
 Pass unwanted events on to listeners of this object. More...
 

Private Attributes

bool m_arbitraryColors
 

Can the swatch have any color, or only preset ones for legacy canvas?

More...
 
KIGFX::COLOR4D m_color
 

The current colour of the swatch

More...
 
KIGFX::COLOR4D m_background
 

The background colour to show the swatch over

More...
 
wxStaticBitmap * m_swatch
 

Handle of the actual swatch shown

More...
 

Detailed Description

Class representing a simple color swatch, of the kind used to set layer colors.

Definition at line 38 of file color_swatch.h.

Constructor & Destructor Documentation

COLOR_SWATCH::COLOR_SWATCH ( wxWindow *  aParent,
KIGFX::COLOR4D  aColor,
int  aID,
bool  aArbitraryColors,
KIGFX::COLOR4D  aBackground 
)

Construct a COLOR_SWATCH.

Parameters
aParentparent window
aColorinitial swatch color
aIDid to use when sending swatch events
aArbitraryColorstrue to allow selection of any 32 bits color for GAL canvas, and false to allow a selection from a set of colors accepted by the legacy canvas.

Definition at line 82 of file color_swatch.cpp.

References GetNewSwatchColor(), m_background, m_color, m_swatch, makeColorSwatch(), and rePostEvent().

83  :
84  wxPanel( aParent, aID ),
85  m_arbitraryColors( aArbitraryColors ),
86  m_color( aColor ),
87  m_background( aBackground )
88 {
89  auto sizer = new wxBoxSizer( wxHORIZONTAL );
90  SetSizer( sizer );
91 
92  auto swatch = makeColorSwatch( this, m_color, m_background, aID );
93  m_swatch = swatch.release(); // hold a handle
94 
95  sizer->Add( m_swatch, 0, 0 );
96 
97  // forward click to any other listeners, since we don't want them
98  m_swatch->Bind( wxEVT_LEFT_DOWN, &COLOR_SWATCH::rePostEvent, this );
99  m_swatch->Bind( wxEVT_RIGHT_DOWN, &COLOR_SWATCH::rePostEvent, this );
100 
101  // bind the events that trigger the dialog
102  m_swatch->Bind( wxEVT_LEFT_DCLICK, [this] ( wxMouseEvent& aEvt ) {
104  } );
105 
106  m_swatch->Bind( wxEVT_MIDDLE_DOWN, [this] ( wxMouseEvent& aEvt ) {
108  } );
109 }
bool m_arbitraryColors
Can the swatch have any color, or only preset ones for legacy canvas?
Definition: color_swatch.h:86
void rePostEvent(wxEvent &aEvt)
Pass unwanted events on to listeners of this object.
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:92
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:95
static std::unique_ptr< wxStaticBitmap > makeColorSwatch(wxWindow *aParent, COLOR4D aColor, COLOR4D aBackground, int aID)
Function makeColorButton creates a wxStaticBitmap and assigns it a solid color and a control ID...
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:89

Member Function Documentation

void COLOR_SWATCH::GetNewSwatchColor ( )

Prompt for a new colour, using the colour picker dialog.

A colour change event will be sent if it's set.

Definition at line 158 of file color_swatch.cpp.

References DisplayColorFrame(), DIALOG_COLOR_PICKER::GetColor(), m_arbitraryColors, m_background, m_color, m_swatch, MakeBitmap(), sendSwatchChangeEvent(), and SWATCH_SIZE_DU().

Referenced by COLOR_SWATCH(), LAYER_WIDGET::OnRightDownLayer(), and LAYER_WIDGET::OnRightDownRender().

159 {
160  COLOR4D newColor = COLOR4D::UNSPECIFIED;
161 
162  if( m_arbitraryColors )
163  {
164  DIALOG_COLOR_PICKER dialog( ::wxGetTopLevelParent( this ), m_color, true );
165 
166  if( dialog.ShowModal() == wxID_OK )
167  newColor = dialog.GetColor();
168  }
169  else
170  newColor = DisplayColorFrame( this, m_color );
171 
172  if( newColor != COLOR4D::UNSPECIFIED )
173  {
174  m_color = newColor;
175 
176  wxBitmap bm = MakeBitmap( newColor, m_background, ConvertDialogToPixels( SWATCH_SIZE_DU ) );
177  m_swatch->SetBitmap( bm );
178 
179  sendSwatchChangeEvent( *this );
180  }
181 }
COLOR4D DisplayColorFrame(wxWindow *aParent, COLOR4D aOldColor)
bool m_arbitraryColors
Can the swatch have any color, or only preset ones for legacy canvas?
Definition: color_swatch.h:86
static const wxSize SWATCH_SIZE_DU(8, 6)
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:92
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
Make a simple color swatch bitmap.
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:95
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:89
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
COLOR4D COLOR_SWATCH::GetSwatchColor ( ) const
Returns
the current swatch color

Definition at line 152 of file color_swatch.cpp.

References m_color.

Referenced by PCB_LAYER_WIDGET::SyncLayerAlphaIndicators().

153 {
154  return m_color;
155 }
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:89
wxBitmap COLOR_SWATCH::MakeBitmap ( KIGFX::COLOR4D  aColor,
KIGFX::COLOR4D  aBackground,
wxSize  aSize 
)
static

Make a simple color swatch bitmap.

Parameters
aWindow- window used as context for device-independent size

Definition at line 45 of file color_swatch.cpp.

References KIGFX::COLOR4D::WithAlpha().

Referenced by GetNewSwatchColor(), makeColorSwatch(), SetSwatchBackground(), SetSwatchColor(), and ZONE_SETTINGS::SetupLayersList().

46 {
47  wxBitmap bitmap( aSize );
48  wxBrush brush;
49  wxMemoryDC iconDC;
50 
51  iconDC.SelectObject( bitmap );
52 
53  brush.SetStyle( wxBRUSHSTYLE_SOLID );
54  brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
55  iconDC.SetBrush( brush );
56  iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
57 
58  brush.SetColour( aColor.ToColour() );
59  iconDC.SetBrush( brush );
60  iconDC.DrawRectangle( 0, 0, aSize.x, aSize.y );
61 
62  return bitmap;
63 }
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:233
void COLOR_SWATCH::rePostEvent ( wxEvent &  aEvt)
private

Pass unwanted events on to listeners of this object.

Definition at line 112 of file color_swatch.cpp.

Referenced by COLOR_SWATCH().

113 {
114  wxPostEvent( this, aEvt );
115 }
void COLOR_SWATCH::SetSwatchBackground ( KIGFX::COLOR4D  aBackground)

Set the swatch background color.

Definition at line 144 of file color_swatch.cpp.

References m_background, m_color, m_swatch, MakeBitmap(), and SWATCH_SIZE_DU().

Referenced by LAYER_WIDGET::OnRenderSwatchChanged().

145 {
146  m_background = aBackground;
147  wxBitmap bm = MakeBitmap( m_color, m_background, ConvertDialogToPixels( SWATCH_SIZE_DU ) );
148  m_swatch->SetBitmap( bm );
149 }
static const wxSize SWATCH_SIZE_DU(8, 6)
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:92
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
Make a simple color swatch bitmap.
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:95
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:89
void COLOR_SWATCH::SetSwatchColor ( KIGFX::COLOR4D  aColor,
bool  sendEvent 
)

Set the current swatch color directly.

Definition at line 130 of file color_swatch.cpp.

References m_background, m_color, m_swatch, MakeBitmap(), sendSwatchChangeEvent(), and SWATCH_SIZE_DU().

131 {
132  m_color = aColor;
133 
134  wxBitmap bm = MakeBitmap( m_color, m_background, ConvertDialogToPixels( SWATCH_SIZE_DU ) );
135  m_swatch->SetBitmap( bm );
136 
137  if( sendEvent )
138  {
139  sendSwatchChangeEvent( *this );
140  }
141 }
static const wxSize SWATCH_SIZE_DU(8, 6)
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:92
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize)
Make a simple color swatch bitmap.
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:95
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:89

Member Data Documentation

bool COLOR_SWATCH::m_arbitraryColors
private

Can the swatch have any color, or only preset ones for legacy canvas?

Definition at line 86 of file color_swatch.h.

Referenced by GetNewSwatchColor().

KIGFX::COLOR4D COLOR_SWATCH::m_background
private

The background colour to show the swatch over

Definition at line 92 of file color_swatch.h.

Referenced by COLOR_SWATCH(), GetNewSwatchColor(), SetSwatchBackground(), and SetSwatchColor().

KIGFX::COLOR4D COLOR_SWATCH::m_color
private

The current colour of the swatch

Definition at line 89 of file color_swatch.h.

Referenced by COLOR_SWATCH(), GetNewSwatchColor(), GetSwatchColor(), SetSwatchBackground(), and SetSwatchColor().

wxStaticBitmap* COLOR_SWATCH::m_swatch
private

Handle of the actual swatch shown

Definition at line 95 of file color_swatch.h.

Referenced by COLOR_SWATCH(), GetNewSwatchColor(), SetSwatchBackground(), and SetSwatchColor().


The documentation for this class was generated from the following files: