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.12 by greg, Mon Oct 2 17:12:39 1989 UTC vs.
Revision 1.19 by greg, Mon Jan 8 14:45:05 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   int  x_close(), x_clear(), x_paintr(), x_errout(),
70                  x_getcur(), x_comout(), x_comin();
71  
72   static struct driver  x_driver = {
73          x_close, x_clear, x_paintr, x_getcur,
74 <        x_comout, x_comin,
76 <        MAXRES, MAXRES
74 >        x_comout, x_comin, 1.0
75   };
76  
77  
78   struct driver *
79 < x_init(name)                    /* initialize driver */
80 < char  *name;
79 > x_init(name, id)                /* initialize driver */
80 > char  *name, *id;
81   {
82 +        char  defgeom[32];
83 +        OpaqueFrame  mainframe;
84 +
85          ourdisplay = XOpenDisplay(NULL);
86          if (ourdisplay == NULL) {
87                  stderr_v("cannot open X-windows; DISPLAY variable set?\n");
# Line 90 | Line 91 | char  *name;
91                  stderr_v("not enough colors\n");
92                  return(NULL);
93          }
94 <        make_cmap(GAMMA);                       /* make color map */
94 <        if (getpixels() < 0)                    /* get pixels */
95 <                stderr_v("cannot allocate colors\n");
94 >        make_gmap(GAMMA);                       /* make color map */
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 = name;
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 driver", name, 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 >        XMapWindow(gwind);
113 >        XSelectInput(gwind, KeyPressed|ButtonPressed|
114 >                        ExposeWindow|ExposeRegion|UnmapWindow);
115 >        x_driver.xsiz = mainframe.width;
116 >        x_driver.ysiz = mainframe.height-COMHEIGHT;
117          x_driver.inpready = 0;
118          cmdvec = x_comout;                      /* set error vectors */
119          if (wrnvec != NULL)
# Line 135 | Line 150 | static
150   x_clear(xres, yres)                     /* clear our display */
151   int  xres, yres;
152   {
153 +        if (xres < MINWIDTH)
154 +                xres = MINWIDTH;
155 +        if (yres < MINHEIGHT)
156 +                yres = MINHEIGHT;
157          if (xres != gwidth || yres != gheight) {        /* new window */
158                  if (comline != NULL)
159                          xt_close(comline);
160 <                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;
160 >                XChangeWindow(gwind, xres, yres+COMHEIGHT);
161                  comline = xt_open(gwind, 0, yres, xres, COMHEIGHT, 0, COMFN);
162 <                if (comline == NULL)
163 <                        goto fail;
164 <                XMapWindow(gwind);
165 <                XSelectInput(gwind,
153 <        KeyPressed|ButtonPressed|ExposeWindow|ExposeRegion|UnmapWindow);
154 <                XStoreName(gwind, clientname);
162 >                if (comline == NULL) {
163 >                        stderr_v("Cannot open command line window\n");
164 >                        quit(1);
165 >                }
166                  gwidth = xres;
167                  gheight = yres;
168          } else                                          /* just clear */
169                  XClear(gwind);
170 <        if (newtab() < 0) {
171 <                stderr_v("Color allocation error\n");
172 <                quit(1);
173 <        }
174 <        checkinp();
170 >                                                /* reinitialize color table */
171 >        if (ncolors == 0 && getpixels() == 0)
172 >                stderr_v("cannot allocate colors\n");
173 >        else
174 >                new_ctab(ncolors);
175 >        XSync(1);                               /* discard input */
176          return;
165 fail:
166        stderr_v("Failure opening window in x_clear\n");
167        quit(1);
177   }
178  
179  
# Line 174 | Line 183 | COLOR  col;
183   int  xmin, ymin, xmax, ymax;
184   {
185          extern long  nrays;             /* global ray count */
186 +        extern int  xnewcolr();         /* pixel assignment routine */
187          static long  lastflush = 0;     /* ray count at last flush */
188  
189          if (ncolors > 0) {
190                  XPixSet(gwind, xmin, gheight-ymax, xmax-xmin, ymax-ymin,
191 <                                pixval[get_pixel(col)]);
191 >                                pixval[get_pixel(col, xnewcolr)]);
192          }
193          if (nrays - lastflush >= WFLUSH) {
194                  if (ncolors <= 0)       /* output necessary for death */
# Line 195 | Line 205 | char  *inp;
205   {
206          int  x_getc(), x_comout();
207  
208 +        if (fromcombuf(inp, &x_driver))
209 +                return;
210          xt_cursor(comline, TBLKCURS);
211          editline(inp, x_getc, x_comout);
212          xt_cursor(comline, TNOCURS);
# Line 251 | Line 263 | int  *xp, *yp;
263  
264  
265   static
266 < newcolr(ndx, clr)               /* enter a color into hardware table */
266 > xnewcolr(ndx, r, g, b)          /* enter a color into hardware table */
267   int  ndx;
268 < COLR  clr;
268 > int  r, g, b;
269   {
270          Color  xcolor;
271  
272          xcolor.pixel = pixval[ndx];
273 <        xcolor.red = clr[RED] << 8;
274 <        xcolor.green = clr[GRN] << 8;
275 <        xcolor.blue = clr[BLU] << 8;
273 >        xcolor.red = r << 8;
274 >        xcolor.green = g << 8;
275 >        xcolor.blue = b << 8;
276  
277          XStoreColor(&xcolor);
278   }
279  
280  
281 < static
270 < newtab()                        /* assign new color table */
271 < {
272 <        extern COLR     *get_ctab();
273 <        COLR    *ctab;
274 <        Color   *defs;
275 <        register int    i;
276 <
277 <        if ((ctab = get_ctab(ncolors)) == NULL)
278 <                return(-1);
279 <        if ((defs = (Color *)malloc(ncolors*sizeof(Color))) == NULL)
280 <                return(-1);
281 <        for (i = 0; i < ncolors; i++) {
282 <                defs[i].pixel = pixval[i];
283 <                defs[i].red = ctab[i][RED] << 8;
284 <                defs[i].green = ctab[i][GRN] << 8;
285 <                defs[i].blue = ctab[i][BLU] << 8;
286 <        }
287 <        XStoreColors(ncolors, defs);
288 <        free((char *)defs);
289 <        return(0);
290 < }
291 <
292 <
293 < static
281 > static int
282   getpixels()                             /* get the color map */
283   {
284          int  planes;
285  
286 +        freepixels();
287          for (ncolors=(1<<DisplayPlanes())-3; ncolors>12; ncolors=ncolors*.937){
288                  pixval = (int *)malloc(ncolors*sizeof(int));
289                  if (pixval == NULL)
290                          break;
291                  if (XGetColorCells(0,ncolors,0,&planes,pixval) != 0)
292 <                        return(0);
292 >                        return(ncolors);
293                  free((char *)pixval);
294          }
295 <        ncolors = 0;
307 <        return(-1);
295 >        return(ncolors = 0);
296   }
297  
298  
# Line 340 | Line 328 | getevent()                     /* get next event */
328                  getkey(levptr(XKeyPressedEvent));
329                  break;
330          case ExposeWindow:
331 <                if (ncolors == 0 && levptr(XExposeEvent)->subwindow == 0)
332 <                        if (getpixels() < 0)
345 <                                stderr_v("cannot grab colors\n");
346 <                        else
347 <                                newtab();
348 <                /* fall through */
331 >                windowchange(levptr(XExposeEvent));
332 >                break;
333          case ExposeRegion:
334                  fixwindow(levptr(XExposeEvent));
335                  break;
# Line 360 | Line 344 | getevent()                     /* get next event */
344  
345  
346   static
347 + windowchange(eexp)                      /* process window change event */
348 + register XExposeEvent  *eexp;
349 + {
350 +        if (eexp->subwindow != 0) {
351 +                fixwindow(eexp);
352 +                return;
353 +        }
354 +                                        /* check for change in size */
355 +        if (eexp->width != gwidth || eexp->height-COMHEIGHT != gheight) {
356 +                x_driver.xsiz = eexp->width;
357 +                x_driver.ysiz = eexp->height-COMHEIGHT;
358 +                strcpy(getcombuf(&x_driver), "new\n");
359 +                return;
360 +        }
361 +                                        /* remap colors */
362 +        if (ncolors == 0 && getpixels() == 0) {
363 +                stderr_v("cannot allocate colors\n");
364 +                return;
365 +        }
366 +        new_ctab(ncolors);
367 +                                        /* redraw */
368 +        fixwindow(eexp);
369 + }
370 +
371 +
372 + static
373   getkey(ekey)                            /* get input key */
374   register XKeyPressedEvent  *ekey;
375   {
# Line 378 | Line 388 | fixwindow(eexp)                                /* repair damage to window */
388   register XExposeEvent  *eexp;
389   {
390          if (eexp->subwindow == 0)
391 <                repaint(eexp->x, gheight - eexp->y - eexp->height,
391 >                sprintf(getcombuf(&x_driver), "repaint %d %d %d %d\n",
392 >                        eexp->x, gheight - eexp->y - eexp->height,
393                          eexp->x + eexp->width, gheight - eexp->y);
394          else if (eexp->subwindow == comline->w)
395                  xt_redraw(comline);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines