Project

General

Profile

WPainter save() and restore()

Added by Edward Hill over 14 years ago

Hi all,

I am not understand how works functions save() and restore(). I already read about it and tried see examples but still can't understand why it's needed, because even I comment save() and restore() example works well.

Please tell me how it's works and in what case need using it.

Thanks!


Replies (2)

RE: WPainter save() and restore() - Added by Koen Deforche over 14 years ago

Hey Edward,

You use save() and restore() only to get the painter state (transforms, colors, shadows, ...) back to a known state. Typically you do that because you do that if you break down your painting in smaller functions/classes which you want to reuse. The following would be a pattern of a painter helper function which is nice in the sense that it does not modify any painter state after it has finished:

void paintThings(WPainter& p)
{
  p.save();

  ... paint, set colors, apply transforms.

  p.restore();
}
    (1-2/2)