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.16 by greg, Wed Oct 25 15:37:24 1989 UTC vs.
Revision 1.23 by greg, Tue Jan 30 11:37:48 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 + extern char  *progname;
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  
# Line 81 | Line 81 | struct driver *
81   x_init(name, id)                /* initialize driver */
82   char  *name, *id;
83   {
84 +        char  defgeom[32];
85 +        OpaqueFrame  mainframe;
86 +
87          ourdisplay = XOpenDisplay(NULL);
88          if (ourdisplay == NULL) {
89                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 91 | Line 94 | char  *name, *id;
94                  return(NULL);
95          }
96          make_gmap(GAMMA);                       /* make color map */
94        if (getpixels() < 0)                    /* get pixels */
95                stderr_v("cannot allocate colors\n");
97  
98          pickcursor = XCreateCursor(bcross_width, bcross_height,
99                          bcross_bits, bcross_mask_bits,
100                          bcross_x_hot, bcross_y_hot,
101                          BlackPixel, WhitePixel, GXcopy);
102 <        clientname = id;
102 >        mainframe.bdrwidth = BORWIDTH;
103 >        mainframe.border = BlackPixmap;
104 >        mainframe.background = BlackPixmap;
105 >        sprintf(defgeom, "=%dx%d+0+22", DisplayWidth()-(2*BORWIDTH),
106 >                        DisplayHeight()-(2*BORWIDTH+22));
107 >        gwind = XCreate("X10 display driver", progname, NULL, defgeom,
108 >                        &mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT);
109 >        if (gwind == 0) {
110 >                stderr_v("can't create window\n");
111 >                return(NULL);
112 >        }
113 >        XStoreName(gwind, id);
114 >        XMapWindow(gwind);
115 >        XSelectInput(gwind, KeyPressed|ButtonPressed|
116 >                        ExposeWindow|ExposeRegion|UnmapWindow);
117 >        x_driver.xsiz = mainframe.width;
118 >        x_driver.ysiz = mainframe.height-COMHEIGHT;
119          x_driver.inpready = 0;
120          cmdvec = x_comout;                      /* set error vectors */
121          if (wrnvec != NULL)
# Line 135 | Line 152 | static
152   x_clear(xres, yres)                     /* clear our display */
153   int  xres, yres;
154   {
155 +        if (xres < MINWIDTH)
156 +                xres = MINWIDTH;
157 +        if (yres < MINHEIGHT)
158 +                yres = MINHEIGHT;
159          if (xres != gwidth || yres != gheight) {        /* new window */
160                  if (comline != NULL)
161                          xt_close(comline);
162 <                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;
162 >                XChangeWindow(gwind, xres, yres+COMHEIGHT);
163                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
164 <                if (comline == NULL)
165 <                        goto fail;
166 <                XMapWindow(gwind);
167 <                XSelectInput(gwind,
153 <        KeyPressed|ButtonPressed|ExposeWindow|ExposeRegion|UnmapWindow);
154 <                XStoreName(gwind, clientname);
164 >                if (comline == NULL) {
165 >                        stderr_v("Cannot open command line window\n");
166 >                        quit(1);
167 >                }
168                  gwidth = xres;
169                  gheight = yres;
170          } else                                          /* just clear */
171                  XClear(gwind);
172 <                                                /* redo color table */
173 <        new_ctab(ncolors);
174 <        checkinp();
172 >                                                /* reinitialize color table */
173 >        if (getpixels() == 0)
174 >                stderr_v("cannot allocate colors\n");
175 >        else
176 >                new_ctab(ncolors);
177 >        XSync(1);                               /* discard input */
178          return;
163 fail:
164        stderr_v("Failure opening window in x_clear\n");
165        quit(1);
179   }
180  
181  
# Line 189 | Line 202 | int  xmin, ymin, xmax, ymax;
202  
203  
204   static
205 < x_comin(inp)                    /* read in a command line */
206 < char  *inp;
205 > x_comin(inp, prompt)            /* read in a command line */
206 > char  *inp, *prompt;
207   {
208          int  x_getc(), x_comout();
209  
210 +        if (prompt != NULL)
211 +                if (fromcombuf(inp, &x_driver))
212 +                        return;
213 +                else
214 +                        xt_puts(prompt, comline);
215          xt_cursor(comline, TBLKCURS);
216          editline(inp, x_getc, x_comout);
217          xt_cursor(comline, TNOCURS);
# Line 265 | Line 283 | int  r, g, b;
283   }
284  
285  
286 < static
286 > static int
287   getpixels()                             /* get the color map */
288   {
289          int  planes;
290  
291 +        if (ncolors > 0)
292 +                return(ncolors);
293          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
294                  pixval = (int *)malloc(ncolors*sizeof(int));
295                  if (pixval == NULL)
296                          break;
297                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
298 <                        return(0);
298 >                        return(ncolors);
299                  free((char *)pixval);
300          }
301 <        ncolors = 0;
282 <        return(-1);
301 >        return(ncolors = 0);
302   }
303  
304  
# Line 315 | Line 334 | getevent()                     /* get next event */
334                  getkey(levptr(XKeyPressedEvent));
335                  break;
336          case ExposeWindow:
337 <                if (levptr(XExposeEvent)->subwindow == 0) {
338 <                        if (ncolors == 0 && getpixels() < 0) {
320 <                                stderr_v("cannot allocate colors\n");
321 <                                break;
322 <                        }
323 <                        new_ctab(ncolors);
324 <                }
325 <                /* fall through */
337 >                windowchange(levptr(XExposeEvent));
338 >                break;
339          case ExposeRegion:
340                  fixwindow(levptr(XExposeEvent));
341                  break;
# Line 337 | Line 350 | getevent()                     /* get next event */
350  
351  
352   static
353 + windowchange(eexp)                      /* process window change event */
354 + register XExposeEvent  *eexp;
355 + {
356 +        if (eexp->subwindow != 0) {
357 +                fixwindow(eexp);
358 +                return;
359 +        }
360 +                                        /* check for change in size */
361 +        if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) {
362 +                x_driver.xsiz = eexp->width;
363 +                x_driver.ysiz = eexp->height-COMHEIGHT;
364 +                strcpy(getcombuf(&x_driver), "new\n");
365 +                return;
366 +        }
367 +                                        /* remap colors */
368 +        if (getpixels() == 0) {
369 +                stderr_v("cannot allocate colors\n");
370 +                return;
371 +        }
372 +        new_ctab(ncolors);
373 +                                        /* redraw */
374 +        fixwindow(eexp);
375 + }
376 +
377 +
378 + static
379   getkey(ekey)                            /* get input key */
380   register XKeyPressedEvent  *ekey;
381   {
# Line 344 | Line 383 | register XKeyPressedEvent  *ekey;
383          register char  *str;
384  
385          str = XLookupMapping(ekey, &n);
386 <        while (n-- > 0 && c_last < sizeof(c_queue))
386 >        while (n-- > 0 && c_last < sizeof(c_queue)) {
387                  c_queue[c_last++] = *str++;
388 <        x_driver.inpready = c_last - c_first;
388 >                x_driver.inpready++;
389 >        }
390   }
391  
392  
# Line 355 | Line 395 | fixwindow(eexp)                                /* repair damage to window */
395   register XExposeEvent  *eexp;
396   {
397          if (eexp->subwindow == 0)
398 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
398 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
399 >                        eexp->x, gheight - eexp->y - eexp->height,
400                          eexp->x + eexp->width, gheight - eexp->y);
401          else if (eexp->subwindow == comline->w)
402                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines