Search code examples
cx11uigraphicscontextgraphicscontext

C & X11 : how to use graphic contexts


I am confused about "graphic context"s, using the xcb library. There are some examples around the www, they all show creating one single window with one single graphic context. Of course when setting up several windows, each will have its own graphicx context, or perhaps several.

Could or should I create several graphic contexts for one and the same window? For example one for drawing flowers, another for rivers, a third for text labels? Or is it better to use only one and adapt it to the job at hand?

What is considered good programming style, in this respect?


Solution

  • You can create as many contexts as you want. The rule of thumb is:

    • If you draw everything in the same style use one context.
    • If you change the style, but not very often, use one context.
    • If you change styles frequently, follow your senses and either use one content (and change its attributes as needed) or create several contents. The latter approach is faster, but if you have too many GCs, you may run out of them (there is a limit on how many GCs a window may have).