[comp.windows.x] Graphics Contexts

jstravis@athena.mit.edu (John S. Travis) (08/09/89)

	I'm confused about the creation and uses of GCs. What
is the real difference between XCreateGC and XtGetGC. Supposedly,
I'm not supposed to moidify a GC created by XtGetGC but I have and
it *seems* to work. I have some bugs, but I'm not sure where.
What should I use when I have many options as in a draw program.
Maintain multiple GCs and flip back & forth or modify existing?
For example, I allow 4 font sizes. Should i have 4 GC or one
in which i uses XSetFont? I've read Young's book and Oliver Jones'
X window book but am still confused. Thanks for any advice.

john travis
jstravis@athena.mit.edu

rws@EXPO.LCS.MIT.EDU (08/11/89)

    What is the real difference between XCreateGC and XtGetGC.

XCreateGC gives you a private GC that you are free to modify.
XtGetGC gives you a possibly shared GC that you must not modify.

    Supposedly, I'm not supposed to moidify a GC created by XtGetGC but I
    have and it *seems* to work.

You are simply lucky, that no other part of your application (including
whatever widgets you use) has done an XtGetGC and gotten back the same
GC, and depends on the particular values not changing.

    What should I use when I have many options as in a draw program.
    Maintain multiple GCs and flip back & forth or modify existing?

This isn't an easy question to answer.  In some servers, switching between
"static" GCs is fastest, in other servers varying an attribute or two of a
single GC is fastest.  GCs also consume server memory.  I think the jury
is still out on whether the Xt approach of encouraging read-only GCs (of
which there might be a total of a dozen in a real application) is better
or worse than encouraging write-some GCs (in which the application would
have to worry about resetting one or two attributes before using).