Clipping with Complex Path or Rounded Box
It would be very very useful if NanoVG provided a way to clip what is drawn with other shapes than just a rectangle. Correct me if I am wrong but I don't think making holes in paths allows to do exactly that.
- Having a Rounded Box scissor / clip would actually cover all my use cases, so that's probably the simplest
- In theory nvgGlobalCompositeOperation provides a way to clip with any complex shape, except it SOURCE_IN only applies to the current path, and not in two different path, making it impossible to achieve the needed result
You have two ways with conditional.
- You can use nvglu* functions if you using OpenGL backend.
- If fill area wider than clipping area. (e.g. Draw textured text)
- Hollow out clipping area using nvgGlobalCompositeOperation with destination_out
- fill with nvgGlobalCompositeOperation with source_atop (fill for hollow outed area)
I am write example with "Hollow out clipping area". https://github.com/satoren/nanovg/blob/clipping_example/example/example_clip_gl3.c#L51
https://github.com/satoren/nanovg/blob/clipping_example/example/screenshot-clip.png
@satoren your links don't appear to work anymore; do you happen to have the code still laying around?
@TyOverby Unfortunately, there are no codes left. I believe it could be implemented in a similar way to HTML5 canvas clipping with nvgGlobalCompositeOperation. It's been six years and my memory is a little fuzzy, but perhaps #312 made it possible.