typedef struct { unsigned long pixel; unsigned short red, green, blue; char flags; char pad; } XColor;
Colormap DefaultColourmap(display, screen_number) Display *display; int screen_number;
Colormap cmap; cmap = DefaultColormap(XtDisplay(w), DefaultScreen(XtDisplay(w)));
int XAllocColor(display, colormap, color) Display *display; Colormap colormap; Xcolor *color;
int XLookupColor(display, colormap, name, exact, screen) Display *display; Colormap colormap; char *name; XColor *exact, *screen;
int XAllocNamedColor(display, colormap, name, exact, screen) Display *display; Colormap colormap; char *name; XColor *exact, *screen;
/************************************************** * * color.c * * Two simple functions for adding colours to * the current colour map. The colourindexrgb * function creates a colour map entry based on * the red, green and blue components of the * colour and returns the index of the colour. * The colourindexname function creates a colour * map entry based on the name of the colour and * returns the colour map index. * ***************************************************/ #include < X11/StringDefs.h > #include < X11/Intrinsic.h > int colourindexrgb(w, r, g, b) Widget w; int r, g, b; { Display *display; int screen; Colormap cmap; XColor color; display = XtDisplay(w); screen = DefaultScreen(display); cmap = DefaultColormap(display, screen); color.red = r; color.green = g; color.blue = b; if(XAllocColor(display, cmap, &color)) return(color.pixel); else { printf("Warning: can't allocate requested colour\n"); return(BlackPixel(display, screen)); } } int colourindexname(w, name) Widget w; char *name; { Display *display; int screen; Colormap cmap; XColor color, exact; display = XtDisplay(w); screen = DefaultScreen(display); cmap = DefaultColormap(display, screen); if(XAllocNamedColor(display, cmap, name, &color, &exact)) return(color.pixel); else { printf("Warning: can't allocate requested colour\n"); return(BlackPixel(display, screen)); } }
/************************************************** * * ctest.c * * A simple test program for the colourindex * procedures * *************************************************/ #include < X11/StringDefs.h > #include < X11/Intrinsic.h > #include < X11/Xaw/Label.h > #include < X11/Xaw/Box.h > #include "lib.h" main(argc,argv) int argc; char **argv; { Widget toplevel; Widget box; Widget quit; Widget label; int n; Arg wargs[10]; int fg; int bg; toplevel = XtInitialize(argv[0],"ctest", NULL, 0, &argc, argv); box = XtCreateManagedWidget("box",boxWidgetClass, toplevel, NULL, 0); quit = quit_button(box); label = XtCreateManagedWidget("colour",labelWidgetClass, box, NULL, 0); fg = colourindexrgb(label, 65000, 0, 0); bg = colourindexname(label,"navy"); n = 0; XtSetArg(wargs[n], XtNforeground, fg); n++; XtSetArg(wargs[n], XtNbackground, bg); n++; XtSetValues(label, wargs, n); XtRealizeWidget(toplevel); XtMainLoop(); }
Go to Pixmaps and Bitmaps
Go to Index
Go to Graphics Contexts