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.17 by greg, Wed Oct 25 17:17:09 1989 UTC vs.
Revision 1.21 by greg, Wed Jan 10 10:04:30 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 96 | Line 99 | char  *name, *id;
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 133 | 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) {
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);
162 >                XChangeWindow(gwind, xres, yres+COMHEIGHT);
163                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
164 <                if (comline == NULL)
165 <                        goto fail;
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 */
# Line 162 | Line 176 | int  xres, yres;
176                  new_ctab(ncolors);
177          XSync(1);                               /* discard input */
178          return;
165 fail:
166        stderr_v("Failure opening window in x_clear\n");
167        quit(1);
179   }
180  
181  
# Line 196 | Line 207 | char  *inp;
207   {
208          int  x_getc(), x_comout();
209  
210 +        if (fromcombuf(inp, &x_driver))
211 +                return;
212          xt_cursor(comline, TBLKCURS);
213          editline(inp, x_getc, x_comout);
214          xt_cursor(comline, TNOCURS);
# Line 317 | Line 330 | getevent()                     /* get next event */
330                  getkey(levptr(XKeyPressedEvent));
331                  break;
332          case ExposeWindow:
333 <                if (levptr(XExposeEvent)->subwindow == 0) {
334 <                        if (ncolors == 0 && getpixels() == 0) {
322 <                                stderr_v("cannot allocate colors\n");
323 <                                break;
324 <                        }
325 <                        new_ctab(ncolors);
326 <                }
327 <                /* fall through */
333 >                windowchange(levptr(XExposeEvent));
334 >                break;
335          case ExposeRegion:
336                  fixwindow(levptr(XExposeEvent));
337                  break;
# Line 339 | Line 346 | getevent()                     /* get next event */
346  
347  
348   static
349 + windowchange(eexp)                      /* process window change event */
350 + register XExposeEvent  *eexp;
351 + {
352 +        if (eexp->subwindow != 0) {
353 +                fixwindow(eexp);
354 +                return;
355 +        }
356 +                                        /* check for change in size */
357 +        if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) {
358 +                x_driver.xsiz = eexp->width;
359 +                x_driver.ysiz = eexp->height-COMHEIGHT;
360 +                strcpy(getcombuf(&x_driver), "new\n");
361 +                return;
362 +        }
363 +                                        /* remap colors */
364 +        if (ncolors == 0 && getpixels() == 0) {
365 +                stderr_v("cannot allocate colors\n");
366 +                return;
367 +        }
368 +        new_ctab(ncolors);
369 +                                        /* redraw */
370 +        fixwindow(eexp);
371 + }
372 +
373 +
374 + static
375   getkey(ekey)                            /* get input key */
376   register XKeyPressedEvent  *ekey;
377   {
# Line 346 | Line 379 | register XKeyPressedEvent  *ekey;
379          register char  *str;
380  
381          str = XLookupMapping(ekey, &n);
382 <        while (n-- > 0 && c_last < sizeof(c_queue))
382 >        while (n-- > 0 && c_last < sizeof(c_queue)) {
383                  c_queue[c_last++] = *str++;
384 <        x_driver.inpready = c_last - c_first;
384 >                x_driver.inpready++;
385 >        }
386   }
387  
388  
# Line 357 | Line 391 | fixwindow(eexp)                                /* repair damage to window */
391   register XExposeEvent  *eexp;
392   {
393          if (eexp->subwindow == 0)
394 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
394 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
395 >                        eexp->x, gheight - eexp->y - eexp->height,
396                          eexp->x + eexp->width, gheight - eexp->y);
397          else if (eexp->subwindow == comline->w)
398                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines