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 The 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
17 * along with this program. If not, see <https://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 if( !color.m_text )
46 {
47 wxSize swatchSize = aGrid->ConvertDialogToPixels( wxSize( 24, 16 ) );
48 int offset = ( aRect.GetHeight() - swatchSize.GetHeight() ) / 2;
49 wxRect swatch( aRect.GetPosition() + wxPoint( offset, offset ), swatchSize );
50
51 aDC.Clear(); // Ensure the "old" background is erased.
52 COLOR_SWATCH::RenderToDC( &aDC, color, colorProp->GetBackgroundColor(), swatch,
53 aGrid->ConvertDialogToPixels( CHECKERBOARD_SIZE_DU ),
54 aGrid->GetBackgroundColour() );
55
56 return true;
57 }
58 }
59
60 if( aProperty->HasFlag( wxPG_PROP_READONLY ) && !( aFlags & Selected ) )
61 {
62 wxColour disabledFg = aGrid->GetCellDisabledTextColour();
63
64 if( disabledFg.IsOk() )
65 {
66 aDC.SetTextForeground( disabledFg );
67 return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem,
68 aFlags | DontUseCellFgCol );
69 }
70 }
71
72 // Default behavior for value column
73 return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem, aFlags );
74 }
75
76 wxString text;
77 int preDrawFlags = aFlags;
78
79 aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cell );
80
81 text = wxControl::Ellipsize( text, aDC, wxELLIPSIZE_END, aRect.GetWidth() );
82
83 int imageWidth = PreDrawCell( aDC, aRect, aGrid, cell, preDrawFlags );
84
85 int imageOffset = aProperty->GetImageOffset( imageWidth );
86
87 DrawEditorValue( aDC, aRect, imageOffset, text, aProperty, nullptr );
88
89 PostDrawCell( aDC, aGrid, cell, preDrawFlags );
90
91 return !text.IsEmpty();
92}
static void RenderToDC(wxDC *aDC, const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxRect &aRect, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground, const std::vector< int > &aMargins={ 0, 0, 0, 0 })
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:395
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)