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?

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

Definition at line 80 of file color_swatch.cpp.

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

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

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

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

Referenced by COLOR_SWATCH().

148 {
149  COLOR4D newColor = COLOR4D::UNSPECIFIED;
150 
151  if( m_arbitraryColors )
152  {
153  wxColourData colourData;
154  colourData.SetColour( m_color.ToColour() );
155  wxColourDialog dialog( this, &colourData );
156 
157  if( dialog.ShowModal() == wxID_OK )
158  {
159  newColor = COLOR4D( dialog.GetColourData().GetColour() );
160  }
161  }
162  else
163  {
164  newColor = DisplayColorFrame( this, m_color );
165  }
166 
167  if( newColor != COLOR4D::UNSPECIFIED )
168  {
169  m_color = newColor;
170 
171  wxBitmap bm = makeBitmap( newColor );
172  m_swatch->SetBitmap( bm );
173 
174  sendSwatchChangeEvent( *this );
175  }
176 }
COLOR4D DisplayColorFrame(wxWindow *aParent, COLOR4D aOldColor)
bool m_arbitraryColors
Can the swatch have any color, or only preset ones?
Definition: color_swatch.h:77
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:83
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:80
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 141 of file color_swatch.cpp.

References m_color.

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

Pass unwanted events on to listeners of this object.

Definition at line 109 of file color_swatch.cpp.

Referenced by COLOR_SWATCH().

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

Set the current swatch color directly.

Definition at line 127 of file color_swatch.cpp.

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

128 {
129  m_color = aColor;
130 
131  wxBitmap bm = makeBitmap( aColor );
132  m_swatch->SetBitmap( bm );
133 
134  if( sendEvent )
135  {
136  sendSwatchChangeEvent( *this );
137  }
138 }
wxStaticBitmap * m_swatch
Handle of the actual swatch shown
Definition: color_swatch.h:83
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:80

Member Data Documentation

bool COLOR_SWATCH::m_arbitraryColors
private

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

Definition at line 77 of file color_swatch.h.

Referenced by GetNewSwatchColor().

KIGFX::COLOR4D COLOR_SWATCH::m_color
private

The current colour of the swatch

Definition at line 80 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 83 of file color_swatch.h.

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


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