Creating Layers in JGraphics

Luigi Castelli's icon

Hi there,

in what situation and what are the benefits of using layers when drawing an UI object?
I see at the end of the jgraphics.h file there are five functions defined:
jbox_invalidate_layer()
jbox_remove_layer()
jbox_start_layer()
jbox_end_layer()
jbox_paint_layer()

I understand that in situation when you want the same drawing tiled or repeated over and over layers are the way to go, but what does JGraphics do under the hood? Is it all transformed in a surface and then only the actual pixels of the surface are copied over and over ? I can see this being more efficient... But would layers be useful in situation other than tiling or repeating ? (i.e. for instance for drawing a button when you can have a "Button On" and a "Button Off" layer and alternate between the two? In this case I don't see any performance gains, but are there other gains I cannot see?

This question arose from looking at the source code of the ICST objects which make frequent use of layers.

As far as I am concerned I always just create the old plain graphic context and then do all the drawing in there, but I was wondering if maybe the layer strategy is a better one.

Thanks for any comment, clarification, advice.

- Luigi

Timothy Place's icon

The reason for layers in the ambimonitor external is that it prevents having to redraw static parts of the surface every time a redraw occurs -- so it is much more efficient.

do.while's icon

Hi !
i found it fairly efficient ! But one thing bothers me ... my situation require tiling pieces to get the end result as a graphical element .

Particularly i came to the point where i desire to mask out parts of the graphics with intersection of other shape , using jgraphics fill flag JGRAPHICS_FILL_RULE_EVEN_ODD which is really helpful in most cases but one .

When i intersect/mask for example rectangle of given size with another rectangle of the same size i can see small pixel artifacts around the edges where intersection takes apart .

My solution for this was to cut out regions by the size of layer and tile those layers properly together when desired . But i cant paint Layers to Layers .

Is there something i can do about it ? It was actually my first guess for what layers could be used beside efficiency drawing .