KiCad PCB EDA Suite
GRID_CELL_COLOR_RENDERER Class Reference

#include <grid_color_swatch_helpers.h>

Inheritance diagram for GRID_CELL_COLOR_RENDERER:

Public Member Functions

 GRID_CELL_COLOR_RENDERER (wxWindow *aParent=nullptr, SWATCH_SIZE aSize=SWATCH_EXPAND, const KIGFX::COLOR4D &aBackground=KIGFX::COLOR4D::UNSPECIFIED)
 
 GRID_CELL_COLOR_RENDERER (const GRID_CELL_COLOR_RENDERER &aOther)
 
 ~GRID_CELL_COLOR_RENDERER () override
 
wxGridCellRenderer * Clone () const override
 
wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
 
void Draw (wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
 

Private Attributes

wxWindow * m_parent
 
KIGFX::COLOR4D m_background
 
wxSize m_size
 
wxSize m_checkerboardSize
 
KIGFX::COLOR4D m_checkerboardBg
 

Detailed Description

Definition at line 37 of file grid_color_swatch_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_COLOR_RENDERER() [1/2]

GRID_CELL_COLOR_RENDERER::GRID_CELL_COLOR_RENDERER ( wxWindow *  aParent = nullptr,
SWATCH_SIZE  aSize = SWATCH_EXPAND,
const KIGFX::COLOR4D aBackground = KIGFX::COLOR4D::UNSPECIFIED 
)

Definition at line 33 of file grid_color_swatch_helpers.cpp.

34  :
35  wxGridCellRenderer(),
36  m_parent( aParent ),
37  m_background( aBackground )
38 {
39  switch( aSize )
40  {
41  case SWATCH_MEDIUM: m_size = m_parent->ConvertDialogToPixels( SWATCH_SIZE_MEDIUM_DU ); break;
42  case SWATCH_SMALL: m_size = m_parent->ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU ); break;
43  case SWATCH_LARGE: m_size = m_parent->ConvertDialogToPixels( SWATCH_SIZE_LARGE_DU ); break;
44  case SWATCH_EXPAND: m_size = wxDefaultSize; break;
45  }
46 
47  m_checkerboardSize = m_parent->ConvertDialogToPixels( CHECKERBOARD_SIZE_DU );
48  m_checkerboardBg = m_parent->GetBackgroundColour();
49 }
static const wxSize SWATCH_SIZE_LARGE_DU(24, 16)
static const wxSize SWATCH_SIZE_MEDIUM_DU(24, 10)
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)
static const wxSize SWATCH_SIZE_SMALL_DU(8, 6)

References CHECKERBOARD_SIZE_DU(), m_checkerboardBg, m_checkerboardSize, m_parent, m_size, SWATCH_EXPAND, SWATCH_LARGE, SWATCH_MEDIUM, SWATCH_SIZE_LARGE_DU(), SWATCH_SIZE_MEDIUM_DU(), SWATCH_SIZE_SMALL_DU(), and SWATCH_SMALL.

Referenced by Clone().

◆ GRID_CELL_COLOR_RENDERER() [2/2]

GRID_CELL_COLOR_RENDERER::GRID_CELL_COLOR_RENDERER ( const GRID_CELL_COLOR_RENDERER aOther)

◆ ~GRID_CELL_COLOR_RENDERER()

GRID_CELL_COLOR_RENDERER::~GRID_CELL_COLOR_RENDERER ( )
override

Definition at line 62 of file grid_color_swatch_helpers.cpp.

63 {
64 }

Member Function Documentation

◆ Clone()

wxGridCellRenderer * GRID_CELL_COLOR_RENDERER::Clone ( ) const
override

Definition at line 67 of file grid_color_swatch_helpers.cpp.

68 {
69  return new GRID_CELL_COLOR_RENDERER( *this );
70 }
GRID_CELL_COLOR_RENDERER(wxWindow *aParent=nullptr, SWATCH_SIZE aSize=SWATCH_EXPAND, const KIGFX::COLOR4D &aBackground=KIGFX::COLOR4D::UNSPECIFIED)

References GRID_CELL_COLOR_RENDERER().

◆ Draw()

void GRID_CELL_COLOR_RENDERER::Draw ( wxGrid &  aGrid,
wxGridCellAttr &  aAttr,
wxDC &  aDC,
const wxRect &  aRect,
int  aRow,
int  aCol,
bool  isSelected 
)
override

Definition at line 88 of file grid_color_swatch_helpers.cpp.

90 {
91  wxRect rect = aRect;
92 
93  // erase background
94  wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
95 
96  // draw the swatch
97  COLOR4D color( aGrid.GetTable()->GetValue( aRow, aCol ) );
98  wxSize size = ( m_size == wxDefaultSize ) ? aRect.GetSize() : m_size;
101 
102  wxPoint origin = rect.GetTopLeft();
103 
104  if( m_size != wxDefaultSize )
105  {
106  int x = std::max( 0, ( aRect.GetWidth() - m_size.x ) / 2 );
107  int y = std::max( 0, ( aRect.GetHeight() - m_size.y ) / 2 );
108  origin += wxPoint( x, y );
109  }
110 
111  aDC.DrawBitmap( bitmap, origin, true );
112 }
int color
Definition: DXF_plotter.cpp:60
static wxBitmap MakeBitmap(KIGFX::COLOR4D aColor, KIGFX::COLOR4D aBackground, wxSize aSize, wxSize aCheckerboardSize, KIGFX::COLOR4D aCheckerboardBackground)
Make a simple color swatch bitmap.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

References color, m_background, m_checkerboardBg, m_checkerboardSize, m_size, and COLOR_SWATCH::MakeBitmap().

◆ GetBestSize()

wxSize GRID_CELL_COLOR_RENDERER::GetBestSize ( wxGrid &  grid,
wxGridCellAttr &  attr,
wxDC &  dc,
int  row,
int  col 
)
override

Definition at line 73 of file grid_color_swatch_helpers.cpp.

75 {
76  if( m_size != wxDefaultSize )
77  return m_size;
78 
79  wxSize bestSize;
80 
81  dc.SetFont( attr.GetFont() );
82  dc.GetTextExtent( "WWW", &bestSize.x, &bestSize.y );
83 
84  return bestSize;
85 }

References m_size.

Member Data Documentation

◆ m_background

KIGFX::COLOR4D GRID_CELL_COLOR_RENDERER::m_background
private

Definition at line 54 of file grid_color_swatch_helpers.h.

Referenced by Draw(), and GRID_CELL_COLOR_RENDERER().

◆ m_checkerboardBg

KIGFX::COLOR4D GRID_CELL_COLOR_RENDERER::m_checkerboardBg
private

Definition at line 60 of file grid_color_swatch_helpers.h.

Referenced by Draw(), and GRID_CELL_COLOR_RENDERER().

◆ m_checkerboardSize

wxSize GRID_CELL_COLOR_RENDERER::m_checkerboardSize
private

Definition at line 58 of file grid_color_swatch_helpers.h.

Referenced by Draw(), and GRID_CELL_COLOR_RENDERER().

◆ m_parent

wxWindow* GRID_CELL_COLOR_RENDERER::m_parent
private

Definition at line 52 of file grid_color_swatch_helpers.h.

Referenced by GRID_CELL_COLOR_RENDERER().

◆ m_size

wxSize GRID_CELL_COLOR_RENDERER::m_size
private

Definition at line 56 of file grid_color_swatch_helpers.h.

Referenced by Draw(), GetBestSize(), and GRID_CELL_COLOR_RENDERER().


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