nanovg icon indicating copy to clipboard operation
nanovg copied to clipboard

Clipping with Complex Path or Rounded Box

Open hugoam opened this issue 9 years ago • 4 comments

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

hugoam avatar Nov 13 '16 12:11 hugoam

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)
    1. Hollow out clipping area using nvgGlobalCompositeOperation with destination_out
    2. fill with nvgGlobalCompositeOperation with source_atop (fill for hollow outed area)

satoren avatar Nov 19 '16 09:11 satoren

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 avatar Nov 19 '16 11:11 satoren

@satoren your links don't appear to work anymore; do you happen to have the code still laying around?

TyOverby avatar Nov 27 '22 03:11 TyOverby

@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.

satoren avatar Nov 29 '22 08:11 satoren