> On Feb 3, 2023, at 5:31 PM, Laurent Bourgès <bourges.laur...@gmail.com> wrote: > > Hi, > > While working with skia & jfree's skijaGraphics2D wrapper, I observed skia > offers nice methods in SkCanvas missing in javafx Canvas/GraphicsContext to > deal with save/restore state: > > - int getSaveCount () > Returns the number of saved states, each containing: SkMatrix and clip. > > - void restoreToCount (int saveCount) > Restores state to SkMatrix and clip values when save(), returned saveCount. > > As javafx canvas also maintains s stack of saved states, such methods are > trivial to implement to allow resetting completely the canvas state by > restoreToCount(0). > > Moreover, clip(shape) + save/restore are really tricky to allows ensure clip > is reset to previous state ... > > Would you agree to add such methods to have more predictive behaviour than > counting all save() calls to ensure to call restore() the same number of > times to reset the canvas to its initial state ? > > See SkijaGraphics2d implementation that saves / restore skCanvas clip using > such index property: > https://github.com/jfree/skijagraphics2d/blob/main/src/main/java/org/jfree/skija/SkijaGraphics2D.java > > <https://github.com/jfree/skijagraphics2d/blob/main/src/main/java/org/jfree/skija/SkijaGraphics2D.java> > > Cheers, > Laurent
I’d love to see this. I find keeping track of the state of clipping and getting it restored to a specific state can be painful. Swing let you clear the clip with setClip(null) which was definitely useful and I was somewhat surprised to see that I couldn’t do that in JavaFX. Bruce