2
* colors.c -- $Id: colors.c,v 1.1 2003/03/08 15:26:51 travo Exp $
3
* color handling for X11
5
* Copyright (c) 1998. See accompanying LEGAL file for details.
12
x_getgc(p_scr *s, p_win *w, int fillstyle)
15
if (w && w != s->gc_w_clip) {
16
x_clip(s->xdpy->dpy, gc,
17
w->xyclip[0], w->xyclip[1], w->xyclip[2], w->xyclip[3]);
20
if (fillstyle != s->gc_fillstyle) {
21
/* note: if gc_color == P_GRAYB--P_GRAYC, then gc_fillstyle
22
* will not reflect the actual fillstyle in gc
23
* the fillstyle would be unnecessary but for rotated text,
24
* which requires stippled fills, and therefore may not work
25
* properly with P_GRAYB--P_GRAYC colors -- see textout.c */
26
XSetFillStyle(s->xdpy->dpy, gc, fillstyle);
27
s->gc_fillstyle = fillstyle;
33
p_color(p_win *w, p_col_t color)
37
p_col_t old_color = s->gc_color;
39
if (color != old_color) {
42
s->gc_color = -1; /* invalidate; also when w->pixels changes */
43
pixel = x_getpixel(w, color);
45
if (color==P_XOR) XSetFunction(s->xdpy->dpy, gc, GXxor);
46
else if (old_color==P_XOR ||
47
old_color==-1) XSetFunction(s->xdpy->dpy, gc, GXcopy);
49
if ((color==P_GRAYC || color==P_GRAYB) && s->gui_flags) {
50
XSetFillStyle(s->xdpy->dpy, gc, FillOpaqueStippled);
51
XSetStipple(s->xdpy->dpy, gc, s->gray);
52
XSetBackground(s->xdpy->dpy, gc, s->colors[3].pixel);
53
/* note that s->gc_fillstyle cannot be set here */
54
} else if ((old_color==P_GRAYC || old_color==P_GRAYB) && s->gui_flags) {
55
XSetFillStyle(s->xdpy->dpy, gc, FillSolid);
56
XSetBackground(s->xdpy->dpy, gc, s->colors[0].pixel);
59
XSetForeground(s->xdpy->dpy, gc, pixel);
65
x_getpixel(p_win *w, p_col_t color)
69
if (w->parent) w = w->parent; /* offscreens use parent pixels */
70
if (!P_IS_RGB(color)) { /* standard and indexed color models */
71
pixel = w->pixels[color];
73
} else { /* rgb color model */
74
unsigned int r = P_R(color);
75
unsigned int g = P_G(color);
76
unsigned int b = P_B(color);
77
if (s->vclass==TrueColor || s->vclass==DirectColor) {
78
pixel = (s->pixels[r]&s->rmask) |
79
(s->pixels[g]&s->gmask) | (s->pixels[b]&s->bmask);
80
} else if (s->vclass!=PseudoColor) {
81
pixel = s->pixels[(r+g+b)/3];
82
} else if (w->rgb_pixels || x_rgb_palette(w)) {
83
/* use precomputed 5-9-5 color brick */
88
pixel = w->rgb_pixels[r+g+(g<<2)]; /* r + 5*g * 45*b */
90
pixel = s->colors[1].pixel;