Revision Log
Revision: 1.1 - (view) (download) (as text)
| 1 : | ktanaka | 1.1 | #include <stdio.h> |
| 2 : | #include <alloca.h> | ||
| 3 : | #include <X11/Xlib.h> | ||
| 4 : | #include <X11/Xutil.h> | ||
| 5 : | #include <constdef.h> | ||
| 6 : | #include <sys/file.h> | ||
| 7 : | #include <sys/stat.h> | ||
| 8 : | #include <ctype.h> | ||
| 9 : | #ifdef DEBUG | ||
| 10 : | #define MAIN | ||
| 11 : | #endif | ||
| 12 : | #include <defvar.h> | ||
| 13 : | #include <cmpdef.h> | ||
| 14 : | |||
| 15 : | static WORD init_window_f(),drawline_f(),redraw_f(),checkevent_f(),close_window_f(); | ||
| 16 : | static WORD fillpolygon_f(),drawlines_f(),loadpbm_f(),loadjis_f(),copybg_f(); | ||
| 17 : | static WORD getimage_f(),getpixel_f(),fillrectangle_f(),freeimage_f(); | ||
| 18 : | |||
| 19 : | static struct code_inf init_window_info={0,0,0,0,init_window_f,"init_window "}; | ||
| 20 : | static struct code_inf drawline_info={0,0,0,0,drawline_f,"drawline "}; | ||
| 21 : | static struct code_inf redraw_info={0,0,0,0,redraw_f,"redraw "}; | ||
| 22 : | static struct code_inf checkevent_info={0,6,0,0,checkevent_f,"checkevent ButtonPress ButtonRelease button1 button2 button3 KeyPress "}; | ||
| 23 : | static struct code_inf close_window_info={0,0,0,0,close_window_f,"close_window "}; | ||
| 24 : | static struct code_inf fillpolygon_info={0,0,0,0,fillpolygon_f,"fillpolygon "}; | ||
| 25 : | static struct code_inf drawlines_info={0,0,0,0,drawlines_f,"drawlines "}; | ||
| 26 : | static struct code_inf loadpbm_info={0,0,0,0,loadpbm_f,"loadpbm "}; | ||
| 27 : | static struct code_inf loadjis_info={0,0,0,0,loadjis_f,"loadjis "}; | ||
| 28 : | static struct code_inf copybg_info={0,0,0,0,copybg_f,"copybg "}; | ||
| 29 : | static struct code_inf getpixel_info={0,0,0,0,getpixel_f,"getpixel "}; | ||
| 30 : | static struct code_inf getimage_info={0,0,0,0,getimage_f,"getimage "}; | ||
| 31 : | static struct code_inf freeimage_info={0,0,0,0,freeimage_f,"freeimage "}; | ||
| 32 : | static struct code_inf fillrectangle_info={0,0,0,0,fillrectangle_f,"fillrectangle "}; | ||
| 33 : | static struct code_inf *inf_array[]={ | ||
| 34 : | &init_window_info, | ||
| 35 : | &drawline_info, | ||
| 36 : | &redraw_info, | ||
| 37 : | &checkevent_info, | ||
| 38 : | &close_window_info, | ||
| 39 : | &fillpolygon_info, | ||
| 40 : | &drawlines_info, | ||
| 41 : | &loadpbm_info, | ||
| 42 : | &loadjis_info, | ||
| 43 : | ©bg_info, | ||
| 44 : | &getpixel_info, | ||
| 45 : | &getimage_info, | ||
| 46 : | &freeimage_info, | ||
| 47 : | &fillrectangle_info, | ||
| 48 : | (struct code_inf *)0 | ||
| 49 : | }; | ||
| 50 : | WORD init_code_window(fp) | ||
| 51 : | WORD *fp; | ||
| 52 : | { | ||
| 53 : | WORD make_codepiece(); | ||
| 54 : | |||
| 55 : | return(make_codepiece(inf_array,fp)); | ||
| 56 : | } | ||
| 57 : | |||
| 58 : | /* init_window width, height */ | ||
| 59 : | static XWMHints xwmh={ | ||
| 60 : | (InputHint|StateHint), | ||
| 61 : | False, | ||
| 62 : | NormalState, | ||
| 63 : | 0,0,0,0,0,0,}; | ||
| 64 : | static Display *dpy; | ||
| 65 : | static Window win; | ||
| 66 : | static GC curgc,white_gc,gray_gc; | ||
| 67 : | static int w_width,w_height; | ||
| 68 : | static XEvent event; | ||
| 69 : | static Pixmap save,background; | ||
| 70 : | static XSetWindowAttributes xswa; | ||
| 71 : | static Colormap cmap; | ||
| 72 : | static unsigned long pad,fg,bg,bd,bw; | ||
| 73 : | static char *av[1]={"utilisp"}; | ||
| 74 : | |||
| 75 : | static char tilebitmap[]={0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55}; | ||
| 76 : | static Pixmap tilepixmap; | ||
| 77 : | int flag; | ||
| 78 : | |||
| 79 : | static WORD init_window_f(na,fp) | ||
| 80 : | WORD *fp; | ||
| 81 : | { | ||
| 82 : | WORD a; | ||
| 83 : | XSizeHints xsh; | ||
| 84 : | XGCValues gcv; | ||
| 85 : | |||
| 86 : | if(na<2)parerr(); | ||
| 87 : | flag=1; | ||
| 88 : | if(na==3){ | ||
| 89 : | a=ag(0); | ||
| 90 : | fp++; | ||
| 91 : | if(a!=nil)flag=0; | ||
| 92 : | } | ||
| 93 : | w_width=fixtoi(checkfix(a,ag(1))); | ||
| 94 : | w_height=fixtoi(checkfix(a,ag(0))); | ||
| 95 : | if((dpy=XOpenDisplay(NULL))==NULL){ | ||
| 96 : | fprintf(stderr," can't open %s\n",XDisplayName(NULL)); | ||
| 97 : | exit(1); | ||
| 98 : | } | ||
| 99 : | fg=BlackPixel(dpy,DefaultScreen(dpy)); | ||
| 100 : | bg=WhitePixel(dpy,DefaultScreen(dpy)); | ||
| 101 : | if(flag){ | ||
| 102 : | xsh.flags=(PPosition|PSize); | ||
| 103 : | xsh.height=w_height+2; | ||
| 104 : | xsh.width=w_width+2; | ||
| 105 : | xsh.x=(DisplayWidth(dpy,DefaultScreen(dpy))-xsh.width)/2; | ||
| 106 : | xsh.y=(DisplayHeight(dpy,DefaultScreen(dpy))-xsh.height)/2; | ||
| 107 : | win=XCreateSimpleWindow(dpy,DefaultRootWindow(dpy), | ||
| 108 : | xsh.x,xsh.y,xsh.width,xsh.height,bw,bd,bg); | ||
| 109 : | XSetStandardProperties(dpy,win,"utilisp","utilisp",None,av,1,&xsh); | ||
| 110 : | XSetWMHints(dpy,win,&xwmh); | ||
| 111 : | cmap=xswa.colormap=DefaultColormap(dpy,DefaultScreen(dpy)); | ||
| 112 : | xswa.bit_gravity=CenterGravity; | ||
| 113 : | XChangeWindowAttributes(dpy,win,(CWColormap|CWBitGravity),&xswa); | ||
| 114 : | } | ||
| 115 : | else win=DefaultRootWindow(dpy); | ||
| 116 : | gcv.function=GXcopy; | ||
| 117 : | gcv.foreground=fg; | ||
| 118 : | gcv.fill_rule=WindingRule; | ||
| 119 : | curgc=XCreateGC(dpy,win,(GCFunction|GCForeground|GCFillRule),&gcv); | ||
| 120 : | gcv.function=GXcopy; | ||
| 121 : | gcv.foreground=bg; | ||
| 122 : | white_gc=XCreateGC(dpy,win,(GCFunction|GCForeground),&gcv); | ||
| 123 : | gcv.function=GXcopy; | ||
| 124 : | gcv.foreground=fg; | ||
| 125 : | gcv.fill_rule=WindingRule; | ||
| 126 : | gcv.fill_style=FillTiled; | ||
| 127 : | tilepixmap=XCreatePixmapFromBitmapData(dpy,win,tilebitmap,8,8,fg,bg,DefaultDepth(dpy,DefaultScreen(dpy))); | ||
| 128 : | gcv.tile=tilepixmap; | ||
| 129 : | gray_gc=XCreateGC(dpy,win,(GCFunction|GCForeground|GCFillRule|GCFillStyle|GCTile),&gcv); | ||
| 130 : | save=XCreatePixmap(dpy,DefaultRootWindow(dpy),w_width,w_height,DefaultDepth(dpy,DefaultScreen(dpy))); | ||
| 131 : | XFillRectangle(dpy,save,white_gc,0,0,w_width,w_height); | ||
| 132 : | if(flag){ | ||
| 133 : | XSelectInput(dpy,win,ExposureMask|ButtonPressMask|ButtonReleaseMask|KeyPressMask); | ||
| 134 : | XCopyArea(dpy,save,win,curgc,0,0,w_width,w_height,0,0); | ||
| 135 : | XMapWindow(dpy,win); | ||
| 136 : | } | ||
| 137 : | return(nil); | ||
| 138 : | } | ||
| 139 : | |||
| 140 : | static WORD drawline_f(na,fp) | ||
| 141 : | WORD *fp; | ||
| 142 : | { | ||
| 143 : | WORD a; | ||
| 144 : | int x0,y0,x1,y1; | ||
| 145 : | |||
| 146 : | if(na!=4)parerr(); | ||
| 147 : | x0=fixtoi(checkfix(a,ag(3))); | ||
| 148 : | y0=fixtoi(checkfix(a,ag(2))); | ||
| 149 : | x1=fixtoi(checkfix(a,ag(1))); | ||
| 150 : | y1=fixtoi(checkfix(a,ag(0))); | ||
| 151 : | XDrawLine(dpy,save,curgc,x0,y0,x1,y1); | ||
| 152 : | return(nil); | ||
| 153 : | } | ||
| 154 : | |||
| 155 : | static WORD redraw_f(na,fp) | ||
| 156 : | WORD *fp; | ||
| 157 : | { | ||
| 158 : | WORD a; | ||
| 159 : | |||
| 160 : | if(na!=0)parerr(); | ||
| 161 : | if(flag) | ||
| 162 : | XCopyArea(dpy,save,win,curgc,0,0,w_width,w_height,0,0); | ||
| 163 : | return(nil); | ||
| 164 : | } | ||
| 165 : | |||
| 166 : | static WORD checkevent_f(na,fp) | ||
| 167 : | WORD *fp; | ||
| 168 : | { | ||
| 169 : | WORD a; | ||
| 170 : | unsigned char c_buf; | ||
| 171 : | XComposeStatus status; | ||
| 172 : | KeySym last_key; | ||
| 173 : | |||
| 174 : | if(na!=0)parerr(); | ||
| 175 : | if(!flag)return(nil); | ||
| 176 : | while(1){ | ||
| 177 : | XNextEvent(dpy,&event); | ||
| 178 : | if(event.type==Expose && event.xexpose.count==0){ | ||
| 179 : | XCopyArea(dpy,save,win,curgc,0,0,w_width,w_height,0,0); | ||
| 180 : | } | ||
| 181 : | else if(event.type==KeyPress){ | ||
| 182 : | XLookupString(&event, &c_buf, 1, &last_key, &status); | ||
| 183 : | l(0)=lit(5); | ||
| 184 : | l(1)=itofix(c_buf); | ||
| 185 : | return(allist(2,fp-2,nil)); | ||
| 186 : | } | ||
| 187 : | else if(event.type==ButtonPress){ | ||
| 188 : | if(event.xbutton.button==Button1){ | ||
| 189 : | l(0)=lit(0); | ||
| 190 : | l(1)=lit(2); | ||
| 191 : | l(2)=itofix(event.xbutton.x); | ||
| 192 : | l(3)=itofix(event.xbutton.y); | ||
| 193 : | return(allist(4,fp-4,nil)); | ||
| 194 : | } | ||
| 195 : | if(event.xbutton.button==Button2){ | ||
| 196 : | l(0)=lit(0); | ||
| 197 : | l(1)=lit(3); | ||
| 198 : | l(2)=itofix(event.xbutton.x); | ||
| 199 : | l(3)=itofix(event.xbutton.y); | ||
| 200 : | return(allist(4,fp-4,nil)); | ||
| 201 : | } | ||
| 202 : | if(event.xbutton.button==Button3){ | ||
| 203 : | l(0)=lit(0); | ||
| 204 : | l(1)=lit(4); | ||
| 205 : | l(2)=itofix(event.xbutton.x); | ||
| 206 : | l(3)=itofix(event.xbutton.y); | ||
| 207 : | return(allist(4,fp-4,nil)); | ||
| 208 : | } | ||
| 209 : | } | ||
| 210 : | else if(event.type==ButtonRelease){ | ||
| 211 : | if(event.xbutton.button==Button1){ | ||
| 212 : | l(0)=lit(1); | ||
| 213 : | l(1)=lit(2); | ||
| 214 : | l(2)=itofix(event.xbutton.x); | ||
| 215 : | l(3)=itofix(event.xbutton.y); | ||
| 216 : | return(allist(4,fp-4,nil)); | ||
| 217 : | } | ||
| 218 : | if(event.xbutton.button==Button2){ | ||
| 219 : | l(0)=lit(1); | ||
| 220 : | l(1)=lit(3); | ||
| 221 : | l(2)=itofix(event.xbutton.x); | ||
| 222 : | l(3)=itofix(event.xbutton.y); | ||
| 223 : | return(allist(4,fp-4,nil)); | ||
| 224 : | } | ||
| 225 : | if(event.xbutton.button==Button3){ | ||
| 226 : | l(0)=lit(1); | ||
| 227 : | l(1)=lit(4); | ||
| 228 : | l(2)=itofix(event.xbutton.x); | ||
| 229 : | l(3)=itofix(event.xbutton.y); | ||
| 230 : | return(allist(4,fp-4,nil)); | ||
| 231 : | } | ||
| 232 : | } | ||
| 233 : | } | ||
| 234 : | } | ||
| 235 : | |||
| 236 : | static WORD close_window_f(na,fp) | ||
| 237 : | WORD *fp; | ||
| 238 : | { | ||
| 239 : | if(na!=0)parerr(); | ||
| 240 : | XCloseDisplay(dpy); | ||
| 241 : | return(nil); | ||
| 242 : | } | ||
| 243 : | |||
| 244 : | static WORD fillpolygon_f(na,fp) | ||
| 245 : | WORD *fp; | ||
| 246 : | { | ||
| 247 : | int npoints,i; | ||
| 248 : | WORD a,b; | ||
| 249 : | XPoint *points; | ||
| 250 : | |||
| 251 : | if(na!=1)parerr(); | ||
| 252 : | for(npoints=0,a=ag(0);tag(a)==CONS;npoints++,a=cdr(a)); | ||
| 253 : | points=(XPoint *)alloca(npoints*sizeof(XPoint)); | ||
| 254 : | for(i=0,a=ag(0);tag(a)==CONS;i++,a=cdr(a)){ | ||
| 255 : | points[i].x=fixtoi(checkfix(b,car(car(a)))); | ||
| 256 : | points[i].y=fixtoi(checkfix(b,cdr(car(a)))); | ||
| 257 : | } | ||
| 258 : | XFillPolygon(dpy,save,curgc,points,npoints,Complex,CoordModeOrigin); | ||
| 259 : | return(nil); | ||
| 260 : | } | ||
| 261 : | |||
| 262 : | static WORD drawlines_f(na,fp) | ||
| 263 : | WORD *fp; | ||
| 264 : | { | ||
| 265 : | int npoints,i; | ||
| 266 : | WORD a,b; | ||
| 267 : | XPoint *points; | ||
| 268 : | |||
| 269 : | if(na!=1)parerr(); | ||
| 270 : | for(npoints=0,a=ag(0);tag(a)==CONS;npoints++,a=cdr(a)); | ||
| 271 : | points=(XPoint *)alloca(npoints*sizeof(XPoint)); | ||
| 272 : | for(i=0,a=ag(0);tag(a)==CONS;i++,a=cdr(a)){ | ||
| 273 : | points[i].x=fixtoi(checkfix(b,car(car(a)))); | ||
| 274 : | points[i].y=fixtoi(checkfix(b,cdr(car(a)))); | ||
| 275 : | } | ||
| 276 : | XDrawLines(dpy,save,curgc,points,npoints,CoordModeOrigin); | ||
| 277 : | return(nil); | ||
| 278 : | } | ||
| 279 : | static unsigned char revtable[256]; | ||
| 280 : | static makerevbit() | ||
| 281 : | { | ||
| 282 : | int i,j,k; | ||
| 283 : | |||
| 284 : | for(i=0;i<256;i++){ | ||
| 285 : | for(k=j=0;j<8;j++) | ||
| 286 : | if((i>>j)&1)k|=1<<(7-j); | ||
| 287 : | revtable[i]=k; | ||
| 288 : | } | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | static revbit(buf,width,height) | ||
| 292 : | unsigned char *buf; | ||
| 293 : | { | ||
| 294 : | int i,j; | ||
| 295 : | |||
| 296 : | makerevbit(); | ||
| 297 : | for(j=0;j<height;j++){ | ||
| 298 : | if(j&1) | ||
| 299 : | for(i=0;i<width/8;i++) | ||
| 300 : | buf[i+j*width/8]= revtable[buf[i+j*width/8]]&0xaa; | ||
| 301 : | else | ||
| 302 : | for(i=0;i<width/8;i++) | ||
| 303 : | buf[i+j*width/8]= revtable[buf[i+j*width/8]]&0x55; | ||
| 304 : | } | ||
| 305 : | } | ||
| 306 : | |||
| 307 : | static readtokens(fd,tokens,n) | ||
| 308 : | FILE *fd; | ||
| 309 : | char tokens[10][256]; | ||
| 310 : | { | ||
| 311 : | int i,j; | ||
| 312 : | char lastc,c; | ||
| 313 : | |||
| 314 : | for(i=0;i<n;i++){ | ||
| 315 : | for(j=0;j<256;j++){ | ||
| 316 : | c=getc(fd); | ||
| 317 : | if(isspace(c)){ | ||
| 318 : | tokens[i][j]=0; | ||
| 319 : | break; | ||
| 320 : | } | ||
| 321 : | tokens[i][j]=c; | ||
| 322 : | } | ||
| 323 : | } | ||
| 324 : | } | ||
| 325 : | static FILE *fileopen(filename,compressed) | ||
| 326 : | char *filename; | ||
| 327 : | { | ||
| 328 : | char buf[256]; | ||
| 329 : | |||
| 330 : | if(compressed){ | ||
| 331 : | sprintf(buf,"zcat %s",filename); | ||
| 332 : | return(popen(buf,"r")); | ||
| 333 : | } | ||
| 334 : | else | ||
| 335 : | return(fopen(filename,"r")); | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | static fileclose(fd,compressed) | ||
| 339 : | FILE *fd; | ||
| 340 : | { | ||
| 341 : | if(compressed) | ||
| 342 : | pclose(fd); | ||
| 343 : | else | ||
| 344 : | fclose(fd); | ||
| 345 : | } | ||
| 346 : | |||
| 347 : | static WORD loadpbm_f(na,fp) | ||
| 348 : | WORD *fp; | ||
| 349 : | { | ||
| 350 : | char tokens[10][256]; | ||
| 351 : | int width,height,size,len,compressed; | ||
| 352 : | char strbuf[256]; | ||
| 353 : | FILE *fd; | ||
| 354 : | unsigned char *filename,*buf; | ||
| 355 : | struct stat stbuf; | ||
| 356 : | WORD a; | ||
| 357 : | |||
| 358 : | if(na!=1)parerr(); | ||
| 359 : | filename=stringcodes(checkstr(a,ag(0))); | ||
| 360 : | strcpy(strbuf,filename); | ||
| 361 : | len=strlen(strbuf); | ||
| 362 : | if(strbuf[len-2]=='.' && strbuf[len-1]=='Z')compressed=1; | ||
| 363 : | if(stat(strbuf,&stbuf)<0){ | ||
| 364 : | strcat(strbuf,".Z"); | ||
| 365 : | if(stat(strbuf,&stbuf)>=0){ | ||
| 366 : | compressed=1; | ||
| 367 : | } | ||
| 368 : | else{ | ||
| 369 : | fprintf(stderr,"stat rror\n"); | ||
| 370 : | return(nil); | ||
| 371 : | } | ||
| 372 : | } | ||
| 373 : | if((fd=fileopen(strbuf,compressed))==NULL){ | ||
| 374 : | fprintf(stderr,"file %s is not found\n",filename); | ||
| 375 : | return(nil); | ||
| 376 : | } | ||
| 377 : | readtokens(fd,tokens,3); | ||
| 378 : | if(strcmp(tokens[0],"P4")){ | ||
| 379 : | fprintf(stderr,"Not a ppm file\n"); | ||
| 380 : | exit(1); | ||
| 381 : | } | ||
| 382 : | width=atoi(tokens[1]); | ||
| 383 : | height=atoi(tokens[2]); | ||
| 384 : | size=width*height/8; | ||
| 385 : | buf=(unsigned char *)alloca(size); | ||
| 386 : | fread(buf,1,size,fd); | ||
| 387 : | fileclose(fd,compressed); | ||
| 388 : | revbit(buf,width,height); | ||
| 389 : | background=XCreatePixmapFromBitmapData(dpy,DefaultRootWindow(dpy),(char *)buf,width,height,fg,bg,DefaultDepth(dpy,DefaultScreen(dpy))); | ||
| 390 : | XCopyArea(dpy,background,save,curgc,0,0,width,height,0,0); | ||
| 391 : | return(nil); | ||
| 392 : | } | ||
| 393 : | |||
| 394 : | #define JISFONT "/home/misa/kanji/jisfont/jis24" | ||
| 395 : | |||
| 396 : | static WORD loadjis_f(na,fp) | ||
| 397 : | WORD *fp; | ||
| 398 : | { | ||
| 399 : | FILE *fd; | ||
| 400 : | WORD a; | ||
| 401 : | int jiscode,offset; | ||
| 402 : | unsigned char buf[72],buf1[50*400]; | ||
| 403 : | |||
| 404 : | if(na!=1)parerr(); | ||
| 405 : | if((fd=fopen(JISFONT,"r"))==NULL){ | ||
| 406 : | fprintf(stderr,"Open Failed\n"); | ||
| 407 : | exit(1); | ||
| 408 : | } | ||
| 409 : | jiscode=strtol(stringcodes(checkstr(a,ag(0))),NULL,16); | ||
| 410 : | offset=((jiscode/256)-0x21)*94+(jiscode%256)-0x21; | ||
| 411 : | fseek(fd,offset*72,0); | ||
| 412 : | fread(buf,1,72,fd); | ||
| 413 : | fclose(fd); | ||
| 414 : | extendbit(buf,buf1); | ||
| 415 : | background=XCreatePixmapFromBitmapData(dpy,DefaultRootWindow(dpy),(char *)buf1,400,400,fg,bg,DefaultDepth(dpy,DefaultScreen(dpy))); | ||
| 416 : | XCopyArea(dpy,background,save,curgc,0,0,400,400,0,0); | ||
| 417 : | return(nil); | ||
| 418 : | } | ||
| 419 : | |||
| 420 : | static extendbit(buf,buf1) | ||
| 421 : | unsigned char *buf,*buf1; | ||
| 422 : | { | ||
| 423 : | int i,j,k; | ||
| 424 : | |||
| 425 : | bzero(buf1,50*400); | ||
| 426 : | for(j=0;j<24;j++) | ||
| 427 : | for(i=0;i<24;i++) | ||
| 428 : | if(buf[j*3+(i/8)]&(0x80>>(i&7))){ | ||
| 429 : | for(k=0;k<16;k+=2){ | ||
| 430 : | buf1[(j*16+k+8)*50+(i*2+1)]=0xaa; | ||
| 431 : | buf1[(j*16+k+9)*50+(i*2+1)]=0x55; | ||
| 432 : | buf1[(j*16+k+8)*50+(i*2+2)]=0xaa; | ||
| 433 : | buf1[(j*16+k+9)*50+(i*2+2)]=0x55; | ||
| 434 : | } | ||
| 435 : | } | ||
| 436 : | } | ||
| 437 : | |||
| 438 : | static WORD copybg_f(na,fp) | ||
| 439 : | WORD *fp; | ||
| 440 : | { | ||
| 441 : | if(na!=0)parerr(); | ||
| 442 : | XCopyArea(dpy,background,save,curgc,0,0,w_width,w_height,0,0); | ||
| 443 : | return(nil); | ||
| 444 : | } | ||
| 445 : | |||
| 446 : | static XImage* ximage; | ||
| 447 : | static WORD getimage_f(na,fp) | ||
| 448 : | WORD *fp; | ||
| 449 : | { | ||
| 450 : | if(na!=0)parerr(); | ||
| 451 : | ximage=XGetImage(dpy,save,0,0,w_width,w_height,-1,ZPixmap); | ||
| 452 : | return(nil); | ||
| 453 : | } | ||
| 454 : | static WORD freeimage_f(na,fp) | ||
| 455 : | WORD *fp; | ||
| 456 : | { | ||
| 457 : | if(na!=0)parerr(); | ||
| 458 : | free(ximage->data); | ||
| 459 : | XFree(ximage); | ||
| 460 : | return nil; | ||
| 461 : | } | ||
| 462 : | |||
| 463 : | static WORD getpixel_f(na,fp) | ||
| 464 : | WORD *fp; | ||
| 465 : | { | ||
| 466 : | WORD a; | ||
| 467 : | int x,y,r; | ||
| 468 : | |||
| 469 : | if(na!=2)parerr(); | ||
| 470 : | x=fixtoi(checkfix(a,ag(1))); | ||
| 471 : | y=fixtoi(checkfix(a,ag(0))); | ||
| 472 : | r=XGetPixel(ximage,x,y); | ||
| 473 : | return itofix(r); | ||
| 474 : | } | ||
| 475 : | |||
| 476 : | static WORD fillrectangle_f(na,fp) | ||
| 477 : | WORD *fp; | ||
| 478 : | { | ||
| 479 : | WORD a; | ||
| 480 : | int x,y,w,h,col; | ||
| 481 : | |||
| 482 : | if(na!=5)parerr(); | ||
| 483 : | col=fixtoi(checkfix(a,ag(0))); | ||
| 484 : | h=fixtoi(checkfix(a,ag(1))); | ||
| 485 : | w=fixtoi(checkfix(a,ag(2))); | ||
| 486 : | y=fixtoi(checkfix(a,ag(3))); | ||
| 487 : | x=fixtoi(checkfix(a,ag(4))); | ||
| 488 : | if(col>1) | ||
| 489 : | XFillRectangle(dpy,save,curgc,x,y,w,h); | ||
| 490 : | else if(col==1) | ||
| 491 : | XFillRectangle(dpy,save,gray_gc,x,y,w,h); | ||
| 492 : | else | ||
| 493 : | XFillRectangle(dpy,save,white_gc,x,y,w,h); | ||
| 494 : | return(nil); | ||
| 495 : | } | ||
| 496 : | |||
| 497 : | |||
| 498 : | #ifdef DEBUG | ||
| 499 : | main() | ||
| 500 : | { | ||
| 501 : | WORD buf[20]; | ||
| 502 : | |||
| 503 : | buf[19]=itofix(100); | ||
| 504 : | buf[18]=itofix(100); | ||
| 505 : | buf[17]=itofix(100); | ||
| 506 : | init_window(2,&buf[17]); | ||
| 507 : | for(;;); | ||
| 508 : | } | ||
| 509 : | |||
| 510 : | |||
| 511 : | WORD make_codepiece(){} | ||
| 512 : | #endif | ||
| 513 : |
|
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |