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.20 by greg, Tue Jan 9 09:07:03 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 43 | Line 44 | static char SCCSid[] = "$SunId$ LBL";
44  
45   #define  levptr(etype)  ((etype *)&thisevent)
46  
46 static char  *clientname;               /* calling client's name */
47
47   static XEvent  thisevent;               /* current event */
48  
49   static int  ncolors = 0;                /* color table size */
# Line 65 | Line 64 | static char  c_queue[64];              /* input queue */
64   static int  c_first = 0;                /* first character in queue */
65   static int  c_last = 0;                 /* last character in queue */
66  
67 < extern char  *malloc();
67 > extern char  *malloc(), *getcombuf();
68  
69   int  x_close(), x_clear(), x_paintr(), x_errout(),
70                  x_getcur(), x_comout(), x_comin();
71  
72   static struct driver  x_driver = {
73          x_close, x_clear, x_paintr, x_getcur,
74 <        x_comout, x_comin,
76 <        MAXRES, MAXRES
74 >        x_comout, x_comin, 1.0
75   };
76  
77  
78   struct driver *
79 < x_init(name)                    /* initialize driver */
80 < char  *name;
79 > x_init(name, id)                /* initialize driver */
80 > char  *name, *id;
81   {
82 +        char  defgeom[32];
83 +        OpaqueFrame  mainframe;
84 +
85          ourdisplay = XOpenDisplay(NULL);
86          if (ourdisplay == NULL) {
87                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 91 | Line 92 | char  *name;
92                  return(NULL);
93          }
94          make_gmap(GAMMA);                       /* make color map */
94        if (getpixels() < 0)                    /* get pixels */
95                stderr_v("cannot allocate colors\n");
95  
96          pickcursor = XCreateCursor(bcross_width, bcross_height,
97                          bcross_bits, bcross_mask_bits,
98                          bcross_x_hot, bcross_y_hot,
99                          BlackPixel, WhitePixel, GXcopy);
100 <        clientname = name;
100 >        mainframe.bdrwidth = BORWIDTH;
101 >        mainframe.border = BlackPixmap;
102 >        mainframe.background = BlackPixmap;
103 >        sprintf(defgeom, "=%dx%d+0+22", DisplayWidth()-(2*BORWIDTH),
104 >                        DisplayHeight()-(2*BORWIDTH+22));
105 >        gwind = XCreate("X10 driver", name, NULL, defgeom,
106 >                        &mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT);
107 >        if (gwind == 0) {
108 >                stderr_v("can't create window\n");
109 >                return(NULL);
110 >        }
111 >        XStoreName(gwind, id);
112 >        XMapWindow(gwind);
113 >        XSelectInput(gwind, KeyPressed|ButtonPressed|
114 >                        ExposeWindow|ExposeRegion|UnmapWindow);
115 >        x_driver.xsiz = mainframe.width;
116 >        x_driver.ysiz = mainframe.height-COMHEIGHT;
117          x_driver.inpready = 0;
118          cmdvec = x_comout;                      /* set error vectors */
119          if (wrnvec != NULL)
# Line 135 | Line 150 | static
150   x_clear(xres, yres)                     /* clear our display */
151   int  xres, yres;
152   {
153 +        if (xres < MINWIDTH)
154 +                xres = MINWIDTH;
155 +        if (yres < MINHEIGHT)
156 +                yres = MINHEIGHT;
157          if (xres != gwidth || yres != gheight) {        /* new window */
158                  if (comline != NULL)
159                          xt_close(comline);
160 <                if (gwind != 0)
142 <                        XDestroyWindow(gwind);
143 <                gwind = XCreateWindow(RootWindow, 0, BARHEIGHT,
144 <                                xres, yres+COMHEIGHT, BORWIDTH,
145 <                                BlackPixmap, BlackPixmap);
146 <                if (gwind == 0)
147 <                        goto fail;
160 >                XChangeWindow(gwind, xres, yres+COMHEIGHT);
161                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
162 <                if (comline == NULL)
163 <                        goto fail;
164 <                XMapWindow(gwind);
165 <                XSelectInput(gwind,
153 <        KeyPressed|ButtonPressed|ExposeWindow|ExposeRegion|UnmapWindow);
154 <                XStoreName(gwind, clientname);
162 >                if (comline == NULL) {
163 >                        stderr_v("Cannot open command line window\n");
164 >                        quit(1);
165 >                }
166                  gwidth = xres;
167                  gheight = yres;
168          } else                                          /* just clear */
169                  XClear(gwind);
170 <                                                /* redo color table */
171 <        new_ctab(ncolors);
172 <        checkinp();
170 >                                                /* reinitialize color table */
171 >        if (ncolors == 0 && getpixels() == 0)
172 >                stderr_v("cannot allocate colors\n");
173 >        else
174 >                new_ctab(ncolors);
175 >        XSync(1);                               /* discard input */
176          return;
163 fail:
164        stderr_v("Failure opening window in x_clear\n");
165        quit(1);
177   }
178  
179  
# Line 194 | Line 205 | char  *inp;
205   {
206          int  x_getc(), x_comout();
207  
208 +        if (fromcombuf(inp, &x_driver))
209 +                return;
210          xt_cursor(comline, TBLKCURS);
211          editline(inp, x_getc, x_comout);
212          xt_cursor(comline, TNOCURS);
# Line 265 | Line 278 | int  r, g, b;
278   }
279  
280  
281 < static
281 > static int
282   getpixels()                             /* get the color map */
283   {
284          int  planes;
285  
286 +        freepixels();
287          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
288                  pixval = (int *)malloc(ncolors*sizeof(int));
289                  if (pixval == NULL)
290                          break;
291                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
292 <                        return(0);
292 >                        return(ncolors);
293                  free((char *)pixval);
294          }
295 <        ncolors = 0;
282 <        return(-1);
295 >        return(ncolors = 0);
296   }
297  
298  
# Line 315 | Line 328 | getevent()                     /* get next event */
328                  getkey(levptr(XKeyPressedEvent));
329                  break;
330          case ExposeWindow:
331 <                if (levptr(XExposeEvent)->subwindow == 0) {
332 <                        if (ncolors == 0 && getpixels() < 0) {
320 <                                stderr_v("cannot allocate colors\n");
321 <                                break;
322 <                        }
323 <                        new_ctab(ncolors);
324 <                }
325 <                /* fall through */
331 >                windowchange(levptr(XExposeEvent));
332 >                break;
333          case ExposeRegion:
334                  fixwindow(levptr(XExposeEvent));
335                  break;
# Line 337 | Line 344 | getevent()                     /* get next event */
344  
345  
346   static
347 + windowchange(eexp)                      /* process window change event */
348 + register XExposeEvent  *eexp;
349 + {
350 +        if (eexp->subwindow != 0) {
351 +                fixwindow(eexp);
352 +                return;
353 +        }
354 +                                        /* check for change in size */
355 +        if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) {
356 +                x_driver.xsiz = eexp->width;
357 +                x_driver.ysiz = eexp->height-COMHEIGHT;
358 +                strcpy(getcombuf(&x_driver), "new\n");
359 +                return;
360 +        }
361 +                                        /* remap colors */
362 +        if (ncolors == 0 && getpixels() == 0) {
363 +                stderr_v("cannot allocate colors\n");
364 +                return;
365 +        }
366 +        new_ctab(ncolors);
367 +                                        /* redraw */
368 +        fixwindow(eexp);
369 + }
370 +
371 +
372 + static
373   getkey(ekey)                            /* get input key */
374   register XKeyPressedEvent  *ekey;
375   {
# Line 344 | Line 377 | register XKeyPressedEvent  *ekey;
377          register char  *str;
378  
379          str = XLookupMapping(ekey, &n);
380 <        while (n-- > 0 && c_last < sizeof(c_queue))
380 >        while (n-- > 0 && c_last < sizeof(c_queue)) {
381                  c_queue[c_last++] = *str++;
382 <        x_driver.inpready = c_last - c_first;
382 >                x_driver.inpready++;
383 >        }
384   }
385  
386  
# Line 355 | Line 389 | fixwindow(eexp)                                /* repair damage to window */
389   register XExposeEvent  *eexp;
390   {
391          if (eexp->subwindow == 0)
392 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
392 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
393 >                        eexp->x, gheight - eexp->y - eexp->height,
394                          eexp->x + eexp->width, gheight - eexp->y);
395          else if (eexp->subwindow == comline->w)
396                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines