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...
 

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 81 of file color_swatch.cpp.

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

82  :
83  wxPanel( aParent, aID ),
84  m_arbitraryColors( aArbitraryColors ),
85  m_color( aColor ),
86  m_background( aBackground )
87 {
88  auto sizer = new wxBoxSizer( wxHORIZONTAL );
89  SetSizer( sizer );
90 
91  auto swatch = makeColorSwatch( this, m_color, m_background, aID );
92  m_swatch = swatch.release(); // hold a handle
93 
94  sizer->Add( m_swatch, 0, 0 );
95 
96  // forward click to any other listeners, since we don't want them
97  m_swatch->Bind( wxEVT_LEFT_DOWN, &COLOR_SWATCH::rePostEvent, this );
98  m_swatch->Bind( wxEVT_RIGHT_DOWN, &COLOR_SWATCH::rePostEvent, this );
99 
100  // bind the events that trigger the dialog
101  m_swatch->Bind( wxEVT_LEFT_DCLICK, [this] ( wxMouseEvent& aEvt ) {
103  } );
104 
105  m_swatch->Bind( wxEVT_MIDDLE_DOWN, [this] ( wxMouseEvent& aEvt ) {
107  } );
108 }
bool m_arbitraryColors
Can the swatch have any color, or only preset ones for legacy canvas?
Definition: color_swatch.h:84
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:90
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:93
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:87

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 157 of file color_swatch.cpp.

References DisplayColorFrame(), COLOR4D_PICKER_DLG::GetColor(), m_arbitraryColors, m_background, m_color, m_swatch, makeBitmap(), and sendSwatchChangeEvent().

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

158 {
159  COLOR4D newColor = COLOR4D::UNSPECIFIED;
160 
161  if( m_arbitraryColors )
162  {
163  COLOR4D_PICKER_DLG dialog( this, m_color, true );
164 
165  if( dialog.ShowModal() == wxID_OK )
166  newColor = dialog.GetColor();
167  }
168  else
169  newColor = DisplayColorFrame( this, m_color );
170 
171  if( newColor != COLOR4D::UNSPECIFIED )
172  {
173  m_color = newColor;
174 
175  wxBitmap bm = makeBitmap( newColor, m_background, (wxWindow*) this );
176  m_swatch->SetBitmap( bm );
177 
178  sendSwatchChangeEvent( *this );
179  }
180 }
COLOR4D DisplayColorFrame(wxWindow *aParent, COLOR4D aOldColor)
static wxBitmap makeBitmap(COLOR4D aColor, COLOR4D aBackground, wxWindow *aWindow)
Make a simple color swatch bitmap.
bool m_arbitraryColors
Can the swatch have any color, or only preset ones for legacy canvas?
Definition: color_swatch.h:84
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:90
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:93
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:87
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 151 of file color_swatch.cpp.

References m_color.

152 {
153  return m_color;
154 }
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:87
void COLOR_SWATCH::rePostEvent ( wxEvent &  aEvt)
private

Pass unwanted events on to listeners of this object.

Definition at line 111 of file color_swatch.cpp.

Referenced by COLOR_SWATCH().

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

Set the swatch background color.

Definition at line 143 of file color_swatch.cpp.

References m_background, m_color, m_swatch, and makeBitmap().

Referenced by LAYER_WIDGET::OnRenderSwatchChanged().

144 {
145  m_background = aBackground;
146  wxBitmap bm = makeBitmap( m_color, m_background, (wxWindow*) this );
147  m_swatch->SetBitmap( bm );
148 }
static wxBitmap makeBitmap(COLOR4D aColor, COLOR4D aBackground, wxWindow *aWindow)
Make a simple color swatch bitmap.
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:90
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:93
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:87
void COLOR_SWATCH::SetSwatchColor ( KIGFX::COLOR4D  aColor,
bool  sendEvent 
)

Set the current swatch color directly.

Definition at line 129 of file color_swatch.cpp.

References m_background, m_color, m_swatch, makeBitmap(), and sendSwatchChangeEvent().

130 {
131  m_color = aColor;
132 
133  wxBitmap bm = makeBitmap( m_color, m_background, GetParent() );
134  m_swatch->SetBitmap( bm );
135 
136  if( sendEvent )
137  {
138  sendSwatchChangeEvent( *this );
139  }
140 }
static wxBitmap makeBitmap(COLOR4D aColor, COLOR4D aBackground, wxWindow *aWindow)
Make a simple color swatch bitmap.
KIGFX::COLOR4D m_background
The background colour to show the swatch over
Definition: color_swatch.h:90
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:93
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:87

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 84 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 90 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 87 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 93 of file color_swatch.h.

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


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