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.22 by greg, Tue Jan 30 09:47:21 1990 UTC vs.
Revision 2.6 by gregl, Tue Nov 11 20:03:02 1997 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     5/7/87
11   */
12  
13 < #include  <stdio.h>
13 > #include  "standard.h"
14  
15 #include  <sys/ioctl.h>
16
15   #include  <X/Xlib.h>
16   #include  <X/cursors/bcross.cursor>
17   #include  <X/cursors/bcross_mask.cursor>
# Line 29 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   #define BORWIDTH        5               /* border width */
28   #define COMHEIGHT       (COMLH*COMCH)   /* command line height (pixels) */
29   #define MINWIDTH        (32*COMCW)      /* minimum graphics window width */
30 < #define MINHEIGHT       64              /* minimum graphics window height */
30 > #define MINHEIGHT       MINWIDTH                /* minimum graphics window height */
31  
32   #define COMFN           "8x13"          /* command line font name */
33   #define COMLH           3               /* number of command lines */
34   #define COMCW           8               /* approx. character width (pixels) */
35   #define COMCH           13              /* approx. character height (pixels) */
36  
39 #ifndef WFLUSH
40 #define WFLUSH          30              /* flush after this many rays */
41 #endif
42
43 #define  checkinp()     while (XPending() > 0) getevent()
44
37   #define  levptr(etype)  ((etype *)&thisevent)
38  
39   static XEvent  thisevent;               /* current event */
# Line 55 | Line 47 | static Window  gwind = 0;              /* our graphics window */
47  
48   static Cursor  pickcursor = 0;          /* cursor used for picking */
49  
50 < static int  gwidth = 0;                 /* graphics window width */
59 < static int  gheight = 0;                /* graphics window height */
50 > static int  gwidth, gheight;            /* graphics window size */
51  
52   static TEXTWIND  *comline = NULL;       /* our command line */
53  
# Line 68 | Line 59 | extern char  *malloc(), *getcombuf();
59  
60   extern char  *progname;
61  
62 < int  x_close(), x_clear(), x_paintr(), x_errout(),
63 <                x_getcur(), x_comout(), x_comin();
62 > static int  x_close(), x_clear(), x_paintr(), x_errout(),
63 >                x_getcur(), x_comout(), x_comin(), x_flush();
64  
65   static struct driver  x_driver = {
66          x_close, x_clear, x_paintr, x_getcur,
67 <        x_comout, x_comin, 1.0
67 >        x_comout, x_comin, x_flush, 1.0
68   };
69  
70  
# Line 81 | Line 72 | struct driver *
72   x_init(name, id)                /* initialize driver */
73   char  *name, *id;
74   {
75 +        extern char  *getenv();
76 +        char  *gv;
77          char  defgeom[32];
78          OpaqueFrame  mainframe;
79  
80          ourdisplay = XOpenDisplay(NULL);
81          if (ourdisplay == NULL) {
82 <                stderr_v("cannot open X-windows; DISPLAY variable set?\n");
82 >                eputs("cannot open X-windows; DISPLAY variable set?\n");
83                  return(NULL);
84          }
85          if (DisplayPlanes() < 4) {
86 <                stderr_v("not enough colors\n");
86 >                eputs("not enough colors\n");
87                  return(NULL);
88          }
89 <        make_gmap(GAMMA);                       /* make color map */
89 >                                /* make color map */
90 >        if ((gv = getenv("DISPLAY_GAMMA")) != NULL)
91 >                make_gmap(atof(gv));
92 >        else
93 >                make_gmap(GAMMA);
94  
95          pickcursor = XCreateCursor(bcross_width, bcross_height,
96                          bcross_bits, bcross_mask_bits,
# Line 107 | Line 104 | char  *name, *id;
104          gwind = XCreate("X10 display driver", progname, NULL, defgeom,
105                          &mainframe, MINWIDTH, MINHEIGHT+COMHEIGHT);
106          if (gwind == 0) {
107 <                stderr_v("can't create window\n");
107 >                eputs("can't create window\n");
108                  return(NULL);
109          }
110          XStoreName(gwind, id);
114        XMapWindow(gwind);
111          XSelectInput(gwind, KeyPressed|ButtonPressed|
112                          ExposeWindow|ExposeRegion|UnmapWindow);
113 <        x_driver.xsiz = mainframe.width;
114 <        x_driver.ysiz = mainframe.height-COMHEIGHT;
113 >        gwidth = mainframe.width;
114 >        gheight = mainframe.height-COMHEIGHT;
115 >        x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
116 >        x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
117          x_driver.inpready = 0;
118 <        cmdvec = x_comout;                      /* set error vectors */
119 <        if (wrnvec != NULL)
120 <                wrnvec = x_errout;
118 >        erract[COMMAND].pf = x_comout;          /* set error vectors */
119 >        if (erract[WARNING].pf != NULL)
120 >                erract[WARNING].pf = x_errout;
121          return(&x_driver);
122   }
123  
# Line 127 | Line 125 | char  *name, *id;
125   static
126   x_close()                       /* close our display */
127   {
128 <        cmdvec = NULL;                          /* reset error vectors */
129 <        if (wrnvec != NULL)
130 <                wrnvec = stderr_v;
128 >        erract[COMMAND].pf = NULL;              /* reset error vectors */
129 >        if (erract[WARNING].pf != NULL)
130 >                erract[WARNING].pf = wputs;
131          if (ourdisplay == NULL)
132                  return;
133          if (comline != NULL) {
# Line 139 | Line 137 | x_close()                      /* close our display */
137          if (gwind != 0) {
138                  XDestroyWindow(gwind);
139                  gwind = 0;
142                gwidth = gheight = 0;
140          }
141          XFreeCursor(pickcursor);
142          freepixels();
# Line 152 | Line 149 | static
149   x_clear(xres, yres)                     /* clear our display */
150   int  xres, yres;
151   {
155        if (xres < MINWIDTH)
156                xres = MINWIDTH;
157        if (yres < MINHEIGHT)
158                yres = MINHEIGHT;
152          if (xres != gwidth || yres != gheight) {        /* new window */
160                if (comline != NULL)
161                        xt_close(comline);
153                  XChangeWindow(gwind, xres, yres+COMHEIGHT);
163                comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
164                if (comline == NULL) {
165                        stderr_v("Cannot open command line window\n");
166                        quit(1);
167                }
154                  gwidth = xres;
155                  gheight = yres;
156          } else                                          /* just clear */
157                  XClear(gwind);
158                                                  /* reinitialize color table */
159          if (getpixels() == 0)
160 <                stderr_v("cannot allocate colors\n");
160 >                eputs("cannot allocate colors\n");
161          else
162                  new_ctab(ncolors);
163 +                                                /* open new command line */
164 +        if (comline != NULL)
165 +                xt_close(comline);
166 +        comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
167 +        if (comline == NULL) {
168 +                eputs("Cannot open command line window\n");
169 +                quit(1);
170 +        }
171 +        XMapWindow(gwind);                      /* make sure it's mapped */
172          XSync(1);                               /* discard input */
173          return;
174   }
# Line 184 | Line 179 | x_paintr(col, xmin, ymin, xmax, ymax)          /* fill a recta
179   COLOR  col;
180   int  xmin, ymin, xmax, ymax;
181   {
187        extern long  nrays;             /* global ray count */
182          extern int  xnewcolr();         /* pixel assignment routine */
189        static long  lastflush = 0;     /* ray count at last flush */
183  
184          if (ncolors > 0) {
185                  XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin,
186                                  pixval[get_pixel(col, xnewcolr)]);
187          }
195        if (nrays - lastflush >= WFLUSH) {
196                if (ncolors <= 0)       /* output necessary for death */
197                        XPixSet(gwind,0,0,1,1,BlackPixel);
198                checkinp();
199                lastflush = nrays;
200        }
188   }
189  
190  
191   static
192 < x_comin(inp)                    /* read in a command line */
206 < char  *inp;
192 > x_flush()                       /* flush output */
193   {
194 <        int  x_getc(), x_comout();
194 >        if (ncolors <= 0)       /* output necessary for death */
195 >                XPixSet(gwind,0,0,1,1,BlackPixel);
196 >        while (XPending() > 0)
197 >                getevent();
198  
199 <        if (fromcombuf(inp, &x_driver))
200 <                return;
199 > }
200 >
201 >
202 > static
203 > x_comin(inp, prompt)            /* read in a command line */
204 > char  *inp, *prompt;
205 > {
206 >        extern int  x_getc();
207 >
208 >        if (prompt != NULL)
209 >                if (fromcombuf(inp, &x_driver))
210 >                        return;
211 >                else
212 >                        xt_puts(prompt, comline);
213          xt_cursor(comline, TBLKCURS);
214          editline(inp, x_getc, x_comout);
215          xt_cursor(comline, TNOCURS);
# Line 219 | Line 220 | static
220   x_comout(out)                   /* output a string to command line */
221   char  *out;
222   {
223 <        if (comline != NULL)
224 <                xt_puts(out, comline);
225 <        XFlush();
223 >        if (comline == NULL)
224 >                return;
225 >        xt_puts(out, comline);
226 >        if (out[strlen(out)-1] == '\n')
227 >                XFlush();
228   }
229  
230  
# Line 229 | Line 232 | static
232   x_errout(msg)                   /* output an error message */
233   char  *msg;
234   {
235 +        eputs(msg);             /* send to stderr also! */
236          x_comout(msg);
233        stderr_v(msg);          /* send to stderr also! */
237   }
238  
239  
# Line 356 | Line 359 | register XExposeEvent  *eexp;
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;
362 >                gwidth = eexp->width;
363 >                gheight = eexp->height-COMHEIGHT;
364 >                x_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth;
365 >                x_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight;
366                  strcpy(getcombuf(&x_driver), "new\n");
367                  return;
368          }
369                                          /* remap colors */
370          if (getpixels() == 0) {
371 <                stderr_v("cannot allocate colors\n");
371 >                eputs("cannot allocate colors\n");
372                  return;
373          }
374          new_ctab(ncolors);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines