llgcode / draw2d

2D rendering for different output (raster, pdf, svg)
BSD 2-Clause "Simplified" License
1.09k stars 105 forks source link

GraphicContext within GraphicContext #159

Closed cciccole closed 3 years ago

cciccole commented 4 years ago

@llgcode I'm not sure if this is a feature request or simply something I don't know how to do.

I have a use case where I make many individual GraphicContext (gc) objects. I then want to arrange them into a figure.

Ideally, I could just have a gc that represents the figure and then place the individual gc objects into it at the correct locations. Is it possible?

llgcode commented 4 years ago

Hi @cciccole, I think you may want to use save and restore method. In your case:

gc.Save()
// move the current affine transformation 
gc.Translate(x, y)
Draw(gc)
gc.Restore()
// the context before is restored
// the current transformation is part of this context https://github.com/llgcode/draw2d/blob/b96d8208fcfc2e89752f31231b6ca7e31f9e2bb7/draw2dbase/stack_gc.go#L22