A special manager feature minimizes the cost of drawing tasks to be
done after geometric operations have been performed. This is useful
in situations where you want to see the results of your work. This
feature uses a region of invalidated parts of the display called
the update region. The update region
stores the appropriate regions before any modifications are carried
out on objects, as well as those regions that are relevant after
these modifications have been carried out for each view.
To successfully apply an applicable function, you must mark the
regions where the objects are located as invalid, apply the
function, and then invalidate the regions where the objects
involved are now located (applying the function may change the
location of the objects). This mechanism is greatly simplified by a
set of methods of the IlvManager class. Regions to be updated are
only refreshed when the method
reDrawViews
is called. This 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 method
reDrawViews
actually updates the display. The
IlvManager
methods that help you optimize drawing tasks are:
-
Marks the beginning of the drawing optimization operation by emptying the region to update for each view being managed. Once this step is taken, direct or indirect calls to a draw instruction are deferred. For every
initReDraws
, there should be one call toreDrawViews
, otherwise, a warning is issued. Calls toinitReDraws
can be embedded so that the actual refresh only takes place when the last call toreDrawViews
is reached. -
Defines a new region as invalid, that is, this region will be redrawn later. Each call to
invalidateRegion
adds the region to the update region in every view. -
Sends the drawing commands for the whole update region. All the objects involved in previous calls to
invalidateRegion
are then updated. -
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. -
Returns
true
when the manager is in aninitReDraws
/reDrawViews
state.
This mechanism is used in the
applyToObject
method.
In fact the call:
manager.applyToObject(obj, func, userArg, true);
is equivalent to:
manager.initReDraws(); manager.invalidateRegion(obj); manager.applyToObject(obj, func, userArg, false); manager.invalidateRegion(obj); manager.reDrawViews();
The
invalidateRegion
method works with the bounding box of the object given as a
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, for a move operation, you must invalidate the initial
region where the object was before being moved and invalidate the
final region so that the object can be redrawn. In other
situations, such as changing the background, only the call after
the operation is necessary.