2D Graphics > Managers > Basic Manager Features > Optimizing Drawing Tasks
 
Optimizing Drawing Tasks
A special manager feature lets you perform several geometric operations and redraw only when all the modifications are done. This is implemented by the use of the update region, which is a region made up of invalidated rectangles.
The update region stores the appropriate regions before any modifications are carried out on objects. It also stores the relevant regions after these modifications have been carried out for each view.
To successfully perform an application task, you must mark the regions where relevant objects are located as invalid, apply the function, and then invalidate the regions where the objects involved are now placed. This mechanism is simplified by means of a set of member functions of the IlvManager class. Regions to be updated are refreshed only when IlvManager::reDrawViews is called, which means that refreshing the views of a manager is done by marking regions to be redrawn in a cycle of IlvManager::initReDraws and IlvManager::reDrawViews.
These cycles can be nested so that only the last call to the IlvManager::reDrawViews member function actually updates the display.
The IlvManager member functions that help you optimize drawing tasks are:
*IlvManager::initReDraws - Marks the beginning of the drawing optimization operation by emptying the region to update for each managed view. Once this step is completed, direct or indirect calls to a draw directive are deferred. For every IlvManager::initReDraws, there should be one call to IlvManager::reDrawViews, or else a warning is issued. Calls to IlvManager::initReDraws can be embedded so that the actual refresh takes place only when the last call to IlvManager::reDrawViews is reached.
*IlvManager::invalidateRegion - Marks a region as invalid. This region will be redrawn later. Each call to IlvManager::invalidateRegion adds the region to the update region in every view.
*IlvManager::reDrawViews - Sends the drawing commands for the whole update region. All the objects involved in previous calls to IlvManager::invalidateRegion are then updated.
*IlvManager::abortReDraws - Aborts the mechanism of deferred redraws (for example, if you need to refresh the whole screen). This function resets the update region to empty. If needed, you should start again with an IlvManager::initReDraws call.
*IlvManager::isInvalidating - Returns IlTrue when the manager is in an IlvManager::initReDraws/IlvManager::reDrawViews state.
The successive use of these member functions is a mechanism used in the IlvManager::applyToObject member function. In fact, the call:
manager->applyToObject(obj, func, userArg, IlTrue);
 
is equivalent to:
manager->initReDraws();
manager->invalidateRegion(obj);
manager->applyToObject(obj, func, userArg, IlFalse);
manager->invalidateRegion(obj);
manager->reDrawViews();
 
The IlvManager::invalidateRegion member function works with the bounding box of the object given in the parameter. When an operation applied to the object modifies its bounding box, IlvManager::invalidateRegion must be called twice; once before and once after the operation.
For example, when moving an object, you must invalidate the region where the object was initially located and invalidate the final region so that the object can be redrawn. If the object bounding box is not modified, only one call to IlvManager::invalidateRegion is necessary.

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.