Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context.Pop() does not restore to previous state #27

Open
ghost opened this issue Oct 1, 2017 · 4 comments
Open

Context.Pop() does not restore to previous state #27

ghost opened this issue Oct 1, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 1, 2017

When applying a clipping mask after saving the current context state, calling context.Pop() does not revert to the previous clipping mask. (It appears that this does not revert anything, but the effect on the mask is more obvious than other side effects.) Objects drawn after the call to Pop() are still affected by the mask.

Demonstration of issue. PR on the way.

@dsamarin
Copy link

dsamarin commented May 14, 2018

@fogleman Do you have any comments on the pull request for this issue? I would love to use this library for my project because the API is very well-written. This problem is coming up for me when I use the recursive Push(), DrawRectangle(), Clip(), render(), Pop() pattern for a scene graph.

@fogleman
Copy link
Owner

One thing to note is that the current path is not affected by Push/Pop. This behavior is borrowed from Cairo. From their docs:

One interesting change in cairo is that the path is no longer
part of the graphics state managed by
cairo_save/restore. This allows functions to construct paths
without interfering with the graphics state. But it prevents
the traditional idiom for fill-and-stroke:

	cairo_save; cairo_fill; cairo_restore; cairo_stroke

Instead we know have alternate versions cairo cairo_fill,
cairo_stroke, and cairo_clip that preserve the current path
rather than consuming it. So the idiom now becomes simply:

	cairo_fill_preserve; cairo_stroke

I seem to have treated the clipping region the same way, but I can't remember why. I'd be okay with changing that, but I think @derekschaab 's PR breaks the behavior mentioned above.

@fogleman
Copy link
Owner

@dsamarin Anyway, in the meantime you can simply use ResetClip instead of Push/Pop.

FD- added a commit to FD-/gg that referenced this issue Aug 6, 2022
@markusheukelom
Copy link

ResetClip doesn't work a hierarchy of clipping paths: ResetClip will reset all clipping paths, instead of the just the clipping path(s) set after the last Push. Instead this does seems to work better:

d.Canvas.Push()
clip := d.Canvas.AsMask()
defer d.Canvas.Pop()
defer d.Canvas.SetMask(clip)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants