ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/x11.c
(Generate patch)

Comparing ray/src/rt/x11.c (file contents):
Revision 1.16 by greg, Wed Jul 18 12:25:07 1990 UTC vs.
Revision 2.6 by greg, Wed Jun 24 09:12:50 1992 UTC

# Line 1 | Line 1
1 + /* Copyright (c) 1992 Regents of the University of California */
2 +
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
6  
5 /* Copyright (c) 1989 Regents of the University of California */
6
7   /*
8 < *  x11.c - driver for X-windows version 11.3
8 > *  x11.c - driver for X-windows version 11
9   *
10   *     Jan 1990
11   */
# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   #include  "color.h"
22   #include  "driver.h"
23   #include  "x11twind.h"
24 + #include  "x11icon.h"
25  
26 < #define GAMMA           2.2             /* exponent for color correction */
26 > #define GAMMA           2.2             /* default exponent correction */
27  
28   #define MINWIDTH        (32*COMCW)      /* minimum graphics window width */
29   #define MINHEIGHT       MINWIDTH        /* minimum graphics window height */
# Line 37 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38  
39   #define  ourscreen      DefaultScreen(ourdisplay)
40   #define  ourroot        RootWindow(ourdisplay,ourscreen)
40 #define  ourwhite       WhitePixel(ourdisplay,ourscreen)
41 #define  ourblack       BlackPixel(ourdisplay,ourscreen)
41  
42   #define  levptr(etype)  ((etype *)&currentevent)
43  
44   static XEvent  currentevent;            /* current event */
45  
46   static int  ncolors = 0;                /* color table size */
47 < static int  *pixval = NULL;             /* allocated pixels */
47 > static unsigned long  *pixval = NULL;   /* allocated pixels */
48 > static unsigned long  ourblack=0, ourwhite=1;
49  
50   static Display  *ourdisplay = NULL;     /* our display */
51  
52 < static Visual  *ourvisual;              /* our visual structure */
52 > static XVisualInfo  ourvinfo;           /* our visual information */
53  
54   static Window  gwind = 0;               /* our graphics window */
55  
# Line 82 | Line 82 | struct driver *
82   x11_init(name, id)              /* initialize driver */
83   char  *name, *id;
84   {
85 +        extern char  *getenv();
86 +        char  *gv;
87          int  nplanes;
86        XVisualInfo  ourvinfo;
88          XSetWindowAttributes    ourwinattr;
89          XWMHints  ourxwmhints;
90          XSizeHints      oursizhints;
# Line 93 | Line 94 | char  *name, *id;
94                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
95                  return(NULL);
96          }
97 +                                        /* find a usable visual */
98          nplanes = DisplayPlanes(ourdisplay, ourscreen);
99 <        if (nplanes < 4) {
100 <                stderr_v("not enough colors\n");
101 <                return(NULL);
102 <        } else if (nplanes <= 12) {
99 >        if (XMatchVisualInfo(ourdisplay,ourscreen,
100 >                                24,TrueColor,&ourvinfo) ||
101 >                        XMatchVisualInfo(ourdisplay,ourscreen,
102 >                                24,DirectColor,&ourvinfo)) {
103 >                ourblack = 0;
104 >                ourwhite = ourvinfo.red_mask |
105 >                                ourvinfo.green_mask |
106 >                                ourvinfo.blue_mask ;
107 >        } else {
108 >                if (nplanes < 4) {
109 >                        stderr_v("not enough colors\n");
110 >                        return(NULL);
111 >                }
112                  if (!XMatchVisualInfo(ourdisplay,ourscreen,
113 <                                nplanes,PseudoColor,&ourvinfo)) {
114 <                        stderr_v("PseudoColor server required\n");
113 >                                        nplanes,PseudoColor,&ourvinfo) &&
114 >                                !XMatchVisualInfo(ourdisplay,ourscreen,
115 >                                        nplanes,GrayScale,&ourvinfo)) {
116 >                        stderr_v("unsupported visual type\n");
117                          return(NULL);
118                  }
119 <        } else if (!XMatchVisualInfo(ourdisplay,ourscreen,
120 <                        nplanes,TrueColor,&ourvinfo) &&
108 <                                                /* kludge for DirectColor */
109 <                        !XMatchVisualInfo(ourdisplay,ourscreen,
110 <                        nplanes,DirectColor,&ourvinfo)) {
111 <                stderr_v("TrueColor server required\n");
112 <                return(NULL);
119 >                ourblack = BlackPixel(ourdisplay,ourscreen);
120 >                ourwhite = WhitePixel(ourdisplay,ourscreen);
121          }
122 <        ourvisual = ourvinfo.visual;
123 <        make_gmap(GAMMA);
124 <        /* open window */
122 >                                        /* set gamma */
123 >        if ((gv = getenv("GAMMA")) != NULL)
124 >                make_gmap(atof(gv));
125 >        else
126 >                make_gmap(GAMMA);
127 >                                        /* open window */
128          ourwinattr.background_pixel = ourblack;
129          ourwinattr.border_pixel = ourblack;
130 +                                        /* this is stupid */
131 +        ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot,
132 +                                ourvinfo.visual, AllocNone);
133          gwind = XCreateWindow(ourdisplay, ourroot, 0, 0,
134                  DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH,
135                  DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH,
136 <                BORWIDTH, nplanes, InputOutput, ourvisual,
137 <                CWBackPixel|CWBorderPixel, &ourwinattr);
136 >                BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual,
137 >                CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
138          if (gwind == 0) {
139                  stderr_v("cannot create window\n");
140                  return(NULL);
141          }
142 <        XStoreName(ourdisplay, gwind, id);
142 >        XStoreName(ourdisplay, gwind, id);
143          /* create a cursor */
144          pickcursor = XCreateFontCursor(ourdisplay, XC_diamond_cross);
145          ourgc = XCreateGC(ourdisplay, gwind, 0, NULL);
146 <        ourxwmhints.flags = InputHint;
146 >        ourxwmhints.flags = InputHint|IconPixmapHint;
147          ourxwmhints.input = True;
148 +        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
149 +                        gwind, x11icon_bits, x11icon_width, x11icon_height);
150          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
151          oursizhints.min_width = MINWIDTH;
152          oursizhints.min_height = MINHEIGHT+COMHEIGHT;
# Line 138 | Line 154 | char  *name, *id;
154          XSetNormalHints(ourdisplay, gwind, &oursizhints);
155          XSelectInput(ourdisplay, gwind, ExposureMask);
156          XMapWindow(ourdisplay, gwind);
157 <        XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XExposeEvent));
157 >        XWindowEvent(ourdisplay, gwind, ExposureMask, levptr(XEvent));
158          gwidth = levptr(XExposeEvent)->width;
159          gheight = levptr(XExposeEvent)->height - COMHEIGHT;
160          x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
# Line 195 | Line 211 | int  xres, yres;
211          }
212          XClearWindow(ourdisplay, gwind);
213                                                  /* reinitialize color table */
214 <        if (ourvisual->class == PseudoColor)
214 >        if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale)
215                  if (getpixels() == 0)
216                          stderr_v("cannot allocate colors\n");
217                  else
# Line 203 | Line 219 | int  xres, yres;
219                                                  /* get new command line */
220          if (comline != NULL)
221                  xt_close(comline);
222 <        comline = xt_open(ourdisplay,
223 <                        DefaultGC(ourdisplay,ourscreen),
208 <                        gwind, 0, gheight, gwidth, COMHEIGHT, 0, COMFN);
222 >        comline = xt_open(ourdisplay, gwind, 0, gheight,
223 >                        gwidth, COMHEIGHT, 0, ourblack, ourwhite, COMFN);
224          if (comline == NULL) {
225                  stderr_v("Cannot open command line window\n");
226                  quit(1);
# Line 228 | Line 243 | int  xmin, ymin, xmax, ymax;
243  
244          if (ncolors > 0)
245                  pixel = pixval[get_pixel(col, xnewcolr)];
246 <        else if (ourvisual->class != PseudoColor)
246 >        else if (ourvinfo.class == TrueColor || ourvinfo.class == DirectColor)
247                  pixel = true_pixel(col);
248          else
249                  return;
# Line 340 | Line 355 | getpixels()                            /* get the color map */
355          register int  i, j;
356  
357          if (ncolors > 0)
358 <                goto donecolors;
359 <        if (ourvisual == DefaultVisual(ourdisplay,ourscreen)) {
358 >                return(ncolors);
359 >        if (ourvinfo.visual == DefaultVisual(ourdisplay,ourscreen)) {
360                  ourmap = DefaultColormap(ourdisplay,ourscreen);
361                  goto loop;
362          }
363   newmap:
364 <        ourmap = XCreateColormap(ourdisplay,gwind,ourvisual,AllocNone);
364 >        ourmap = XCreateColormap(ourdisplay,gwind,ourvinfo.visual,AllocNone);
365   loop:
366 <        for (ncolors = ourvisual->map_entries;
367 <                        ncolors > ourvisual->map_entries/3;
366 >        for (ncolors = ourvinfo.colormap_size;
367 >                        ncolors > ourvinfo.colormap_size/3;
368                          ncolors = ncolors*.937) {
369 <                pixval = (int *)malloc(ncolors*sizeof(int));
369 >                pixval = (unsigned long *)malloc(ncolors*sizeof(unsigned long));
370                  if (pixval == NULL)
371                          return(ncolors = 0);
372                  if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,
# Line 382 | Line 397 | loop:
397                          i--;
398                  }
399          XSetWindowColormap(ourdisplay, gwind, ourmap);
385 donecolors:
386 #ifdef  DEBUG
387        thiscolor.flags = DoRed|DoGreen|DoBlue;
388        thiscolor.red = thiscolor.green = thiscolor.blue = 0;
389        for (i = 0; i < ncolors; i++) {
390                thiscolor.pixel = pixval[i];
391                XStoreColor(ourdisplay, ourmap, &thiscolor);
392        }
393 #endif
400          return(ncolors);
401   }
402  
# Line 416 | Line 422 | COLOR  col;
422          BYTE  rgb[3];
423  
424          map_color(rgb, col);
425 <        rval = ourvisual->red_mask*rgb[RED]/255 & ourvisual->red_mask;
426 <        rval |= ourvisual->green_mask*rgb[GRN]/255 & ourvisual->green_mask;
427 <        rval |= ourvisual->blue_mask*rgb[BLU]/255 & ourvisual->blue_mask;
425 >        rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask;
426 >        rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask;
427 >        rval |= ourvinfo.blue_mask*rgb[BLU]/255 & ourvinfo.blue_mask;
428          return(rval);
429   }
430  
# Line 447 | Line 453 | getevent()                     /* get next event */
453                  freepixels();
454                  break;
455          case MapNotify:
456 <                if (ourvisual->class == PseudoColor)
456 >                if (ourvinfo.class == PseudoColor ||
457 >                                ourvinfo.class == GrayScale)
458                          if (getpixels() == 0)
459                                  stderr_v("Cannot allocate colors\n");
460                          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines