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.18 by greg, Mon Jan 8 13:38:41 1990 UTC

# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   #define GAMMA           2.2             /* exponent for color correction */
28  
29   #define BORWIDTH        5               /* border width */
30 #define BARHEIGHT       25              /* menu bar size */
30   #define COMHEIGHT       (COMLH*COMCH)   /* command line height (pixels) */
31 + #define MINWIDTH        (32*COMCW)      /* minimum graphics window width */
32 + #define MINHEIGHT       64              /* minimum graphics window height */
33  
34   #define COMFN           "8x13"          /* command line font name */
35   #define COMLH           3               /* number of command lines */
# Line 65 | Line 66 | static char  c_queue[64];              /* input queue */
66   static int  c_first = 0;                /* first character in queue */
67   static int  c_last = 0;                 /* last character in queue */
68  
69 < extern char  *malloc();
69 > extern char  *malloc(), *getcombuf();
70  
71   int  x_close(), x_clear(), x_paintr(), x_errout(),
72                  x_getcur(), x_comout(), x_comin();
73  
74   static struct driver  x_driver = {
75          x_close, x_clear, x_paintr, x_getcur,
76 <        x_comout, x_comin,
76 <        MAXRES, MAXRES
76 >        x_comout, x_comin, 1.0
77   };
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.xsiz = DisplayWidth()-(2*BORWIDTH);
101 >        x_driver.ysiz = DisplayHeight()-(COMHEIGHT+2*BORWIDTH);
102          x_driver.inpready = 0;
103          cmdvec = x_comout;                      /* set error vectors */
104          if (wrnvec != NULL)
# Line 135 | Line 135 | static
135   x_clear(xres, yres)                     /* clear our display */
136   int  xres, yres;
137   {
138 +        if (xres < MINWIDTH)
139 +                xres = MINWIDTH;
140 +        if (yres < MINHEIGHT)
141 +                yres = MINHEIGHT;
142          if (xres != gwidth || yres != gheight) {        /* new window */
143                  if (comline != NULL)
144                          xt_close(comline);
145 <                if (gwind != 0)
146 <                        XDestroyWindow(gwind);
147 <                gwind = XCreateWindow(RootWindow, 0, BARHEIGHT,
148 <                                xres, yres+COMHEIGHT, BORWIDTH,
149 <                                BlackPixmap, BlackPixmap);
150 <                if (gwind == 0)
151 <                        goto fail;
145 >                if (gwind == 0) {
146 >                        gwind = XCreateWindow(RootWindow, 0, 0,
147 >                                        xres, yres+COMHEIGHT, BORWIDTH,
148 >                                        BlackPixmap, BlackPixmap);
149 >                        if (gwind == 0)
150 >                                goto fail;
151 >                        XStoreName(gwind, clientname);
152 >                        XSelectInput(gwind, KeyPressed|ButtonPressed|
153 >                                        ExposeWindow|ExposeRegion|UnmapWindow);
154 >                        XMapWindow(gwind);
155 >                } else
156 >                        XChangeWindow(gwind, xres, yres+COMHEIGHT);
157                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
158                  if (comline == NULL)
159                          goto fail;
151                XMapWindow(gwind);
152                XSelectInput(gwind,
153        KeyPressed|ButtonPressed|ExposeWindow|ExposeRegion|UnmapWindow);
154                XStoreName(gwind, clientname);
160                  gwidth = xres;
161                  gheight = yres;
162          } else                                          /* just clear */
163                  XClear(gwind);
164 <        if (newtab() < 0) {
165 <                stderr_v("Color allocation error\n");
166 <                quit(1);
167 <        }
168 <        checkinp();
164 >                                                /* reinitialize color table */
165 >        if (ncolors == 0 && getpixels() == 0)
166 >                stderr_v("cannot allocate colors\n");
167 >        else
168 >                new_ctab(ncolors);
169 >        XSync(1);                               /* discard input */
170          return;
171   fail:
172          stderr_v("Failure opening window in x_clear\n");
# Line 174 | Line 180 | COLOR  col;
180   int  xmin, ymin, xmax, ymax;
181   {
182          extern long  nrays;             /* global ray count */
183 +        extern int  xnewcolr();         /* pixel assignment routine */
184          static long  lastflush = 0;     /* ray count at last flush */
185  
186          if (ncolors > 0) {
187                  XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin,
188 <                                pixval[get_pixel(col)]);
188 >                                pixval[get_pixel(col, xnewcolr)]);
189          }
190          if (nrays - lastflush >= WFLUSH) {
191                  if (ncolors <= 0)       /* output necessary for death */
# Line 195 | Line 202 | char  *inp;
202   {
203          int  x_getc(), x_comout();
204  
205 +        if (fromcombuf(inp, &x_driver))
206 +                return;
207          xt_cursor(comline, TBLKCURS);
208          editline(inp, x_getc, x_comout);
209          xt_cursor(comline, TNOCURS);
# Line 251 | Line 260 | int  *xp, *yp;
260  
261  
262   static
263 < newcolr(ndx, clr)               /* enter a color into hardware table */
263 > xnewcolr(ndx, r, g, b)          /* enter a color into hardware table */
264   int  ndx;
265 < COLR  clr;
265 > int  r, g, b;
266   {
267          Color  xcolor;
268  
269          xcolor.pixel = pixval[ndx];
270 <        xcolor.red = clr[RED] << 8;
271 <        xcolor.green = clr[GRN] << 8;
272 <        xcolor.blue = clr[BLU] << 8;
270 >        xcolor.red = r << 8;
271 >        xcolor.green = g << 8;
272 >        xcolor.blue = b << 8;
273  
274          XStoreColor(&xcolor);
275   }
276  
277  
278 < 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
278 > static int
279   getpixels()                             /* get the color map */
280   {
281          int  planes;
282  
283 +        freepixels();
284          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
285                  pixval = (int *)malloc(ncolors*sizeof(int));
286                  if (pixval == NULL)
287                          break;
288                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
289 <                        return(0);
289 >                        return(ncolors);
290                  free((char *)pixval);
291          }
292 <        ncolors = 0;
307 <        return(-1);
292 >        return(ncolors = 0);
293   }
294  
295  
# Line 340 | Line 325 | getevent()                     /* get next event */
325                  getkey(levptr(XKeyPressedEvent));
326                  break;
327          case ExposeWindow:
328 <                if (ncolors == 0 && levptr(XExposeEvent)->subwindow == 0)
329 <                        if (getpixels() < 0)
345 <                                stderr_v("cannot grab colors\n");
346 <                        else
347 <                                newtab();
348 <                /* fall through */
328 >                windowchange(levptr(XExposeEvent));
329 >                break;
330          case ExposeRegion:
331                  fixwindow(levptr(XExposeEvent));
332                  break;
# Line 360 | Line 341 | getevent()                     /* get next event */
341  
342  
343   static
344 + windowchange(eexp)                      /* process window change event */
345 + register XExposeEvent  *eexp;
346 + {
347 +        if (eexp->subwindow != 0) {
348 +                fixwindow(eexp);
349 +                return;
350 +        }
351 +                                        /* check for change in size */
352 +        if (eexp->width != gwidth || eexp->height != gheight+COMHEIGHT) {
353 +                x_driver.xsiz = eexp->width;
354 +                x_driver.ysiz = eexp->height;
355 +                strcpy(getcombuf(&x_driver), "new\n");
356 +                return;
357 +        }
358 +                                        /* remap colors */
359 +        if (ncolors == 0 && getpixels() == 0) {
360 +                stderr_v("cannot allocate colors\n");
361 +                return;
362 +        }
363 +        new_ctab(ncolors);
364 +                                        /* redraw */
365 +        fixwindow(eexp);
366 + }
367 +
368 +
369 + static
370   getkey(ekey)                            /* get input key */
371   register XKeyPressedEvent  *ekey;
372   {
# Line 378 | Line 385 | fixwindow(eexp)                                /* repair damage to window */
385   register XExposeEvent  *eexp;
386   {
387          if (eexp->subwindow == 0)
388 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
388 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
389 >                        eexp->x, gheight - eexp->y - eexp->height,
390                          eexp->x + eexp->width, gheight - eexp->y);
391          else if (eexp->subwindow == comline->w)
392                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines