| 1 |
#ifndef lint
|
| 2 |
static char SCCSid[] = "$SunId$ LBL";
|
| 3 |
#endif
|
| 4 |
|
| 5 |
/*
|
| 6 |
* NeWS driver, by Isaac Kwo
|
| 7 |
*
|
| 8 |
* July 1990
|
| 9 |
*/
|
| 10 |
|
| 11 |
#include "standard.h"
|
| 12 |
#include "newsconstants.h"
|
| 13 |
#include "driver.h"
|
| 14 |
#include "nwsdev.h"
|
| 15 |
#include "color.h"
|
| 16 |
char inputbuffer[256];
|
| 17 |
int pos;
|
| 18 |
int gamma[257];
|
| 19 |
|
| 20 |
static int nws_close(),nws_clear(),nws_painter(),nws_getclick(),
|
| 21 |
nws_printer(),nws_getinput(),nws_flush(),nws_errout(),
|
| 22 |
nws_gpainter();
|
| 23 |
static struct driver nws_driver =
|
| 24 |
{
|
| 25 |
nws_close,nws_clear,nws_gpainter,nws_getclick,
|
| 26 |
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 |
gamma[i]=500*pow(i/256.,1./gammacorrection);
|
| 53 |
ps_open_PostScript();
|
| 54 |
sgicheck(&i);
|
| 55 |
if(i)nws_driver.paintr=nws_painter;
|
| 56 |
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 |
erract[COMMAND].pf=nws_printer;
|
| 65 |
if(erract[WARNING].pf!=NULL)erract[WARNING].pf=nws_errout;
|
| 66 |
return(&nws_driver);
|
| 67 |
}
|
| 68 |
|
| 69 |
static int
|
| 70 |
nws_close() /* close the display */
|
| 71 |
{
|
| 72 |
erract[COMMAND].pf=NULL;
|
| 73 |
if(erract[WARNING].pf!=NULL)erract[WARNING].pf=wputs;
|
| 74 |
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 |
eputs(msg);
|
| 91 |
nws_printer(msg);
|
| 92 |
}
|
| 93 |
|
| 94 |
static int
|
| 95 |
nws_painter(col,xmin,ymin,xmax,ymax)
|
| 96 |
COLOR col;
|
| 97 |
int xmin,ymin,xmax,ymax;
|
| 98 |
{
|
| 99 |
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 |
int i;
|
| 108 |
int col2[3];
|
| 109 |
for(i=0;i<3;i++)
|
| 110 |
{
|
| 111 |
col2[i]=256.*col[i];
|
| 112 |
if(col2[i]>255)col2[i]=255;
|
| 113 |
col2[i]=gamma[col2[i]];
|
| 114 |
}
|
| 115 |
box(xmin,ymin+textareaheight,xmax,ymax+textareaheight
|
| 116 |
,col2[0],col2[1],col2[2]);
|
| 117 |
}
|
| 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 |
}
|