KiCad PCB EDA Suite
color_swatch.cpp File Reference
#include <widgets/color_swatch.h>
#include "color4Dpickerdlg.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 44 of file color_swatch.cpp.

References SWATCH_SIZE_X, and SWATCH_SIZE_Y.

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

45 {
46  wxBitmap bitmap( SWATCH_SIZE_X, SWATCH_SIZE_Y );
47  wxBrush brush;
48  wxMemoryDC iconDC;
49 
50  iconDC.SelectObject( bitmap );
51 
52  brush.SetColour( aColor.ToColour() );
53  brush.SetStyle( wxBRUSHSTYLE_SOLID );
54 
55  iconDC.SetBrush( brush );
56 
57  iconDC.DrawRectangle( 0, 0, SWATCH_SIZE_X, SWATCH_SIZE_Y );
58 
59  return bitmap;
60 }
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 67 of file color_swatch.cpp.

References makeBitmap().

Referenced by COLOR_SWATCH::COLOR_SWATCH().

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

Definition at line 113 of file color_swatch.cpp.

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

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

Variable Documentation

const int SWATCH_SIZE_X = 14
static

Definition at line 34 of file color_swatch.cpp.

Referenced by makeBitmap().

const int SWATCH_SIZE_Y = 12
static

Definition at line 35 of file color_swatch.cpp.

Referenced by makeBitmap().