/* TEBOX ROUTINES by David W. Douglass 12/24/87 */ /* Written and compiled with Megamax C */ #include #define UP_ARROW 0x4800 #define DN_ARROW 0x5000 #define LF_ARROW 0x4B00 #define RT_ARROW 0x4D00 #define INSERT 0x5200 #define DELETE 0x537F #define BACKSP 0x0E08 #define S_INSERT 0x5230 #define C_DELETE 0x531F #define HOME 0x4700 #define S_HOME 0x4737 #define ESC 0x011B #define RETURN 0x1C0D #define TEMAXM 1000 /* max memory reserved for boxes */ #define TEMAXB 4 /* max number of boxes plus one */ static char TEmem[TEMAXM]; /* memory space for box text */ static int TEfree; /* index to start of free memory */ static int TEinfo[TEMAXB][7]; /* text box information */ #define TEstart TEinfo[TEhandle][0] /* index to start of text */ #define TEwidth TEinfo[TEhandle][1] /* dimensions of box (in chars) */ #define TEheight TEinfo[TEhandle][2] #define TExpos TEinfo[TEhandle][3] /* box top left pixel coords */ #define TEypos TEinfo[TEhandle][4] #define TEcsrx TEinfo[TEhandle][5] /* local cursor location coords */ #define TEcsry TEinfo[TEhandle][6] static char TEbuff[81]; /* temp buffer for string output */ /* offsets into text based on corresponding cursor coordinate */ #define TEoffx TEinfo[TEhandle][0]+TEinfo[TEhandle][5] #define TEoffy TEinfo[TEhandle][0]+TEinfo[TEhandle][1]*TEinfo[TEhandle][6] static int TEgh; /* VDI graphics handle */ static int TEblink = -1; /* handle of box to blink cursor in */ static int TEv = 8; /* Rez dependent character cell height */ /***********************************************************************/ TEbox_init (handle) int handle; { int i,temp; for (i=0; i TEMAXM-TEfree+1) return(-1); TEhandle = -1; for (i=TEMAXB-1; i>-1; --i) if (TEinfo[i][0] == -1) TEhandle = i; if (TEhandle < 0) return(-1); TEstart = TEfree; TEfree += (TEw * TEh) + 1; for (i=TEstart; i=TEcsrx; --i) TEbuff[i-TEcsrx+1] = TEmem[TEoffy+i+1] = TEmem[TEoffy+i]; TEbuff[0] = TEmem[TEoffy+i+1] = ' '; TEbuff[TEwidth-TEcsrx] = 0; v_gtext(TEgh,TExpos+8*TEcsrx,TEypos+(TEv*TEcsry)+TEv-1,&TEbuff); break; case DELETE: for (i=TEcsrx+1; i<=TEwidth-1; ++i) TEbuff[i-TEcsrx-1] = TEmem[TEoffy+i-1] = TEmem[TEoffy+i]; TEbuff[i-TEcsrx-1] = TEmem[TEoffy+TEwidth-1] = ' '; TEbuff[i-TEcsrx] = 0; v_gtext(TEgh,TExpos+8*TEcsrx,TEypos+(TEv*TEcsry)+TEv-1,&TEbuff); break; case BACKSP: --TEcsrx; if (TEcsrx < 0) TEcsrx = TEwidth - 1; TEmem[TEoffy+TEcsrx] = ' '; TEbuff[0] = ' '; TEbuff[1] = 0; v_gtext(TEgh,TExpos+8*TEcsrx,TEypos+(TEv*TEcsry)+TEv-1,&TEbuff); break; case S_INSERT: for (j=TEheight-2; j>=TEcsry; --j) for (i=0; i=' ' && keycode <= '~') { TEbuff[0] = TEmem[TEoffy+TEcsrx] = keycode; TEbuff[1] = 0; v_gtext(TEgh,TExpos+8*TEcsrx,TEypos+(TEv*TEcsry)+TEv-1,&TEbuff); ++TEcsrx; if (TEcsrx > TEwidth - 1) ++TEcsry; } break; } /* end of switch */ if (TEcsrx < 0) TEcsrx = TEwidth - 1; if (TEcsrx > TEwidth - 1) TEcsrx = 0; if (TEcsry < 0) TEcsry = TEheight - 1; if (TEcsry > TEheight - 1) TEcsry = 0; TEbox_cursor(TEhandle,1); v_show_c(TEgh,1); } TEbox_cursor (TEhandle,state) int TEhandle,state; { int rect[4]; int x,y,mouseX,mouseY,temp,test,testX,testY; x = TExpos+8*TEcsrx; y = TEypos+TEv*TEcsry; TEbuff[0] = TEmem[TEstart+TEcsry*TEwidth+TEcsrx]; TEbuff[1] = 0; vq_mouse(TEgh,&temp,&mouseX,&mouseY); testX = x-mouseX; testX = testX<0 ? -testX : testX; testY = y-mouseY; testY = testY<0 ? -testY : testY; if ((testX<=16) && (testY<=16)) test = 1; if (test) v_hide_c(TEgh); if (state == 0) { v_gtext(TEgh,x,y+TEv-1,&TEbuff); TEblink = -1; } if (state == 2) { v_gtext(TEgh,x,y+TEv-1,&TEbuff); testX = (mouseX>TExpos)&&(mouseXTEypos)&&(mouseY=TExpos) && (x=TEypos) && (y