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.5 by greg, Tue Sep 20 15:50:00 1994 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines