2022-11-25 17:37:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <wx/control.h>
|
2023-06-25 20:13:07 +00:00
|
|
|
#include <wx/dc.h>
|
2022-11-25 17:37:18 +00:00
|
|
|
#include <wx/propgrid/propgrid.h>
|
|
|
|
#include <properties/pg_cell_renderer.h>
|
2023-06-25 20:13:07 +00:00
|
|
|
#include <properties/pg_properties.h>
|
2023-06-29 03:54:27 +00:00
|
|
|
#include <widgets/color_swatch.h>
|
2022-11-25 17:37:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
PG_CELL_RENDERER::PG_CELL_RENDERER() :
|
|
|
|
wxPGDefaultRenderer()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyGrid *aGrid,
|
|
|
|
wxPGProperty *aProperty, int aColumn, int aItem, int aFlags ) const
|
|
|
|
{
|
2023-06-25 20:13:07 +00:00
|
|
|
wxPGCell cell = aGrid->GetUnspecifiedValueAppearance();
|
|
|
|
|
2022-11-25 17:37:18 +00:00
|
|
|
if( aColumn > 0 )
|
2023-06-25 20:13:07 +00:00
|
|
|
{
|
|
|
|
if( PGPROPERTY_COLOR4D* colorProp = dynamic_cast<PGPROPERTY_COLOR4D*>( aProperty ) )
|
|
|
|
{
|
|
|
|
wxAny av = colorProp->GetValue().GetAny();
|
|
|
|
KIGFX::COLOR4D color = av.IsNull() ? KIGFX::COLOR4D::UNSPECIFIED
|
|
|
|
: av.As<KIGFX::COLOR4D>();
|
|
|
|
|
|
|
|
wxSize swatchSize = aGrid->ConvertDialogToPixels( wxSize( 24, 16 ) );
|
|
|
|
int offset = ( aRect.GetHeight() - swatchSize.GetHeight() ) / 2;
|
|
|
|
wxRect swatch( aRect.GetPosition() + wxPoint( offset, offset ), swatchSize );
|
|
|
|
|
2023-10-27 06:54:38 +00:00
|
|
|
aDC.Clear(); // Ensure the "old" background is erased.
|
2023-06-30 02:53:06 +00:00
|
|
|
COLOR_SWATCH::RenderToDC( &aDC, color, colorProp->GetBackgroundColor(), swatch,
|
2023-06-29 03:54:27 +00:00
|
|
|
aGrid->ConvertDialogToPixels( CHECKERBOARD_SIZE_DU ),
|
2023-06-30 02:53:06 +00:00
|
|
|
aGrid->GetBackgroundColour() );
|
2023-06-25 20:13:07 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default behavior for value column
|
2022-11-25 17:37:18 +00:00
|
|
|
return wxPGDefaultRenderer::Render( aDC, aRect, aGrid, aProperty, aColumn, aItem, aFlags );
|
2023-06-25 20:13:07 +00:00
|
|
|
}
|
2022-11-25 17:37:18 +00:00
|
|
|
|
|
|
|
wxString text;
|
|
|
|
int preDrawFlags = aFlags;
|
|
|
|
|
|
|
|
aProperty->GetDisplayInfo( aColumn, aItem, aFlags, &text, &cell );
|
|
|
|
|
2024-01-10 11:27:40 +00:00
|
|
|
text = wxControl::Ellipsize( text, aDC, wxELLIPSIZE_END, aRect.GetWidth() );
|
2022-11-25 17:37:18 +00:00
|
|
|
|
2022-11-25 20:24:38 +00:00
|
|
|
int imageWidth = PreDrawCell( aDC, aRect, aGrid, cell, preDrawFlags );
|
|
|
|
|
2022-11-25 17:37:18 +00:00
|
|
|
int imageOffset = aProperty->GetImageOffset( imageWidth );
|
|
|
|
|
|
|
|
DrawEditorValue( aDC, aRect, imageOffset, text, aProperty, nullptr );
|
|
|
|
|
|
|
|
PostDrawCell( aDC, aGrid, cell, preDrawFlags );
|
|
|
|
|
|
|
|
return !text.IsEmpty();
|
2023-06-25 20:13:07 +00:00
|
|
|
}
|