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.15 by greg, Wed Oct 4 09:18:54 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 91 | Line 91 | char  *name;
91                  return(NULL);
92          }
93          make_gmap(GAMMA);                       /* make color map */
94        if (getpixels() < 0)                    /* get pixels */
95                stderr_v("cannot allocate colors\n");
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 <                                                /* redo color table */
165 <        new_ctab(ncolors);
166 <        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 194 | 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 265 | Line 275 | int  r, g, b;
275   }
276  
277  
278 < 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;
282 <        return(-1);
292 >        return(ncolors = 0);
293   }
294  
295  
# Line 315 | Line 325 | getevent()                     /* get next event */
325                  getkey(levptr(XKeyPressedEvent));
326                  break;
327          case ExposeWindow:
328 <                if (levptr(XExposeEvent)->subwindow == 0) {
329 <                        if (ncolors == 0 && getpixels() < 0) {
320 <                                stderr_v("cannot allocate colors\n");
321 <                                break;
322 <                        }
323 <                        new_ctab(ncolors);
324 <                }
325 <                /* fall through */
328 >                windowchange(levptr(XExposeEvent));
329 >                break;
330          case ExposeRegion:
331                  fixwindow(levptr(XExposeEvent));
332                  break;
# Line 337 | 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 355 | 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