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 reDrawViews is called, which means that refreshing the views of a manager is done by marking regions to be redrawn in a cycle of initReDraws and reDrawViews.
These cycles can be nested so that only the last call to the reDrawViews member function actually updates the display.
The IlvManager member functions that help you optimize drawing tasks are:
*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 initReDraws, there should be one call to reDrawViews, or else a warning is issued. Calls to initReDraws can be embedded so that the actual refresh takes place only when the last call to reDrawViews is reached.
*invalidateRegion - Marks a region as invalid. This region will be redrawn later. Each call to invalidateRegion adds the region to the update region in every view.
*reDrawViews - Sends the drawing commands for the whole update region. All the objects involved in previous calls to invalidateRegion are then updated.
*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 initReDraws call.
*isInvalidating - Returns IlTrue when the manager is in an initReDraws/reDrawViews state.
The successive use of these member functions is a mechanism used in the applyToObject member function. In fact, the call:
manager->applyToObject(obj, func, userArg, IlvTrue);
 
is equivalent to:
manager->initReDraws();
manager->invalidateRegion(obj);
manager->applyToObject(obj, func, userArg, IlvFalse);
manager->invalidateRegion(obj);
manager->reDrawViews();
 
The 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, 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 invalidateRegion is necessary.

Version 5.5.1
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.