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

Reset / Clear #15

Open
Martin-Pitt opened this issue Mar 30, 2021 · 0 comments
Open

Reset / Clear #15

Martin-Pitt opened this issue Mar 30, 2021 · 0 comments

Comments

@Martin-Pitt
Copy link

Martin-Pitt commented Mar 30, 2021

I use .save() and .restore() as the first and last calls during drawing to reset my canvas state. Since I call save at the beginning to store the initial state basically. Outside the two calls I can cleanly clearRect just before first .save() when drawing again.

Would .reset() be like resetting to initial state in the same way as these state related methods? Wouldn't it surprise developers if it does extra things like clearing the canvas?

Perhaps separately a simple .clear() that is like .clearRect() but implies the whole canvas instead of having to define the coordinates awkwardly?

There is already a separation between what is canvas state and clearing canvas content and I think it would be a mistake to mix the two.

So my suggestion is:

  • .reset() — restores the state of the canvas to the initial state, clearing the entire state stack
  • .clear() — erases the pixels in the entire canvas area by setting them to transparent black
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

1 participant