KiCad PCB EDA Suite
GRID_CELL_ICON_TEXT_RENDERER Class Reference

#include <grid_icon_text_helpers.h>

Inheritance diagram for GRID_CELL_ICON_TEXT_RENDERER:

Public Member Functions

 GRID_CELL_ICON_TEXT_RENDERER (const std::vector< BITMAP_DEF > &icons, const wxArrayString &names)
 
void Draw (wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
 

Private Attributes

const std::vector< BITMAP_DEF > & m_icons
 
const wxArrayString & m_names
 

Detailed Description

Definition at line 39 of file grid_icon_text_helpers.h.

Constructor & Destructor Documentation

GRID_CELL_ICON_TEXT_RENDERER::GRID_CELL_ICON_TEXT_RENDERER ( const std::vector< BITMAP_DEF > &  icons,
const wxArrayString &  names 
)

Definition at line 33 of file grid_icon_text_helpers.cpp.

34  :
35  m_icons( icons ),
36  m_names( names )
37 {
38 }
const std::vector< BITMAP_DEF > & m_icons

Member Function Documentation

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

Definition at line 40 of file grid_icon_text_helpers.cpp.

References KiBitmap(), m_icons, and m_names.

43 {
44  wxString value = aGrid.GetCellValue( aRow, aCol );
45  wxBitmap bitmap;
46 
47  wxRect rect = aRect;
48  rect.Inflate( -1 );
49 
50  // erase background
51  wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
52 
53  // draw the icon
54  // note that the set of icons might be smaller than the set of labels if the last
55  // label is <...>.
56  if( m_names.Index( value ) < (int) m_icons.size() )
57  {
58  bitmap = KiBitmap( (BITMAP_DEF) m_icons[ m_names.Index( value ) ] );
59  aDC.DrawBitmap( bitmap, rect.GetLeft() + 3, rect.GetTop() + 2, true );
60  }
61  // still need a bitmap to fetch the width
62  else
63  bitmap = KiBitmap( (BITMAP_DEF) m_icons[ 0 ] );
64 
65  // draw the text
66  rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 7 );
67  SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
68  aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
69 }
PNG memory record (file in memory).
Definition: bitmap_types.h:43
const std::vector< BITMAP_DEF > & m_icons
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79

Member Data Documentation

const std::vector<BITMAP_DEF>& GRID_CELL_ICON_TEXT_RENDERER::m_icons
private

Definition at line 48 of file grid_icon_text_helpers.h.

Referenced by Draw().

const wxArrayString& GRID_CELL_ICON_TEXT_RENDERER::m_names
private

Definition at line 49 of file grid_icon_text_helpers.h.

Referenced by Draw().


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