Skip to Content
XLIB Programming Manual, Rel. 5, Third Edition
book

XLIB Programming Manual, Rel. 5, Third Edition

by Adrian Nye
June 1994
Intermediate to advanced
821 pages
24h 40m
English
O'Reilly Media, Inc.
Content preview from XLIB Programming Manual, Rel. 5, Third Edition

5.2 Switching Between Graphics Contexts

One purpose of the GC is to store information about how to interpret graphics requests so that the same information does not have to be sent with every request. Another useful feature of the GC concept is that you can create several GCs with the different characteristics you need and then switch between them. Example 5-4 demonstrates how this is done. It creates two slightly different GCs with swapped foreground and background pixel values.

Example 5-4. Example of switching graphics contexts

GC gc1, gc2;
XGCValues values;
unsigned long valuemask;
    .
    .
    .
/* Open display, create window, etc. */
values.foreground = BlackPixel(display,screen_num);
values.background = WhitePixel(display,screen_num);

gc1 = XCreateGC(display, RootWindow(display, screen_num),
    (GCForeground | GCBackground), &values);

values.foreground = WhitePixel(display,screen_num);
values.background = BlackPixel(display,screen_num);

gc2 = XCreateGC(display, RootWindow(display, screen_num),
    (GCForeground | GCBackground), &values);

/* Now you can use either gc in drawing routines, thereby
 * quickly swapping the foreground and background colors */

Whether it is faster to switch between GCs or to modify a few values of a single GC depends on the particular server implementation. On some types of display hardware, several or many GCs can be cached. On these servers, it is faster to switch between GCs than to change members of them. On servers that do not cache or that cache only one GC, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Xlib Reference Manual for Version 11 of the X Window System

Xlib Reference Manual for Version 11 of the X Window System

Adrian Nye

Publisher Resources

ISBN: 9780596806187Supplemental ContentCatalog PageErrata