~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/x11/colors.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * colors.c -- $Id: colors.c,v 1.1 2003/03/08 15:26:51 travo Exp $
 
3
 * color handling for X11
 
4
 *
 
5
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
#include "config.h"
 
9
#include "playx.h"
 
10
 
 
11
GC
 
12
x_getgc(p_scr *s, p_win *w, int fillstyle)
 
13
{
 
14
  GC gc = s->gc;
 
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]);
 
18
    s->gc_w_clip = w;
 
19
  }
 
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;
 
28
  }
 
29
  return gc;
 
30
}
 
31
 
 
32
void
 
33
p_color(p_win *w, p_col_t color)
 
34
{
 
35
  p_scr *s = w->s;
 
36
  GC gc = s->gc;
 
37
  p_col_t old_color = s->gc_color;
 
38
 
 
39
  if (color != old_color) {
 
40
    p_col_t pixel;
 
41
 
 
42
    s->gc_color = -1; /* invalidate; also when w->pixels changes */
 
43
    pixel = x_getpixel(w, color);
 
44
 
 
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);
 
48
 
 
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);
 
57
    }
 
58
 
 
59
    XSetForeground(s->xdpy->dpy, gc, pixel);
 
60
    s->gc_color = color;
 
61
  }
 
62
}
 
63
 
 
64
p_col_t
 
65
x_getpixel(p_win *w, p_col_t color)
 
66
{
 
67
  p_scr *s = w->s;
 
68
  p_col_t pixel;
 
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];
 
72
 
 
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 */
 
84
      r = (r+32)>>6;
 
85
      g = (g+16)>>5;
 
86
      b = (b+32)>>6;
 
87
      g += b+(b<<3);
 
88
      pixel = w->rgb_pixels[r+g+(g<<2)];  /* r + 5*g * 45*b */
 
89
    } else {
 
90
      pixel = s->colors[1].pixel;
 
91
    }
 
92
  }
 
93
  return pixel;
 
94
}