📄 x_wrdwindow.c
字号:
int (*DrawStringFunc)(); DrawStringFunc=XDrawString; line[pos]=0; if(prevattr<0){ DrawStringFunc=NULL; }else if(prevattr&CATTR_16FONT){ f=mywin.f16; DrawStringFunc=XDrawString16; pos/=2; }else f=mywin.f8; if(DrawStringFunc!=NULL){ XSetFont(mywin.d,mywin.gc,f->fid); lbearing=f->min_bounds.lbearing; ascent=f->max_bounds.ascent; if(prevattr&CATTR_COLORED){ int tcol; tcol=(prevattr&CATTR_TXTCOL_MASK)>>CATTR_TXTCOL_MASK_SHIFT; XSetForeground(mywin.d,mywin.gc, mywin.txtcolor[tcol].pixel); }else if(prevattr&CATTR_BGCOLORED){ int tcol; tcol=(prevattr&CATTR_TXTCOL_MASK)>>CATTR_TXTCOL_MASK_SHIFT; DrawStringFunc=(DrawStringFunc==XDrawString)?(int(*)())DrawReverseString:(int(*)())DrawReverseString16; XSetForeground(mywin.d,mywin.gc, mywin.txtcolor[tcol].pixel); } (*DrawStringFunc)(mywin.d,drawable,mywin.gc, s_x-lbearing,i*CSIZEY+ascent,line,pos); drawflag=1; if((prevattr&CATTR_COLORED)||(prevattr&CATTR_BGCOLORED)) XSetForeground(mywin.d,mywin.gc,mywin.txtcolor[COLOR_DEFAULT].pixel); } prevattr=curattr; s_x=e_x; pos=0; } line[pos++]=mywin.scrnbuf[i][j].c; e_x+=CSIZEX; } } } return drawflag;}/* Copy disp_screen to offscr */static void TransferArea(int sx, int sy, int width, int height){ if(!truecolor) XCopyArea(mywin.d, mywin.disp_screen, mywin.offscr, mywin.gc, sx, sy, width, height, sx, sy); else { XImage *im; int x, y, i, c; int units_per_line; int x0, y0; if(sx + width > SIZEX) width = SIZEX - sx; if(sy + height > SIZEY) height = SIZEY - sy;#if XSHM_SUPPORT if(shm_screen) { im = shm_screen->im; XCopyArea(mywin.d, mywin.disp_screen, shm_screen->pm, mywin.gc, sx, sy, width, height, 0, 0); XSync(mywin.d, 0); /* Wait until ready */ x0 = 0; y0 = 0; } else#endif /* XSHM_SUPPORT */ { im = XGetImage(mywin.d, mywin.disp_screen, sx, sy, width, height, AllPlanes, ZPixmap); x0 = 0; y0 = 0; } units_per_line = im->bytes_per_line / (im->bits_per_pixel / 8); /* Optimize 8, 16, 32 bit depth image */ switch(im->bits_per_pixel) { case 8: for(y = 0; y < height; y++) for(x = 0; x < width; x++) { i = (y0 + y) * units_per_line + x0 + x; c = im->data[i]; im->data[i] = truecolor_palette[c]; } break; case 16: for(y = 0; y < height; y++) for(x = 0; x < width; x++) { i = (y0 + y) * units_per_line + x0 + x; c = ((uint16 *)im->data)[i]; ((uint16 *)im->data)[i] = truecolor_palette[c]; } break; case 32: for(y = 0; y < height; y++) for(x = 0; x < width; x++) { i = (y0 + y) * units_per_line + x0 + x; c = ((uint32 *)im->data)[i]; ((uint32 *)im->data)[i] = truecolor_palette[c]; } break; default: for(y = 0; y < height; y++) for(x = 0; x < width; x++) { c = XGetPixel(im, x0 + x, y0 + y); XPutPixel(im, x0 + x, y0 + y, truecolor_palette[c]); } break; }#if XSHM_SUPPORT if(shm_screen) XCopyArea(mywin.d, shm_screen->pm, mywin.offscr, mywin.gc, x0, y0, width, height, sx, sy); else#endif { XPutImage(mywin.d, mywin.offscr, mywin.gc, im, x0, y0, sx, sy, width, height); XDestroyImage(im); } }}static void Redraw(int x, int y, int width, int height){ if(!mywin.redrawflag) return; if(mywin.gon) TransferArea(x, y, width, height); else { XSetForeground(mywin.d, mywin.gc, BlackPixel(mywin.d,DefaultScreen(mywin.d))); XFillRectangle(mywin.d, mywin.offscr, mywin.gc, x, y, width, height); } if(mywin.ton) RedrawText(mywin.offscr, x, y, width, height); XClearArea(mywin.d, mywin.w, x, y, width, height, False);}/******************************************************* * Utilities for VT Parser ********************************************************/static void DelChar(int line,int col){ int rx1,ry1,rx2,ry2; rx1=(col)*CSIZEX; rx2=(col+1)*CSIZEX; ry1=(line)*CSIZEY; ry2=(line+1)*CSIZEY; if(mywin.scrnbuf[line][col].attr&CATTR_16FONT){ if(mywin.scrnbuf[line][col].attr&CATTR_LPART){ mywin.scrnbuf[line][col+1].c=0; mywin.scrnbuf[line][col+1].attr=0; rx2+=CSIZEX; } else{ mywin.scrnbuf[line][col-1].c=0; mywin.scrnbuf[line][col-1].attr=0; rx1-=CSIZEX; } } RedrawInject(rx1,ry1,rx2-rx1,ry2-ry1,False); mywin.scrnbuf[line][col].c=0; mywin.scrnbuf[line][col].attr=0;}static void ClearLine(int j){ free(mywin.scrnbuf[j]); mywin.scrnbuf[j]=NULL; RedrawInject(0,j*CSIZEY,SIZEX,CSIZEY,False);}static void ClearLeft(void){ memset(mywin.scrnbuf[mywin.curline],0,sizeof(Linbuf)*mywin.curcol); if(!(mywin.scrnbuf[mywin.curline][mywin.curcol+1].attr &(CATTR_LPART))){ mywin.scrnbuf[mywin.curline][mywin.curcol+1].attr=0; mywin.scrnbuf[mywin.curline][mywin.curcol+1].c=0; } RedrawInject(0,(mywin.curline)*CSIZEY,SIZEX,CSIZEY,False);}static void ClearRight(void){ /*Erase Right*/ memset(mywin.scrnbuf[mywin.curline]+mywin.curcol,0, sizeof(Linbuf)*(COLS-mywin.curcol)); if((mywin.scrnbuf[mywin.curline][mywin.curcol-1].attr &(CATTR_LPART))){ mywin.scrnbuf[mywin.curline][mywin.curcol-1].attr=0; mywin.scrnbuf[mywin.curline][mywin.curcol-1].c=0; } RedrawInject(0,(mywin.curline)*CSIZEY,SIZEX,CSIZEY,False);}static void RedrawInject(int x,int y,int width,int height,int flag){ static int xfrom,yfrom,xto,yto; int x2,y2; x2=x+width; y2=y+height; if(x==-1){ xfrom=yfrom=xto=yto=-1; return; } if(flag==False){ if(xfrom==-1){ xfrom=x; yfrom=y; xto=x2; yto=y2; } else{ xfrom=(xfrom<x)?xfrom:x; yfrom=(yfrom<y)?yfrom:y; xto=(xto>x2)?xto:x2; yto=(yto>y2)?yto:y2; } } else if(xfrom!=-1) Redraw(xfrom,yfrom,xto-xfrom,yto-yfrom);}/************************************************************ * Graphic Command Functions * * * **************************************************************/void x_GMode(int mode){ int i; unsigned long mask; if(mode == -1) { /* Initialize plane mask */ mywin.gmode = -1; XSetPlaneMask(mywin.d,mywin.gcgr,AllPlanes); return; } mode&=15; mywin.gmode = mode; mode = (mode&8)|wrd_plane_remap[mode&7]; mask = mywin.basepix; for(i=0;i<NUMPLANE;i++){ mask|=(((mode&1)==1)?mywin.pmask[i]:0); mode=mode>>1; } XSetPlaneMask(mywin.d,mywin.gcgr,mask);}void x_GMove(int xorig,int yorig,int xend,int yend,int xdist,int ydist, int srcp,int endp,int swflag){ int w, h; w=xend-xorig+1; h=yend-yorig+1; if((srcp<2)&&(endp<2)){ if(swflag==1){ XSetFunction(mywin.d,mywin.gcgr,GXxor); XCopyArea(mywin.d,mywin.screens[endp],mywin.screens[srcp],mywin.gcgr ,xdist,ydist,w,h,xorig,yorig); XCopyArea(mywin.d,mywin.screens[srcp],mywin.screens[endp],mywin.gcgr ,xorig,yorig,w,h,xdist,ydist); XCopyArea(mywin.d,mywin.screens[endp],mywin.screens[srcp],mywin.gcgr ,xdist,ydist,w,h,xorig,yorig); XSetFunction(mywin.d,mywin.gcgr,GXcopy); if(mywin.screens[srcp]==mywin.disp_screen) Redraw(xorig,yorig,w,h); } else XCopyArea(mywin.d,mywin.screens[srcp],mywin.screens[endp],mywin.gcgr ,xorig,yorig,w,h,xdist,ydist); if(mywin.screens[endp]==mywin.disp_screen) { Redraw(xdist,ydist,w,h); } }}void x_VSget(int *params,int nparam){ int numalloc,depth; depth=DefaultDepth(mywin.d,DefaultScreen(mywin.d)); if(vgvram.vpix!=NULL) x_VRel(); vgvram.vpix=safe_malloc(sizeof(Pixmap)*params[0]); for(numalloc=0;numalloc<params[0];numalloc++){ vgvram.vpix[numalloc]=XCreatePixmap(mywin.d,mywin.w,SIZEX,SIZEY,depth); } vgvram.num=numalloc;}void x_VRel(){ int i; if(mywin.d == NULL) return; if(vgvram.vpix==NULL) return; for(i=0;i<vgvram.num;i++) XFreePixmap(mywin.d,vgvram.vpix[i]); free(vgvram.vpix); vgvram.vpix=NULL; vgvram.num=0;} void x_VCopy(int sx1,int sy1,int sx2,int sy2,int tx,int ty ,int ss,int ts,int mode){ int vpg,rpg,w,h; Pixmap srcpage,distpage,tmp; w=sx2-sx1+1; h=sy2-sy1+1; if(mode!=0){ vpg=ss; rpg=ts; }else{ vpg=ts; rpg=ss; } if(vpg<vgvram.num) srcpage=vgvram.vpix[vpg]; else return; if(rpg<2) distpage=mywin.screens[rpg]; else return; if(mode==0){ tmp=srcpage; srcpage=distpage; distpage=tmp; } XCopyArea(mywin.d,srcpage,distpage,mywin.gc ,sx1,sy1,w,h,tx,ty); if(distpage==mywin.disp_screen) Redraw(tx,ty,w,h);}void x_XCopy(int sx1, int sy1, int sx2, int sy2, int tx, int ty, int ss, int ts, int method, int *opts, int nopts){ XImage *simg, *timg; int i, x, y, w, h; int gmode_save; w = sx2 - sx1 + 1; h = sy2 - sy1 + 1; gmode_save = mywin.gmode; if(w <= 0 || w > SIZEX || h <= 0 || h > SIZEY || ss < 0 || ss >= NUMVSCREEN || ts < 0 || ts >= NUMVSCREEN) return; simg = timg = NULL; x_GMode(-1); switch(method) { default: case 0: /* copy */ x_GMove(sx1, sy1, sx2, sy2, tx, ty, ss, ts, 0); break; case 1: /* copy except pallet No.0 */ simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; timg = XGetImage(mywin.d, mywin.screens[ts], tx, ty, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!timg) break; for(y = 0; y < h; y++) for(x = 0; x < w; x++) { int pixel = XGetPixel(simg, x, y); if(pixel != mywin.curcoltab[0].pixel) XPutPixel(timg, x, y, pixel); } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, timg, 0, 0, tx, ty, w, h); if(mywin.screens[ts] == mywin.disp_screen) Redraw(tx, ty, w, h); break; case 2: /* xor */ XSetFunction(mywin.d,mywin.gcgr,GXxor); x_GMove(sx1, sy1, sx2, sy2, tx, ty, ss, ts, 0); XSetFunction(mywin.d,mywin.gcgr,GXcopy); break; case 3: /* and */ XSetFunction(mywin.d,mywin.gcgr,GXand); x_GMove(sx1, sy1, sx2, sy2, tx, ty, ss, ts, 0); XSetFunction(mywin.d,mywin.gcgr,GXcopy); break; case 4: /* or */ XSetFunction(mywin.d,mywin.gcgr,GXor); x_GMove(sx1, sy1, sx2, sy2, tx, ty, ss, ts, 0); XSetFunction(mywin.d,mywin.gcgr,GXcopy); break; case 5: /* reverse x */ simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; for(y = 0; y < h; y++) { for(x = 0; x < w/2; x++) { int p1, p2; p1 = XGetPixel(simg, x, y); p2 = XGetPixel(simg, w-x-1, y); XPutPixel(simg, x, y, p2); XPutPixel(simg, w-x-1, y, p1); } } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, simg, 0, 0, tx, ty, w, h); if(mywin.screens[ts] == mywin.disp_screen) Redraw(tx, ty, w, h); break; case 6: /* reverse y */ simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; for(y = 0; y < h/2; y++) { for(x = 0; x < w; x++) { int p1, p2; p1 = XGetPixel(simg, x, y); p2 = XGetPixel(simg, x, h-y-1); XPutPixel(simg, x, y, p2); XPutPixel(simg, x, h-y-1, p1); } } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, simg, 0, 0, tx, ty, w, h); if(mywin.screens[ts] == mywin.disp_screen) Redraw(tx, ty, w, h); break; case 7: /* reverse x-y */ simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; for(i = 0; i < w*h/2; i++) { int p1, p2; p1 = simg->data[i]; p2 = simg->data[w*h-i-1]; simg->data[i] = p2; simg->data[w*h-i-1] = p1; } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, simg, 0, 0, tx, ty, w, h); if(mywin.screens[ts] == mywin.disp_screen) Redraw(tx, ty, w, h); break; case 8: /* copy except pallet No.0 (type2) */ if(nopts < 2) break; simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; timg = XGetImage(mywin.d, mywin.screens[ts], opts[0], opts[1], w, h, mywin.gscreen_plane_mask, ZPixmap); if(!timg) break; for(y = 0; y < h; y++) for(x = 0; x < w; x++) { int pixel = XGetPixel(simg, x, y); if(pixel != mywin.curcoltab[0].pixel) XPutPixel(timg, x, y, pixel); } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, timg, 0, 0, tx, ty, w, h); if(mywin.screens[ts] == mywin.disp_screen) Redraw(tx, ty, w, h); break; case 9: { /* Mask copy */ int m, opt5, c; if(nopts < 5) break; opt5 = opts[4]; simg = XGetImage(mywin.d, mywin.screens[ss], sx1, sy1, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!simg) break; timg = XGetImage(mywin.d, mywin.screens[ts], tx, ty, w, h, mywin.gscreen_plane_mask, ZPixmap); if(!timg) break; for(y = 0; y < h; y++) { m = opts[y & 3] & 0xff; for(x = 0; x < w; x++) { if((1 << (x&7)) & m) { if(opt5 == 16) continue; c = mywin.curcoltab[opt5 & 0xf].pixel; } else c = XGetPixel(simg, x, y); XPutPixel(timg, x, y, c); } } XPutImage(mywin.d, mywin.screens[ts], mywin.gcgr, timg,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -