Drawing improvements for symbol & footprint diffs.

Moves forced-transparency setting down into VIEW_ITEM so that it can
be used to place forced-transparent objects in a different target.
This keeps EnableDepthTest() from equalizing the alpha values between
the two symbols (or two footprints).
This commit is contained in:
Jeff Young 2023-03-11 12:42:58 +00:00
parent 4737e3b8a7
commit c9351dfd67
9 changed files with 58 additions and 31 deletions

View File

@ -37,7 +37,6 @@ EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType ) :
m_status( 0 ),
m_parent( parent ),
m_forceVisible( false ),
m_forceTransparency( 0.0 ),
m_flags( 0 ),
m_structType( idType )
{ }
@ -47,7 +46,6 @@ EDA_ITEM::EDA_ITEM( KICAD_T idType ) :
m_status( 0 ),
m_parent( nullptr ),
m_forceVisible( false ),
m_forceTransparency( 0.0 ),
m_flags( 0 ),
m_structType( idType )
{ }
@ -58,10 +56,11 @@ EDA_ITEM::EDA_ITEM( const EDA_ITEM& base ) :
m_status( base.m_status ),
m_parent( base.m_parent ),
m_forceVisible( base.m_forceVisible ),
m_forceTransparency( base.m_forceTransparency ),
m_flags( base.m_flags ),
m_structType( base.m_structType )
{ }
{
SetForcedTransparency( base.GetForcedTransparency() );
}
void EDA_ITEM::SetModified()
@ -244,12 +243,13 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
{
// do not call initVars()
m_structType = aItem.m_structType;
m_flags = aItem.m_flags;
m_status = aItem.m_status;
m_parent = aItem.m_parent;
m_forceVisible = aItem.m_forceVisible;
m_forceTransparency = aItem.m_forceTransparency;
m_structType = aItem.m_structType;
m_flags = aItem.m_flags;
m_status = aItem.m_status;
m_parent = aItem.m_parent;
m_forceVisible = aItem.m_forceVisible;
SetForcedTransparency( aItem.GetForcedTransparency() );
return *this;
}

View File

@ -927,7 +927,8 @@ struct VIEW::DRAW_ITEM_VISITOR
view( aView ),
layer( aLayer ),
useDrawPriority( aUseDrawPriority ),
reverseDrawOrder( aReverseDrawOrder )
reverseDrawOrder( aReverseDrawOrder ),
drawForcedTransparent( false )
{
}
@ -935,6 +936,12 @@ struct VIEW::DRAW_ITEM_VISITOR
{
wxCHECK( aItem->viewPrivData(), false );
if( aItem->m_forcedTransparency > 0 && !drawForcedTransparent )
{
foundForcedTransparent = true;
return true;
}
// Conditions that have to be fulfilled for an item to be drawn
bool drawCondition = aItem->viewPrivData()->isRenderable()
&& aItem->ViewGetLOD( layer, view ) < view->m_scale;
@ -976,6 +983,8 @@ struct VIEW::DRAW_ITEM_VISITOR
int layer, layers[VIEW_MAX_LAYERS];
bool useDrawPriority, reverseDrawOrder;
std::vector<VIEW_ITEM*> drawItems;
bool drawForcedTransparent;
bool foundForcedTransparent;
};
@ -997,7 +1006,6 @@ void VIEW::redrawRect( const BOX2I& aRect )
else if( l->hasNegatives )
m_gal->StartNegativesLayer();
l->items->Query( aRect, drawFunc );
if( m_useDrawPriority )
@ -1007,6 +1015,17 @@ void VIEW::redrawRect( const BOX2I& aRect )
m_gal->EndDiffLayer();
else if( l->hasNegatives )
m_gal->EndNegativesLayer();
if( drawFunc.foundForcedTransparent )
{
drawFunc.drawForcedTransparent = true;
m_gal->SetTarget( TARGET_NONCACHED );
m_gal->EnableDepthTest( true );
m_gal->SetLayerDepth( l->renderingOrder );
l->items->Query( aRect, drawFunc );
}
}
}
}

View File

@ -95,12 +95,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
else
val = ( pct - 0.5 ) * 2;
m_boardItemCopy->SetForceTransparency( val );
m_boardItemCopy->SetForcedTransparency( val );
m_boardItemCopy->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetForceTransparency( val );
child->SetForcedTransparency( val );
} );
}
@ -113,12 +113,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
else
val = 1.0 - ( pct * 2 );
m_libraryItem->SetForceTransparency( val );
m_libraryItem->SetForcedTransparency( val );
m_libraryItem->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetForceTransparency( val );
child->SetForcedTransparency( val );
} );
}

View File

@ -498,8 +498,8 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDr
color = color.Mix( sheetColour, 0.5f );
}
if( aItem->GetForceTransparency() > 0.0 )
color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForceTransparency() ) );
if( aItem->GetForcedTransparency() > 0.0 )
color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
return color;
}

View File

@ -131,12 +131,12 @@ void SYMBOL_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
else
val = ( pct - 0.5 ) * 2;
m_previewItem->SetForceTransparency( val );
m_previewItem->SetForcedTransparency( val );
view->Update( m_previewItem );
for( LIB_ITEM& child : m_previewItem->GetDrawItems() )
{
child.SetForceTransparency( val );
child.SetForcedTransparency( val );
view->Update( &child );
}
}
@ -150,12 +150,12 @@ void SYMBOL_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
else
val = 1.0 - ( pct * 2 );
m_libraryItem->SetForceTransparency( val );
m_libraryItem->SetForcedTransparency( val );
view->Update( m_libraryItem );
for( LIB_ITEM& child : m_libraryItem->GetDrawItems() )
{
child.SetForceTransparency( val );
child.SetForcedTransparency( val );
view->Update( &child );
}
}

View File

@ -199,9 +199,6 @@ public:
void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
bool IsForceVisible() const { return m_forceVisible; }
void SetForceTransparency( double aTransparency ) { m_forceTransparency = aTransparency; }
double GetForceTransparency() const { return m_forceTransparency; }
/**
* Populate \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
* purposes.
@ -497,7 +494,6 @@ protected:
EDA_ITEM_FLAGS m_status;
EDA_ITEM* m_parent; ///< Linked list: Link (parent struct)
bool m_forceVisible;
double m_forceTransparency;
EDA_ITEM_FLAGS m_flags;
private:

View File

@ -76,7 +76,9 @@ enum VIEW_VISIBILITY_FLAGS {
class VIEW_ITEM : public INSPECTABLE
{
public:
VIEW_ITEM() : m_viewPrivData( nullptr )
VIEW_ITEM() :
m_viewPrivData( nullptr ),
m_forcedTransparency( 0.0 )
{
}
@ -145,10 +147,21 @@ public:
m_viewPrivData = nullptr;
}
void SetForcedTransparency( double aForcedTransparency )
{
m_forcedTransparency = aForcedTransparency;
}
double GetForcedTransparency() const
{
return m_forcedTransparency;
}
private:
friend class VIEW;
VIEW_ITEM_DATA* m_viewPrivData;
double m_forcedTransparency; ///< Additional transparency for diff'ing items.
};
} // namespace KIGFX

View File

@ -212,9 +212,8 @@ void FOOTPRINT_PREVIEW_PANEL::DisplayFootprints( std::shared_ptr<FOOTPRINT> aFoo
fitToCurrentFootprint();
}
Show();
Layout();
RefreshAll();
Show();
}

View File

@ -434,8 +434,8 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) cons
else if( item->Type() == PCB_BITMAP_T )
color.a *= m_imageOpacity;
if( item->GetForceTransparency() > 0.0 )
color = color.WithAlpha( color.a * ( 1.0 - item->GetForceTransparency() ) );
if( item->GetForcedTransparency() > 0.0 )
color = color.WithAlpha( color.a * ( 1.0 - item->GetForcedTransparency() ) );
// No special modifiers enabled
return color;