Commit e697a2c4 authored by Maciej Suminski's avatar Maciej Suminski

Functions for direct item drawing.

parent aabd2a46
...@@ -89,6 +89,53 @@ void VIEW::Remove( VIEW_ITEM* aItem ) ...@@ -89,6 +89,53 @@ void VIEW::Remove( VIEW_ITEM* aItem )
} }
void VIEW::Draw( VIEW_ITEM* aItem, int aLayer ) const
{
if( isCached( aLayer ) )
{
// Draw using cached information or create one
int group = aItem->getGroup( aLayer );
if( group >= 0 )
{
m_gal->DrawGroup( group );
}
else
{
group = m_gal->BeginGroup();
aItem->setGroup( aLayer, group );
if( !m_painter->Draw( aItem, aLayer ) )
aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method
m_gal->EndGroup();
}
}
else
{
// Immediate mode
if( !m_painter->Draw( aItem, aLayer ) )
aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method
}
// Draws a bright contour around the item
if( static_cast<const EDA_ITEM*>( aItem )->IsBrightened() )
{
m_painter->DrawBrightened( aItem );
}
}
void VIEW::Draw( VIEW_ITEM* aItem ) const
{
int layers[VIEW_MAX_LAYERS], layers_count;
aItem->ViewGetLayers( layers, layers_count );
for( int i = 0; i < layers_count; ++i )
{
Draw( aItem, layers[i] );
}
}
void VIEW::SetRequired( int aLayerId, int aRequiredId, bool aRequired ) void VIEW::SetRequired( int aLayerId, int aRequiredId, bool aRequired )
{ {
wxASSERT( (unsigned) aLayerId < m_layers.size() ); wxASSERT( (unsigned) aLayerId < m_layers.size() );
...@@ -337,7 +384,7 @@ struct VIEW::updateItemsColor ...@@ -337,7 +384,7 @@ struct VIEW::updateItemsColor
void VIEW::UpdateLayerColor( int aLayer ) void VIEW::UpdateLayerColor( int aLayer )
{ {
// There is no point in updating non-cached layers // There is no point in updating non-cached layers
if( m_layers[aLayer].target != TARGET_CACHED ) if( !isCached( aLayer ) )
return; return;
BOX2I r; BOX2I r;
...@@ -360,7 +407,7 @@ void VIEW::UpdateAllLayersColor() ...@@ -360,7 +407,7 @@ void VIEW::UpdateAllLayersColor()
VIEW_LAYER* l = &( ( *i ).second ); VIEW_LAYER* l = &( ( *i ).second );
// There is no point in updating non-cached layers // There is no point in updating non-cached layers
if( l->target != TARGET_CACHED ) if( !isCached( l->id ) )
continue; continue;
updateItemsColor visitor( l->id, m_painter, m_gal ); updateItemsColor visitor( l->id, m_painter, m_gal );
...@@ -392,7 +439,7 @@ struct VIEW::changeItemsDepth ...@@ -392,7 +439,7 @@ struct VIEW::changeItemsDepth
void VIEW::ChangeLayerDepth( int aLayer, int aDepth ) void VIEW::ChangeLayerDepth( int aLayer, int aDepth )
{ {
// There is no point in updating non-cached layers // There is no point in updating non-cached layers
if( m_layers[aLayer].target != TARGET_CACHED ) if( !isCached( aLayer ) )
return; return;
BOX2I r; BOX2I r;
...@@ -488,43 +535,13 @@ struct VIEW::drawItem ...@@ -488,43 +535,13 @@ struct VIEW::drawItem
void operator()( VIEW_ITEM* aItem ) void operator()( VIEW_ITEM* aItem )
{ {
GAL* gal = view->GetGAL();
// Conditions that have te be fulfilled for an item to be drawn // Conditions that have te be fulfilled for an item to be drawn
bool drawCondition = aItem->ViewIsVisible() && bool drawCondition = aItem->ViewIsVisible() &&
aItem->ViewGetLOD( currentLayer->id ) < view->m_scale; aItem->ViewGetLOD( currentLayer->id ) < view->m_scale;
if( !drawCondition ) if( !drawCondition )
return; return;
if( currentLayer->target == TARGET_CACHED ) view->Draw( aItem, currentLayer->id );
{
// Draw using cached information or create one
int group = aItem->getGroup( currentLayer->id );
if( group >= 0 )
{
gal->DrawGroup( group );
}
else
{
group = gal->BeginGroup();
aItem->setGroup( currentLayer->id, group );
if( !view->m_painter->Draw( aItem, currentLayer->id ) )
aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method
gal->EndGroup();
}
}
else
{
// Immediate mode
if( !view->m_painter->Draw( aItem, currentLayer->id ) )
aItem->ViewDraw( currentLayer->id, gal, BOX2I() ); // Alternative drawing method
}
if( static_cast<const EDA_ITEM*>( aItem )->IsBrightened() )
{
view->m_painter->DrawBrightened( aItem );
}
} }
const VIEW_LAYER* currentLayer; const VIEW_LAYER* currentLayer;
...@@ -691,7 +708,10 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) ...@@ -691,7 +708,10 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags )
} }
else if( aUpdateFlags == VIEW_ITEM::GEOMETRY ) else if( aUpdateFlags == VIEW_ITEM::GEOMETRY )
{ {
updateItemGeometry( aItem, layers[i]); // Reinsert item
Remove( aItem );
Add( aItem );
updateItemGeometry( aItem, layers[i]); /// TODO is it still necessary?
} }
// Mark those layers as dirty, so the VIEW will be refreshed // Mark those layers as dirty, so the VIEW will be refreshed
...@@ -766,7 +786,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) ...@@ -766,7 +786,7 @@ void VIEW::RecacheAllItems( bool aImmediately )
VIEW_LAYER* l = & ( ( *i ).second ); VIEW_LAYER* l = & ( ( *i ).second );
// Obviously, there is only one cached target that has to be recomputed // Obviously, there is only one cached target that has to be recomputed
if( l->target == TARGET_CACHED ) if( isCached( l->id ) )
{ {
m_gal->SetTarget( l->target ); m_gal->SetTarget( l->target );
m_gal->SetLayerDepth( l->renderingOrder ); m_gal->SetLayerDepth( l->renderingOrder );
......
...@@ -89,11 +89,25 @@ public: ...@@ -89,11 +89,25 @@ public:
* Finds all visible items that touch or are within the rectangle aRect. * Finds all visible items that touch or are within the rectangle aRect.
* @param aRect area to search for items * @param aRect area to search for items
* @param aResult result of the search, containing VIEW_ITEMs associated with their layers. * @param aResult result of the search, containing VIEW_ITEMs associated with their layers.
* Sorted according to the rendering order (items that are on top of the rendering stack as first). * Sorted according to the rendering order (items that are on top of the rendering stack as
* first).
* @return Number of found items. * @return Number of found items.
*/ */
int Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult ); int Query( const BOX2I& aRect, std::vector<LayerItemPair>& aResult );
/**
* Function Draw()
* Draws an item, but on a specified layers. It has to be marked that some of drawing settings
* are based on the layer on which an item is drawn.
*/
void Draw( VIEW_ITEM* aItem, int aLayer ) const;
/**
* Function Draw()
* Draws an item on all layers that the item uses.
*/
void Draw( VIEW_ITEM* aItem ) const;
/** /**
* Function SetRequired() * Function SetRequired()
* Marks the aRequiredId layer as required for the aLayerId layer. In order to display the * Marks the aRequiredId layer as required for the aLayerId layer. In order to display the
...@@ -442,6 +456,12 @@ private: ...@@ -442,6 +456,12 @@ private:
/// Checks if every layer required by the aLayerId layer is enabled. /// Checks if every layer required by the aLayerId layer is enabled.
bool areRequiredLayersEnabled( int aLayerId ) const; bool areRequiredLayersEnabled( int aLayerId ) const;
/// Returns true if the layer is cached
inline bool isCached( int aLayer ) const
{
return ( m_layers.at( aLayer ).target == TARGET_CACHED );
}
/// Contains set of possible displayed layers and its properties /// Contains set of possible displayed layers and its properties
LayerMap m_layers; LayerMap m_layers;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment