Commit 5ac69977 authored by Maciej Suminski's avatar Maciej Suminski

Revisiting GAL:

- VIEW_ITEM::ViewUpdate() does not update items immediately. Now it marks them to be updated and the real update occurs on the next rendering frame.
- VIEW::InvalidateItem() made private.
- VIEW_LAYER::enabled -> visible
- Some functions moved to header files.
parent 87785441
......@@ -124,17 +124,22 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
{
m_drawing = true;
m_view->UpdateItems();
m_gal->BeginDrawing();
m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
m_gal->ClearScreen();
m_view->ClearTargets();
// Grid has to be redrawn only when the NONCACHED target is redrawn
if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
m_gal->DrawGrid();
m_view->Redraw();
m_gal->DrawCursor( m_viewControls->GetCursorPosition() );
if( m_view->IsDirty() )
{
m_view->ClearTargets();
// Grid has to be redrawn only when the NONCACHED target is redrawn
if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
m_gal->DrawGrid();
m_view->Redraw();
}
m_gal->DrawCursor( m_viewControls->GetCursorPosition() );
m_gal->EndDrawing();
m_drawing = false;
......@@ -215,6 +220,7 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
wxSize size = GetClientSize();
m_gal->ResizeScreen( size.GetX(), size.GetY() );
m_gal->SetBackgroundColor( KIGFX::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) );
if( m_painter )
m_painter->SetGAL( m_gal );
......
This diff is collapsed.
......@@ -31,25 +31,12 @@ using namespace KIGFX;
void VIEW_ITEM::ViewSetVisible( bool aIsVisible )
{
bool update = false;
if( m_visible != aIsVisible )
update = true;
m_visible = aIsVisible;
// update only if the visibility has really changed
if( update )
if( m_visible != aIsVisible )
{
m_visible = aIsVisible;
ViewUpdate( APPEARANCE );
}
void VIEW_ITEM::ViewUpdate( int aUpdateFlags )
{
if( !m_view )
return;
m_view->InvalidateItem( this, aUpdateFlags );
}
}
......
......@@ -94,7 +94,7 @@ public:
* first).
* @return Number of found items.
*/
int Query( const BOX2I& aRect, std::vector<LAYER_ITEM_PAIR>& aResult );
int Query( const BOX2I& aRect, std::vector<LAYER_ITEM_PAIR>& aResult ) const;
/**
* Function SetRequired()
......@@ -140,7 +140,10 @@ public:
* Function SetPainter()
* Sets the painter object used by the view for drawing VIEW_ITEMS.
*/
void SetPainter( PAINTER* aPainter );
void SetPainter( PAINTER* aPainter )
{
m_painter = aPainter;
}
/**
* Function GetPainter()
......@@ -181,7 +184,10 @@ public:
* (depending on correct GAL unit length & DPI settings).
* @param aScale: the scalefactor
*/
void SetScale( double aScale );
void SetScale( double aScale )
{
SetScale( aScale, m_center );
}
/**
* Function SetScale()
......@@ -247,7 +253,7 @@ public:
* Returns the size of the our rendering area, in pixels.
* @return viewport screen size
*/
VECTOR2D GetScreenPixelSize() const;
const VECTOR2D& GetScreenPixelSize() const;
/**
* Function AddLayer()
......@@ -279,11 +285,11 @@ public:
*/
inline void SetLayerVisible( int aLayer, bool aVisible = true )
{
if( m_layers[aLayer].enabled != aVisible )
if( m_layers[aLayer].visible != aVisible )
{
// Target has to be redrawn after changing its visibility
MarkTargetDirty( m_layers[aLayer].target );
m_layers[aLayer].enabled = aVisible;
m_layers[aLayer].visible = aVisible;
}
}
......@@ -294,7 +300,7 @@ public:
*/
inline bool IsLayerVisible( int aLayer ) const
{
return m_layers.at( aLayer ).enabled;
return m_layers.at( aLayer ).visible;
}
/**
......@@ -402,18 +408,11 @@ public:
*/
void Redraw();
/**
* Function PartialRedraw()
* Redraws only the parts of the view that have been affected by items
* for which ViewUpdate() function has been called since last redraw.
*/
void PartialRedraw();
/**
* Function RecacheAllItems()
* Rebuilds GAL display lists.
* @param aForceNow decides if every item should be instantly recached. Otherwise items are
* going to be recached when they become visible.
* going to be recached when they become visible.
*/
void RecacheAllItems( bool aForceNow = false );
......@@ -432,7 +431,16 @@ public:
* Returns true if any of the VIEW layers needs to be refreshened.
* @return True in case if any of layers is marked as dirty.
*/
bool IsDirty() const;
bool IsDirty() const
{
for( int i = 0; i < TARGETS_NUMBER; ++i )
{
if( IsTargetDirty( i ) )
return true;
}
return false;
}
/**
* Function IsTargetDirty()
......@@ -440,7 +448,12 @@ public:
* redrawn.
* @return True if the above condition is fulfilled.
*/
bool IsTargetDirty( int aTarget ) const;
bool IsTargetDirty( int aTarget ) const
{
wxASSERT( aTarget < TARGETS_NUMBER );
return m_dirtyTargets[aTarget];
}
/**
* Function MarkTargetDirty()
......@@ -470,6 +483,22 @@ public:
m_dirtyTargets[i] = true;
}
/**
* Function MarkForUpdate()
* Adds an item to a list of items that are going to be refreshed upon the next frame rendering.
* @param aItem is the item to be refreshed.
*/
void MarkForUpdate( VIEW_ITEM* aItem )
{
m_needsUpdate.push_back( aItem );
}
/**
* Function UpdateItems()
* Iterates through the list of items that asked for updating and updates them.
*/
void UpdateItems();
/**
* Function SetPanBoundary()
* Sets limits for panning area.
......@@ -493,26 +522,18 @@ public:
m_scaleLimits = VECTOR2D( aMaximum, aMinimum );
}
/**
* Function InvalidateItem()
* Manages dirty flags & redraw queueing when updating an item.
* @param aItem is the item to be updated.
* @param aUpdateFlags determines the way an item is refreshed.
*/
void InvalidateItem( VIEW_ITEM* aItem, int aUpdateFlags );
static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown
static const int VIEW_MAX_LAYERS = 128; ///< maximum number of layers that may be shown
private:
struct VIEW_LAYER
{
bool enabled; ///* is the layer to be rendered?
bool displayOnly; ///* is the layer display only?
VIEW_RTREE* items; ///* R-tree indexing all items on this layer.
int renderingOrder; ///* rendering order of this layer
int id; ///* layer ID
RENDER_TARGET target; ///* where the layer should be rendered
std::set<int> requiredLayers; ///* layers that have to be enabled to show the layer
bool visible; ///< is the layer to be rendered?
bool displayOnly; ///< is the layer display only?
VIEW_RTREE* items; ///< R-tree indexing all items on this layer.
int renderingOrder; ///< rendering order of this layer
int id; ///< layer ID
RENDER_TARGET target; ///< where the layer should be rendered
std::set<int> requiredLayers; ///< layers that have to be enabled to show the layer
};
// Convenience typedefs
......@@ -532,7 +553,7 @@ private:
///* Redraws contents within rect aRect
void redrawRect( const BOX2I& aRect );
inline void clearTargetDirty( int aTarget )
inline void markTargetClean( int aTarget )
{
wxASSERT( aTarget < TARGETS_NUMBER );
......@@ -549,7 +570,7 @@ private:
* @param aImmediate dictates the way of drawing - it allows to force immediate drawing mode
* for cached items.
*/
void draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate = false ) const;
void draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate = false );
/**
* Function draw()
......@@ -559,7 +580,7 @@ private:
* @param aImmediate dictates the way of drawing - it allows to force immediate drawing mode
* for cached items.
*/
void draw( VIEW_ITEM* aItem, bool aImmediate = false ) const;
void draw( VIEW_ITEM* aItem, bool aImmediate = false );
/**
* Function draw()
......@@ -569,7 +590,7 @@ private:
* @param aImmediate dictates the way of drawing - it allows to force immediate drawing mode
* for cached items.
*/
void draw( VIEW_GROUP* aGroup, bool aImmediate = false ) const;
void draw( VIEW_GROUP* aGroup, bool aImmediate = false );
///* Sorts m_orderedLayers when layer rendering order has changed
void sortLayers();
......@@ -578,6 +599,14 @@ private:
///* used by GAL)
void clearGroupCache();
/**
* Function InvalidateItem()
* Manages dirty flags & redraw queueing when updating an item.
* @param aItem is the item to be updated.
* @param aUpdateFlags determines the way an item is refreshed.
*/
void invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags );
/// Updates colors that are used for an item to be drawn
void updateItemColor( VIEW_ITEM* aItem, int aLayer );
......@@ -638,6 +667,9 @@ private:
/// Zoom limits
VECTOR2D m_scaleLimits;
/// Items to be updated
std::vector<VIEW_ITEM*> m_needsUpdate;
};
} // namespace KIGFX
......
......@@ -157,12 +157,16 @@ public:
/**
* Enum VIEW_UPDATE_FLAGS.
* Defines the how severely the shape/appearance of the item has been changed:
* - NONE: TODO
* - APPEARANCE: shape or layer set of the item have not been affected,
* only colors or visibility.
* - COLOR:
* - GEOMETRY: shape or layer set of the item have changed, VIEW may need to reindex it.
* - ALL: all flags above */
* - LAYERS: TODO
* - ALL: all the flags above */
enum VIEW_UPDATE_FLAGS {
NONE = 0x00, /// No updates are required
APPEARANCE = 0x01, /// Visibility flag has changed
COLOR = 0x02, /// Color has changed
GEOMETRY = 0x04, /// Position or shape has changed
......@@ -170,7 +174,8 @@ public:
ALL = 0xff
};
VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_groups( NULL ), m_groupsSize( 0 ) {}
VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_requiredUpdate( NONE ),
m_groups( NULL ), m_groupsSize( 0 ) {}
/**
* Destructor. For dynamic views, removes the item from the view.
......@@ -262,9 +267,15 @@ public:
* For dynamic VIEWs, informs the associated VIEW that the graphical representation of
* this item has changed. For static views calling has no effect.
*
* @param aUpdateFlags: how much the object has changed
* @param aUpdateFlags: how much the object has changed.
*/
virtual void ViewUpdate( int aUpdateFlags = ALL );
virtual void ViewUpdate( int aUpdateFlags = ALL )
{
if( m_view && m_requiredUpdate == NONE )
m_view->MarkForUpdate( this );
m_requiredUpdate |= aUpdateFlags;
}
/**
* Function ViewRelease()
......@@ -298,8 +309,9 @@ protected:
deleteGroups();
}
VIEW* m_view; ///* Current dynamic view the item is assigned to.
bool m_visible; ///* Are we visible in the current dynamic VIEW.
VIEW* m_view; ///< Current dynamic view the item is assigned to.
bool m_visible; ///< Are we visible in the current dynamic VIEW.
int m_requiredUpdate; ///< Flag required for updating
///* Helper for storing cached items group ids
typedef std::pair<int, int> GroupPair;
......@@ -374,6 +386,24 @@ protected:
m_layers.set( aLayers[i] );
}
}
/**
* Function viewRequiredUpdate()
* Returns current update flag for an item.
*/
virtual int viewRequiredUpdate() const
{
return m_requiredUpdate;
}
/**
* Function clearUpdateFlags()
* Marks an item as already updated, so it is not going to be redrawn.
*/
void clearUpdateFlags()
{
m_requiredUpdate = NONE;
}
};
} // namespace KIGFX
......
......@@ -746,20 +746,20 @@ void MODULE::ViewUpdate( int aUpdateFlags )
if( !m_view )
return;
// Update the module itself
VIEW_ITEM::ViewUpdate( aUpdateFlags );
// Update pads
for( D_PAD* pad = m_Pads.GetFirst(); pad; pad = pad->Next() )
m_view->InvalidateItem( pad, aUpdateFlags );
pad->ViewUpdate( aUpdateFlags );
// Update module's drawing (mostly silkscreen)
for( BOARD_ITEM* drawing = m_Drawings.GetFirst(); drawing; drawing = drawing->Next() )
m_view->InvalidateItem( drawing, aUpdateFlags );
drawing->ViewUpdate( aUpdateFlags );
// Update module's texts
m_view->InvalidateItem( m_Reference, aUpdateFlags );
m_view->InvalidateItem( m_Value, aUpdateFlags );
// Update the module itself
m_view->InvalidateItem( this, aUpdateFlags );
m_Reference->ViewUpdate( aUpdateFlags );
m_Value->ViewUpdate( aUpdateFlags );
}
......
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