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 2.3 by greg, Fri Jun 4 14:48:35 1993 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
12  
13   #include  <stdio.h>
14 <
14 > #include  <math.h>
15   #include  <sys/ioctl.h>
16  
17   #include  <X/Xlib.h>
# 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       MINWIDTH                /* minimum graphics window height */
33  
34   #define COMFN           "8x13"          /* command line font name */
35   #define COMLH           3               /* number of command lines */
36   #define COMCW           8               /* approx. character width (pixels) */
37   #define COMCH           13              /* approx. character height (pixels) */
38  
38 #ifndef WFLUSH
39 #define WFLUSH          30              /* flush after this many rays */
40 #endif
41
42 #define  checkinp()     while (XPending() > 0) getevent()
43
39   #define  levptr(etype)  ((etype *)&thisevent)
40  
46 static char  *clientname;               /* calling client's name */
47
41   static XEvent  thisevent;               /* current event */
42  
43   static int  ncolors = 0;                /* color table size */
# Line 56 | Line 49 | static Window  gwind = 0;              /* our graphics window */
49  
50   static Cursor  pickcursor = 0;          /* cursor used for picking */
51  
52 < static int  gwidth = 0;                 /* graphics window width */
60 < static int  gheight = 0;                /* graphics window height */
52 > static int  gwidth, gheight;            /* graphics window size */
53  
54   static TEXTWIND  *comline = NULL;       /* our command line */
55  
# Line 65 | Line 57 | static char  c_queue[64];              /* input queue */
57   static int  c_first = 0;                /* first character in queue */
58   static int  c_last = 0;                 /* last character in queue */
59  
60 < extern char  *malloc();
60 > extern char  *malloc(), *getcombuf();
61  
62 < int  x_close(), x_clear(), x_paintr(), x_errout(),
71 <                x_getcur(), x_comout(), x_comin();
62 > extern char  *progname;
63  
64 + static int  x_close(), x_clear(), x_paintr(), x_errout(),
65 +                x_getcur(), x_comout(), x_comin(), x_flush();
66 +
67   static struct driver  x_driver = {
68          x_close, x_clear, x_paintr, x_getcur,
69 <        x_comout, x_comin,
76 <        MAXRES, MAXRES
69 >        x_comout, x_comin, x_flush, 1.0
70   };
71  
72  
# Line 81 | Line 74 | struct driver *
74   x_init(name, id)                /* initialize driver */
75   char  *name, *id;
76   {
77 +        extern char  *getenv();
78 +        char  *gv;
79 +        char  defgeom[32];
80 +        OpaqueFrame  mainframe;
81 +
82          ourdisplay = XOpenDisplay(NULL);
83          if (ourdisplay == NULL) {
84                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 90 | Line 88 | char  *name, *id;
88                  stderr_v("not enough colors\n");
89                  return(NULL);
90          }
91 <        make_gmap(GAMMA);                       /* make color map */
91 >                                /* make color map */
92 >        if ((gv = getenv("GAMMA")) != NULL)
93 >                make_gmap(atof(gv));
94 >        else
95 >                make_gmap(GAMMA);
96  
97          pickcursor = XCreateCursor(bcross_width, bcross_height,
98                          bcross_bits, bcross_mask_bits,
99                          bcross_x_hot, bcross_y_hot,
100                          BlackPixel, WhitePixel, GXcopy);
101 <        clientname = id;
101 >        mainframe.bdrwidth = BORWIDTH;
102 >        mainframe.border = BlackPixmap;
103 >        mainframe.background = BlackPixmap;
104 >        sprintf(defgeom, "=%dx%d+0+22", DisplayWidth()-(2*BORWIDTH),
105 >                        DisplayHeight()-(2*BORWIDTH+22));
106 >        gwind = XCreate("X10 display driver", progname, NULL, defgeom,
107 >                        &mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT);
108 >        if (gwind == 0) {
109 >                stderr_v("can't create window\n");
110 >                return(NULL);
111 >        }
112 >        XStoreName(gwind, id);
113 >        XSelectInput(gwind, KeyPressed|ButtonPressed|
114 >                        ExposeWindow|ExposeRegion|UnmapWindow);
115 >        gwidth = mainframe.width;
116 >        gheight = mainframe.height-COMHEIGHT;
117 >        x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
118 >        x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
119          x_driver.inpready = 0;
120          cmdvec = x_comout;                      /* set error vectors */
121          if (wrnvec != NULL)
# Line 120 | Line 139 | x_close()                      /* close our display */
139          if (gwind != 0) {
140                  XDestroyWindow(gwind);
141                  gwind = 0;
123                gwidth = gheight = 0;
142          }
143          XFreeCursor(pickcursor);
144          freepixels();
# Line 134 | Line 152 | x_clear(xres, yres)                    /* clear our display */
152   int  xres, yres;
153   {
154          if (xres != gwidth || yres != gheight) {        /* new window */
155 <                if (comline != NULL)
138 <                        xt_close(comline);
139 <                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);
151 <                comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
152 <                if (comline == NULL)
153 <                        goto fail;
155 >                XChangeWindow(gwind, xres, yres+COMHEIGHT);
156                  gwidth = xres;
157                  gheight = yres;
158          } else                                          /* just clear */
159                  XClear(gwind);
160                                                  /* reinitialize color table */
161 <        if (ncolors == 0 && getpixels() == 0)
161 >        if (getpixels() == 0)
162                  stderr_v("cannot allocate colors\n");
163          else
164                  new_ctab(ncolors);
165 +                                                /* open new command line */
166 +        if (comline != NULL)
167 +                xt_close(comline);
168 +        comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
169 +        if (comline == NULL) {
170 +                stderr_v("Cannot open command line window\n");
171 +                quit(1);
172 +        }
173 +        XMapWindow(gwind);                      /* make sure it's mapped */
174          XSync(1);                               /* discard input */
175          return;
165 fail:
166        stderr_v("Failure opening window in x_clear\n");
167        quit(1);
176   }
177  
178  
# Line 173 | Line 181 | x_paintr(col, xmin, ymin, xmax, ymax)          /* fill a recta
181   COLOR  col;
182   int  xmin, ymin, xmax, ymax;
183   {
176        extern long  nrays;             /* global ray count */
184          extern int  xnewcolr();         /* pixel assignment routine */
178        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, xnewcolr)]);
189          }
184        if (nrays - lastflush >= WFLUSH) {
185                if (ncolors <= 0)       /* output necessary for death */
186                        XPixSet(gwind,0,0,1,1,BlackPixel);
187                checkinp();
188                lastflush = nrays;
189        }
190   }
191  
192  
193   static
194 < x_comin(inp)                    /* read in a command line */
195 < char  *inp;
194 > x_flush()                       /* flush output */
195   {
196 <        int  x_getc(), x_comout();
196 >        if (ncolors <= 0)       /* output necessary for death */
197 >                XPixSet(gwind,0,0,1,1,BlackPixel);
198 >        while (XPending() > 0)
199 >                getevent();
200  
201 + }
202 +
203 +
204 + static
205 + x_comin(inp, prompt)            /* read in a command line */
206 + char  *inp, *prompt;
207 + {
208 +        extern int  x_getc();
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 206 | Line 222 | static
222   x_comout(out)                   /* output a string to command line */
223   char  *out;
224   {
225 <        if (comline != NULL)
226 <                xt_puts(out, comline);
227 <        XFlush();
225 >        if (comline == NULL)
226 >                return;
227 >        xt_puts(out, comline);
228 >        if (out[strlen(out)-1] == '\n')
229 >                XFlush();
230   }
231  
232  
# Line 216 | Line 234 | static
234   x_errout(msg)                   /* output an error message */
235   char  *msg;
236   {
219        x_comout(msg);
237          stderr_v(msg);          /* send to stderr also! */
238 +        x_comout(msg);
239   }
240  
241  
# Line 272 | Line 290 | getpixels()                            /* get the color map */
290   {
291          int  planes;
292  
293 <        freepixels();
293 >        if (ncolors > 0)
294 >                return(ncolors);
295          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
296                  pixval = (int *)malloc(ncolors*sizeof(int));
297                  if (pixval == NULL)
# Line 317 | Line 336 | getevent()                     /* get next event */
336                  getkey(levptr(XKeyPressedEvent));
337                  break;
338          case ExposeWindow:
339 <                if (levptr(XExposeEvent)->subwindow == 0) {
340 <                        if (ncolors == 0 && getpixels() == 0) {
322 <                                stderr_v("cannot allocate colors\n");
323 <                                break;
324 <                        }
325 <                        new_ctab(ncolors);
326 <                }
327 <                /* fall through */
339 >                windowchange(levptr(XExposeEvent));
340 >                break;
341          case ExposeRegion:
342                  fixwindow(levptr(XExposeEvent));
343                  break;
# Line 339 | Line 352 | getevent()                     /* get next event */
352  
353  
354   static
355 + windowchange(eexp)                      /* process window change event */
356 + register XExposeEvent  *eexp;
357 + {
358 +        if (eexp->subwindow != 0) {
359 +                fixwindow(eexp);
360 +                return;
361 +        }
362 +                                        /* check for change in size */
363 +        if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) {
364 +                gwidth = eexp->width;
365 +                gheight = eexp->height-COMHEIGHT;
366 +                x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
367 +                x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
368 +                strcpy(getcombuf(&x_driver), "new\n");
369 +                return;
370 +        }
371 +                                        /* remap colors */
372 +        if (getpixels() == 0) {
373 +                stderr_v("cannot allocate colors\n");
374 +                return;
375 +        }
376 +        new_ctab(ncolors);
377 +                                        /* redraw */
378 +        fixwindow(eexp);
379 + }
380 +
381 +
382 + static
383   getkey(ekey)                            /* get input key */
384   register XKeyPressedEvent  *ekey;
385   {
# Line 346 | Line 387 | register XKeyPressedEvent  *ekey;
387          register char  *str;
388  
389          str = XLookupMapping(ekey, &n);
390 <        while (n-- > 0 && c_last < sizeof(c_queue))
390 >        while (n-- > 0 && c_last < sizeof(c_queue)) {
391                  c_queue[c_last++] = *str++;
392 <        x_driver.inpready = c_last - c_first;
392 >                x_driver.inpready++;
393 >        }
394   }
395  
396  
# Line 357 | Line 399 | fixwindow(eexp)                                /* repair damage to window */
399   register XExposeEvent  *eexp;
400   {
401          if (eexp->subwindow == 0)
402 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
402 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
403 >                        eexp->x, gheight - eexp->y - eexp->height,
404                          eexp->x + eexp->width, gheight - eexp->y);
405          else if (eexp->subwindow == comline->w)
406                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines