Properties: fixes to color swatches

This commit is contained in:
Jon Evans 2023-06-29 22:53:06 -04:00
parent e17cd5abc6
commit 59495971ee
5 changed files with 26 additions and 14 deletions

View File

@ -41,19 +41,14 @@ bool PG_CELL_RENDERER::Render( wxDC &aDC, const wxRect &aRect, const wxPropertyG
wxAny av = colorProp->GetValue().GetAny();
KIGFX::COLOR4D color = av.IsNull() ? KIGFX::COLOR4D::UNSPECIFIED
: av.As<KIGFX::COLOR4D>();
KIGFX::COLOR4D background;
PreDrawCell( aDC, aRect, aGrid, cell, aFlags );
wxSize swatchSize = aGrid->ConvertDialogToPixels( wxSize( 24, 16 ) );
int offset = ( aRect.GetHeight() - swatchSize.GetHeight() ) / 2;
wxRect swatch( aRect.GetPosition() + wxPoint( offset, offset ), swatchSize );
COLOR_SWATCH::RenderToDC( &aDC, color, background, swatch,
COLOR_SWATCH::RenderToDC( &aDC, color, colorProp->GetBackgroundColor(), swatch,
aGrid->ConvertDialogToPixels( CHECKERBOARD_SIZE_DU ),
aGrid->GetParent()->GetBackgroundColour() );
PostDrawCell( aDC, aGrid, cell, aFlags );
aGrid->GetBackgroundColour() );
return true;
}

View File

@ -406,8 +406,9 @@ const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
COLOR4D aValue ) :
wxStringProperty( aLabel, aName, aValue.ToCSSString() )
COLOR4D aValue, COLOR4D aBackgroundColor ) :
wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
m_backgroundColor( aBackgroundColor )
{
SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
SetFlag( wxPG_PROP_NOEDITOR );

View File

@ -82,11 +82,11 @@ void COLOR_SWATCH::RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
rowCycle = false;
}
for( int x = aRect.GetTop(); x < aRect.GetBottom(); x += aCheckerboardSize.x )
for( int x = aRect.GetLeft(); x < aRect.GetRight(); x += aCheckerboardSize.x )
{
bool colCycle = rowCycle;
for( int y = aRect.GetLeft(); y < aRect.GetRight(); y += aCheckerboardSize.y )
for( int y = aRect.GetTop(); y < aRect.GetBottom(); y += aCheckerboardSize.y )
{
COLOR4D color = colCycle ? black : white;
brush.SetColour( color.ToColour() );
@ -94,7 +94,7 @@ void COLOR_SWATCH::RenderToDC( wxDC* aDC, const KIGFX::COLOR4D& aColor,
aDC->SetBrush( brush );
aDC->SetPen( pen );
aDC->DrawRectangle( x, y, x + aCheckerboardSize.x, y + aCheckerboardSize.y );
aDC->DrawRectangle( x, y, aCheckerboardSize.x, aCheckerboardSize.y );
colCycle = !colCycle;
}

View File

@ -124,7 +124,15 @@ void SCH_PROPERTIES_PANEL::AfterCommit()
wxPGProperty* SCH_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
{
return PGPropertyFactory( aProperty, m_frame );
wxPGProperty* prop = PGPropertyFactory( aProperty, m_frame );
if( auto colorProp = dynamic_cast<PGPROPERTY_COLOR4D*>( prop ) )
{
COLOR4D bg = m_frame->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND );
colorProp->SetBackgroundColor( bg );
}
return prop;
}

View File

@ -194,7 +194,8 @@ class PGPROPERTY_COLOR4D : public wxStringProperty
{
public:
PGPROPERTY_COLOR4D( const wxString& aLabel = wxPG_LABEL, const wxString& aName = wxPG_LABEL,
KIGFX::COLOR4D aValue = KIGFX::COLOR4D::UNSPECIFIED );
KIGFX::COLOR4D aValue = KIGFX::COLOR4D::UNSPECIFIED,
KIGFX::COLOR4D aBackground = KIGFX::COLOR4D::UNSPECIFIED );
virtual ~PGPROPERTY_COLOR4D() = default;
@ -202,6 +203,13 @@ public:
bool StringToValue( wxVariant &aVariant, const wxString &aText,
int aFlags = 0 ) const override;
void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) { m_backgroundColor = aColor; }
const KIGFX::COLOR4D& GetBackgroundColor() const { return m_backgroundColor; }
private:
/// Used for rendering colors with opacity
KIGFX::COLOR4D m_backgroundColor;
};
#endif /* PG_PROPERTIES_H */