Forums > Dev

Creating Layers in JGraphics

November 9, 2009 | 11:40 pm

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:

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

November 13, 2009 | 5:02 pm

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.

February 7, 2015 | 1:40 pm

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 .

Viewing 3 posts - 1 through 3 (of 3 total)