KiCad PCB EDA Suite
color_swatch.cpp File Reference
#include <widgets/color_swatch.h>
#include <wx/colour.h>
#include <wx/colordlg.h>
#include <memory>

Go to the source code of this file.

Functions

 wxDEFINE_EVENT (COLOR_SWATCH_CHANGED, wxCommandEvent)
 
COLOR4D DisplayColorFrame (wxWindow *aParent, COLOR4D aOldColor)
 
static wxBitmap makeBitmap (COLOR4D aColor)
 Make a simple color swatch bitmap. More...
 
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. More...
 
static void sendSwatchChangeEvent (COLOR_SWATCH &aSender)
 

Variables

static const int SWATCH_SIZE_X = 14
 
static const int SWATCH_SIZE_Y = 12
 

Function Documentation

COLOR4D DisplayColorFrame ( wxWindow *  aParent,
COLOR4D  aOldColor 
)
static wxBitmap makeBitmap ( COLOR4D  aColor)
static

Make a simple color swatch bitmap.

Definition at line 46 of file color_swatch.cpp.

References SWATCH_SIZE_X, and SWATCH_SIZE_Y.

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

47 {
48  wxBitmap bitmap( SWATCH_SIZE_X, SWATCH_SIZE_Y );
49  wxBrush brush;
50  wxMemoryDC iconDC;
51 
52  iconDC.SelectObject( bitmap );
53 
54  brush.SetColour( aColor.ToColour() );
55  brush.SetStyle( wxBRUSHSTYLE_SOLID );
56 
57  iconDC.SetBrush( brush );
58 
59  iconDC.DrawRectangle( 0, 0, SWATCH_SIZE_X, SWATCH_SIZE_Y );
60 
61  return bitmap;
62 }
static const int SWATCH_SIZE_Y
static const int SWATCH_SIZE_X
static std::unique_ptr<wxStaticBitmap> makeColorSwatch ( wxWindow *  aParent,
COLOR4D  aColor,
int  aID 
)
static

Function makeColorButton creates a wxStaticBitmap and assigns it a solid color and a control ID.

Definition at line 69 of file color_swatch.cpp.

References makeBitmap().

Referenced by COLOR_SWATCH::COLOR_SWATCH().

71 {
72  // construct a bitmap of the right color and make the swatch from it
73  wxBitmap bitmap = makeBitmap( aColor );
74  auto ret = std::make_unique<wxStaticBitmap>( aParent, aID, bitmap );
75 
76  return ret;
77 }
static wxBitmap makeBitmap(COLOR4D aColor)
Make a simple color swatch bitmap.
static void sendSwatchChangeEvent ( COLOR_SWATCH aSender)
static

Definition at line 115 of file color_swatch.cpp.

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

116 {
117  wxCommandEvent changeEvt( COLOR_SWATCH_CHANGED );
118 
119  // use this class as the object (alternative might be to
120  // set a custom event class but that's more work)
121  changeEvt.SetEventObject( &aSender );
122 
123  wxPostEvent( &aSender, changeEvt );
124 }
wxDEFINE_EVENT ( COLOR_SWATCH_CHANGED  ,
wxCommandEvent   
)

Variable Documentation

const int SWATCH_SIZE_X = 14
static

Definition at line 36 of file color_swatch.cpp.

Referenced by makeBitmap().

const int SWATCH_SIZE_Y = 12
static

Definition at line 37 of file color_swatch.cpp.

Referenced by makeBitmap().