KiCad PCB EDA Suite
grid_bitmap_toggle.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Jon Evans <[email protected]>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <wx/dc.h>
23
24#include <algorithm>
25
26
28 const wxBitmap& aUncheckedBitmap ) :
29 wxGridCellRenderer(),
30 m_bitmapChecked( aCheckedBitmap ),
31 m_bitmapUnchecked( aUncheckedBitmap )
32{
33}
34
35
37{
40 return clone;
41}
42
43
44void GRID_BITMAP_TOGGLE_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
45 const wxRect& aRect, int aRow, int aCol, bool aIsSelected )
46{
47 // erase background
48 wxGridCellRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
49
50 bool checked = aGrid.GetCellValue( aRow, aCol ) == "1";
51 const wxBitmap& bitmap = checked ? m_bitmapChecked : m_bitmapUnchecked;
52
53 int x = std::max( 0, ( aRect.GetWidth() - m_bitmapChecked.GetWidth() ) / 2 );
54 int y = std::max( 0, ( aRect.GetHeight() - m_bitmapChecked.GetHeight() ) / 2 );
55
56 aDc.DrawBitmap( bitmap, aRect.GetTopLeft() + wxPoint( x, y ) );
57}
58
59
60wxSize GRID_BITMAP_TOGGLE_RENDERER::GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
61 int aRow, int aCol)
62{
63 return m_bitmapChecked.GetSize();
64}
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
void Draw(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDc, const wxRect &aRect, int aRow, int aCol, bool aIsSelected) override
wxSize GetBestSize(wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDc, int aRow, int aCol) override
GRID_BITMAP_TOGGLE_RENDERER * Clone() const override
GRID_BITMAP_TOGGLE_RENDERER(const wxBitmap &aCheckedBitmap, const wxBitmap &aUncheckedBitmap)