KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 wxBitmapBundle& 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 wxBitmapBundle& bundle = checked ? m_bitmapChecked : m_bitmapUnchecked;
52 wxBitmap bitmap = bundle.GetBitmapFor( &aGrid );
53
54 int x = std::max( 0, ( aRect.GetWidth() - bitmap.GetWidth() ) / 2 );
55 int y = std::max( 0, ( aRect.GetHeight() - bitmap.GetHeight() ) / 2 );
56
57 aDc.DrawBitmap( bitmap, aRect.GetTopLeft() + wxPoint( x, y ) );
58}
59
60
61wxSize GRID_BITMAP_TOGGLE_RENDERER::GetBestSize( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& aDc,
62 int aRow, int aCol)
63{
64 return m_bitmapChecked.GetPreferredBitmapSizeFor( &aGrid );
65}
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 wxBitmapBundle &aCheckedBitmap, const wxBitmapBundle &aUncheckedBitmap)