ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/nwsdev.c
Revision: 2.3
Committed: Sat Feb 22 02:07:29 2003 UTC (22 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.2: +0 -0 lines
State: FILE REMOVED
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2     static char SCCSid[] = "$SunId$ LBL";
3     #endif
4    
5     /*
6 greg 1.2 * NeWS driver, by Isaac Kwo
7 greg 1.1 *
8     * July 1990
9     */
10    
11 gregl 2.2 #include "standard.h"
12 greg 1.1 #include "newsconstants.h"
13     #include "driver.h"
14     #include "nwsdev.h"
15 greg 1.3 #include "color.h"
16 greg 1.1 char inputbuffer[256];
17     int pos;
18 greg 1.3 int gamma[257];
19 greg 1.1
20     static int nws_close(),nws_clear(),nws_painter(),nws_getclick(),
21 greg 1.3 nws_printer(),nws_getinput(),nws_flush(),nws_errout(),
22     nws_gpainter();
23 greg 1.1 static struct driver nws_driver =
24     {
25 greg 1.3 nws_close,nws_clear,nws_gpainter,nws_getclick,
26 greg 1.1 nws_printer,nws_getinput,nws_flush,1.0
27     };
28    
29     static int
30     nws_clear()
31     {
32     cps_clear();
33     }
34    
35     static int
36     nws_getclick(xp,yp)
37     int *xp,*yp;
38     {
39     int key;
40     cps_getclick(xp,yp,&key);
41     nws_driver.inpready=0;
42     return(key);
43     }
44    
45     struct driver *
46     nws_init(name,id) /* initialize driver */
47     char *name,*id;
48     {
49     int wX,wY,wW,wH,i;
50     gamma[256]=1;
51     for(i=0;i<256;i++)
52 greg 1.3 gamma[i]=500*pow(i/256.,1./gammacorrection);
53 greg 1.1 ps_open_PostScript();
54 greg 1.3 sgicheck(&i);
55     if(i)nws_driver.paintr=nws_painter;
56 greg 1.1 getthebox(&wX,&wY,&wW,&wH);
57     if(wW<100)wW=100;
58     if(wH<100+textareaheight)wH=100+textareaheight;
59     cps_initcanvas
60     (wX,wY,wW,wH,(int)MB1,(int)MB2,(int)MB3);
61     nws_driver.xsiz=wW;
62     nws_driver.ysiz=wH-textareaheight;
63     nws_driver.inpready=0;
64 gregl 2.2 erract[COMMAND].pf=nws_printer;
65     if(erract[WARNING].pf!=NULL)erract[WARNING].pf=nws_errout;
66 greg 1.1 return(&nws_driver);
67     }
68    
69     static int
70     nws_close() /* close the display */
71     {
72 gregl 2.2 erract[COMMAND].pf=NULL;
73     if(erract[WARNING].pf!=NULL)erract[WARNING].pf=wputs;
74 greg 1.1 cps_cleanup();
75     ps_flush_PostScript();
76     ps_close_PostScript();
77     }
78    
79     static int
80     nws_flush() /* flush output and check for keyboard input */
81     {
82     ps_flush_PostScript();
83     isready(&(nws_driver.inpready));
84     }
85    
86     static int
87     nws_errout(msg) /* output an error message */
88     char *msg; /* my comments are so bogus */
89     {
90 gregl 2.2 eputs(msg);
91 greg 1.1 nws_printer(msg);
92     }
93    
94     static int
95     nws_painter(col,xmin,ymin,xmax,ymax)
96 greg 1.3 COLOR col;
97 greg 1.1 int xmin,ymin,xmax,ymax;
98     {
99 greg 1.3 box(xmin,ymin+textareaheight,xmax,ymax+textareaheight
100     ,(int)(500*col[RED]),(int)(500*col[GRN]),(int)(500*col[BLU]));
101     }
102     static int
103     nws_gpainter(col,xmin,ymin,xmax,ymax)
104     COLOR col;
105     int xmin,ymin,xmax,ymax;
106     {
107 greg 1.1 int i;
108 greg 1.3 int col2[3];
109 greg 1.1 for(i=0;i<3;i++)
110     {
111 greg 1.3 col2[i]=256.*col[i];
112     if(col2[i]>255)col2[i]=255;
113     col2[i]=gamma[col2[i]];
114 greg 1.1 }
115     box(xmin,ymin+textareaheight,xmax,ymax+textareaheight
116 greg 1.2 ,col2[0],col2[1],col2[2]);
117 greg 1.1 }
118     static int
119     nws_printer(orig) /* printer recognises \n as a linefeed */
120     char *orig;
121     {
122     char *m,*s,string[BUFSIZ]; /* s is for string and m is for message */
123     m=s=string;
124     while((*(s++))=(*(orig++)));
125     s=string;
126     while(*s)
127     if(*s++=='\n')
128     {
129     *(s-1)=0;
130     linefeed(m);
131     m=s;
132     }
133     printout(m);
134     }
135    
136     static int
137     mygetc()
138     {
139     int key;
140     getkey(&key);
141     return(key);
142     }
143     static int
144     myputs(str)
145     char *str;
146     {
147     char buf[2]; buf[1]=0;
148     for(;*str;str++)
149     switch(*str)
150     {
151     case '\n': pos=0; linefeed(""); break;
152     case '\b':
153     buf[0]=inputbuffer[--pos];
154     delete(buf);
155     break;
156     default:
157     buf[0]=inputbuffer[pos++]=(*str);
158     printout(buf);
159     break;
160     }
161     return(0);
162     }
163     static int
164     nws_getinput(s,prompt)
165     char s[BUFSIZ];
166     {
167     if(prompt)nws_printer(prompt);
168     startcomin();
169     pos=0;
170     editline(s,mygetc,myputs);
171     endcomin();
172     nws_driver.inpready=0;
173     }