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

Comparing ray/src/rt/x10.c (file contents):
Revision 1.12 by greg, Mon Oct 2 17:12:39 1989 UTC vs.
Revision 1.17 by greg, Wed Oct 25 17:17:09 1989 UTC

# Line 78 | Line 78 | static struct driver  x_driver = {
78  
79  
80   struct driver *
81 < x_init(name)                    /* initialize driver */
82 < char  *name;
81 > x_init(name, id)                /* initialize driver */
82 > char  *name, *id;
83   {
84          ourdisplay = XOpenDisplay(NULL);
85          if (ourdisplay == NULL) {
# Line 90 | Line 90 | char  *name;
90                  stderr_v("not enough colors\n");
91                  return(NULL);
92          }
93 <        make_cmap(GAMMA);                       /* make color map */
94 <        if (getpixels() < 0)                    /* get pixels */
95 <                stderr_v("cannot allocate colors\n");
93 >        make_gmap(GAMMA);                       /* make color map */
94  
95          pickcursor = XCreateCursor(bcross_width, bcross_height,
96                          bcross_bits, bcross_mask_bits,
97                          bcross_x_hot, bcross_y_hot,
98                          BlackPixel, WhitePixel, GXcopy);
99 <        clientname = name;
99 >        clientname = id;
100          x_driver.inpready = 0;
101          cmdvec = x_comout;                      /* set error vectors */
102          if (wrnvec != NULL)
# Line 138 | Line 136 | int  xres, yres;
136          if (xres != gwidth || yres != gheight) {        /* new window */
137                  if (comline != NULL)
138                          xt_close(comline);
139 <                if (gwind != 0)
140 <                        XDestroyWindow(gwind);
141 <                gwind = XCreateWindow(RootWindow, 0, BARHEIGHT,
142 <                                xres, yres+COMHEIGHT, BORWIDTH,
143 <                                BlackPixmap, BlackPixmap);
144 <                if (gwind == 0)
145 <                        goto fail;
139 >                if (gwind == 0) {
140 >                        gwind = XCreateWindow(RootWindow, 0, BARHEIGHT,
141 >                                        xres, yres+COMHEIGHT, BORWIDTH,
142 >                                        BlackPixmap, BlackPixmap);
143 >                        if (gwind == 0)
144 >                                goto fail;
145 >                        XStoreName(gwind, clientname);
146 >                        XSelectInput(gwind, KeyPressed|ButtonPressed|
147 >                                        ExposeWindow|ExposeRegion|UnmapWindow);
148 >                        XMapWindow(gwind);
149 >                } else
150 >                        XChangeWindow(gwind, xres, yres+COMHEIGHT);
151                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
152                  if (comline == NULL)
153                          goto fail;
151                XMapWindow(gwind);
152                XSelectInput(gwind,
153        KeyPressed|ButtonPressed|ExposeWindow|ExposeRegion|UnmapWindow);
154                XStoreName(gwind, clientname);
154                  gwidth = xres;
155                  gheight = yres;
156          } else                                          /* just clear */
157                  XClear(gwind);
158 <        if (newtab() < 0) {
159 <                stderr_v("Color allocation error\n");
160 <                quit(1);
161 <        }
162 <        checkinp();
158 >                                                /* reinitialize color table */
159 >        if (ncolors == 0 && getpixels() == 0)
160 >                stderr_v("cannot allocate colors\n");
161 >        else
162 >                new_ctab(ncolors);
163 >        XSync(1);                               /* discard input */
164          return;
165   fail:
166          stderr_v("Failure opening window in x_clear\n");
# Line 174 | Line 174 | COLOR  col;
174   int  xmin, ymin, xmax, ymax;
175   {
176          extern long  nrays;             /* global ray count */
177 +        extern int  xnewcolr();         /* pixel assignment routine */
178          static long  lastflush = 0;     /* ray count at last flush */
179  
180          if (ncolors > 0) {
181                  XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin,
182 <                                pixval[get_pixel(col)]);
182 >                                pixval[get_pixel(col, xnewcolr)]);
183          }
184          if (nrays - lastflush >= WFLUSH) {
185                  if (ncolors <= 0)       /* output necessary for death */
# Line 251 | Line 252 | int  *xp, *yp;
252  
253  
254   static
255 < newcolr(ndx, clr)               /* enter a color into hardware table */
255 > xnewcolr(ndx, r, g, b)          /* enter a color into hardware table */
256   int  ndx;
257 < COLR  clr;
257 > int  r, g, b;
258   {
259          Color  xcolor;
260  
261          xcolor.pixel = pixval[ndx];
262 <        xcolor.red = clr[RED] << 8;
263 <        xcolor.green = clr[GRN] << 8;
264 <        xcolor.blue = clr[BLU] << 8;
262 >        xcolor.red = r << 8;
263 >        xcolor.green = g << 8;
264 >        xcolor.blue = b << 8;
265  
266          XStoreColor(&xcolor);
267   }
268  
269  
270 < static
270 < newtab()                        /* assign new color table */
271 < {
272 <        extern COLR     *get_ctab();
273 <        COLR    *ctab;
274 <        Color   *defs;
275 <        register int    i;
276 <
277 <        if ((ctab = get_ctab(ncolors)) == NULL)
278 <                return(-1);
279 <        if ((defs = (Color *)malloc(ncolors*sizeof(Color))) == NULL)
280 <                return(-1);
281 <        for (i = 0; i < ncolors; i++) {
282 <                defs[i].pixel = pixval[i];
283 <                defs[i].red = ctab[i][RED] << 8;
284 <                defs[i].green = ctab[i][GRN] << 8;
285 <                defs[i].blue = ctab[i][BLU] << 8;
286 <        }
287 <        XStoreColors(ncolors, defs);
288 <        free((char *)defs);
289 <        return(0);
290 < }
291 <
292 <
293 < static
270 > static int
271   getpixels()                             /* get the color map */
272   {
273          int  planes;
274  
275 +        freepixels();
276          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
277                  pixval = (int *)malloc(ncolors*sizeof(int));
278                  if (pixval == NULL)
279                          break;
280                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
281 <                        return(0);
281 >                        return(ncolors);
282                  free((char *)pixval);
283          }
284 <        ncolors = 0;
307 <        return(-1);
284 >        return(ncolors = 0);
285   }
286  
287  
# Line 340 | Line 317 | getevent()                     /* get next event */
317                  getkey(levptr(XKeyPressedEvent));
318                  break;
319          case ExposeWindow:
320 <                if (ncolors == 0 && levptr(XExposeEvent)->subwindow == 0)
321 <                        if (getpixels() < 0)
322 <                                stderr_v("cannot grab colors\n");
323 <                        else
324 <                                newtab();
320 >                if (levptr(XExposeEvent)->subwindow == 0) {
321 >                        if (ncolors == 0 && getpixels() == 0) {
322 >                                stderr_v("cannot allocate colors\n");
323 >                                break;
324 >                        }
325 >                        new_ctab(ncolors);
326 >                }
327                  /* fall through */
328          case ExposeRegion:
329                  fixwindow(levptr(XExposeEvent));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines