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)
 Construct a COLOR_SWATCH. More...
 
void SetSwatchColor (KIGFX::COLOR4D aColor, bool sendEvent)
 Set the current swatch color directly. 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...
 
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 
)

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

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

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

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

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

Referenced by COLOR_SWATCH().

146 {
147  COLOR4D newColor = COLOR4D::UNSPECIFIED;
148 
149  if( m_arbitraryColors )
150  {
151  COLOR4D_PICKER_DLG dialog( this, m_color, true );
152 
153  if( dialog.ShowModal() == wxID_OK )
154  newColor = dialog.GetColor();
155  }
156  else
157  newColor = DisplayColorFrame( this, m_color );
158 
159  if( newColor != COLOR4D::UNSPECIFIED )
160  {
161  m_color = newColor;
162 
163  wxBitmap bm = makeBitmap( newColor );
164  m_swatch->SetBitmap( bm );
165 
166  sendSwatchChangeEvent( *this );
167  }
168 }
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:79
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:85
static wxBitmap makeBitmap(COLOR4D aColor)
Make a simple color swatch bitmap.
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:82
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 139 of file color_swatch.cpp.

References m_color.

140 {
141  return m_color;
142 }
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:82
void COLOR_SWATCH::rePostEvent ( wxEvent &  aEvt)
private

Pass unwanted events on to listeners of this object.

Definition at line 107 of file color_swatch.cpp.

Referenced by COLOR_SWATCH().

108 {
109  wxPostEvent( this, aEvt );
110 }
void COLOR_SWATCH::SetSwatchColor ( KIGFX::COLOR4D  aColor,
bool  sendEvent 
)

Set the current swatch color directly.

Definition at line 125 of file color_swatch.cpp.

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

126 {
127  m_color = aColor;
128 
129  wxBitmap bm = makeBitmap( aColor );
130  m_swatch->SetBitmap( bm );
131 
132  if( sendEvent )
133  {
134  sendSwatchChangeEvent( *this );
135  }
136 }
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:85
static wxBitmap makeBitmap(COLOR4D aColor)
Make a simple color swatch bitmap.
static void sendSwatchChangeEvent(COLOR_SWATCH &aSender)
KIGFX::COLOR4D m_color
The current colour of the swatch
Definition: color_swatch.h:82

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 79 of file color_swatch.h.

Referenced by GetNewSwatchColor().

KIGFX::COLOR4D COLOR_SWATCH::m_color
private

The current colour of the swatch

Definition at line 82 of file color_swatch.h.

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

wxStaticBitmap* COLOR_SWATCH::m_swatch
private

Handle of the actual swatch shown

Definition at line 85 of file color_swatch.h.

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


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