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)
 
static const wxSize SWATCH_SIZE_DU (8, 6)
 
COLOR4D DisplayColorFrame (wxWindow *aParent, COLOR4D aOldColor)
 
static wxBitmap makeBitmap (COLOR4D aColor, COLOR4D aBackground, wxWindow *aWindow)
 Make a simple color swatch bitmap. More...
 
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. More...
 
static void sendSwatchChangeEvent (COLOR_SWATCH &aSender)
 

Function Documentation

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

Make a simple color swatch bitmap.

Parameters
aWindow- window used as context for device-independent size

Definition at line 45 of file color_swatch.cpp.

References SWATCH_SIZE_DU(), and KIGFX::COLOR4D::WithAlpha().

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

46 {
47  wxSize size( aWindow->ConvertDialogToPixels( SWATCH_SIZE_DU ) );
48  wxBitmap bitmap( size );
49  wxBrush brush;
50  wxMemoryDC iconDC;
51 
52  iconDC.SelectObject( bitmap );
53 
54  brush.SetStyle( wxBRUSHSTYLE_SOLID );
55  brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
56  iconDC.SetBrush( brush );
57  iconDC.DrawRectangle( 0, 0, size.x, size.y );
58 
59  brush.SetColour( aColor.ToColour() );
60  iconDC.SetBrush( brush );
61  iconDC.DrawRectangle( 0, 0, size.x, size.y );
62 
63  return bitmap;
64 }
static const wxSize SWATCH_SIZE_DU(8, 6)
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:237
static std::unique_ptr<wxStaticBitmap> makeColorSwatch ( wxWindow *  aParent,
COLOR4D  aColor,
COLOR4D  aBackground,
int  aID 
)
static

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

Definition at line 71 of file color_swatch.cpp.

References makeBitmap().

Referenced by COLOR_SWATCH::COLOR_SWATCH().

73 {
74  wxBitmap bitmap = makeBitmap( aColor, aBackground, aParent );
75  auto ret = std::make_unique<wxStaticBitmap>( aParent, aID, bitmap );
76 
77  return ret;
78 }
static wxBitmap makeBitmap(COLOR4D aColor, COLOR4D aBackground, wxWindow *aWindow)
Make a simple color swatch bitmap.
static void sendSwatchChangeEvent ( COLOR_SWATCH aSender)
static

Definition at line 117 of file color_swatch.cpp.

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

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

Referenced by makeBitmap().

wxDEFINE_EVENT ( COLOR_SWATCH_CHANGED  ,
wxCommandEvent   
)