KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pg_cell_renderer.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) 2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <wx/control.h>
20#include <wx/dc.h>
21#include <wx/propgrid/propgrid.h>
25
26
28 wxPGDefaultRenderer()
29{}
30
31
32bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyGrid *aGrid,
33 wxPGProperty *aProperty, int aColumn, int aItem, int aFlags ) const
34{
35 wxPGCell cell = aGrid->GetUnspecifiedValueAppearance();
36
37 if( aColumn > 0 )
38 {
39 if( PGPROPERTY_COLOR4D* colorProp = dynamic_cast<PGPROPERTY_COLOR4D*>( aProperty ) )
40 {
41 wxAny av = colorProp->GetValue().GetAny();
43 : av.As<KIGFX::COLOR4D>();
44
45 wxSize swatchSize = aGrid->ConvertDialogToPixels( wxSize( 24, 16 ) );
46 int offset = ( aRect.GetHeight() - swatchSize.GetHeight() ) / 2;
47 wxRect swatch( aRect.GetPosition() + wxPoint( offset, offset ), swatchSize );
48
49 aDC.Clear(); // Ensure the "old" background is erased.
50 COLOR_SWATCH::RenderToDC( &aDC, color, colorProp->GetBackgroundColor(), swatch,
51 aGrid->ConvertDialogToPixels( CHECKERBOARD_SIZE_DU ),
52 aGrid->GetBackgroundColour() );
53
54 return true;
55 }
56
57 // Default behavior for value column
58 return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem, aFlags );
59 }
60
61 wxString text;
62 int preDrawFlags = aFlags;
63
64 aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cell );
65
66 text = wxControl::Ellipsize( text, aDC, wxELLIPSIZE_END, aRect.GetWidth() );
67
68 int imageWidth = PreDrawCell( aDC, aRect, aGrid, cell, preDrawFlags );
69
70 int imageOffset = aProperty->GetImageOffset( imageWidth );
71
72 DrawEditorValue( aDC, aRect, imageOffset, text, aProperty, nullptr );
73
74 PostDrawCell( aDC, aGrid, cell, preDrawFlags );
75
76 return !text.IsEmpty();
77}
int color
Definition: DXF_plotter.cpp:58
static void RenderToDC(wxDC *aDC, const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxRect &aRect, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
bool Render(wxDC &aDC, const wxRect &aRect, const wxPropertyGrid *aGrid, wxPGProperty *aProperty, int aColumn, int aItem, int aFlags) const override
static const wxSize CHECKERBOARD_SIZE_DU(3, 3)