1b59 /* Misc text and font routines for SVGACC */ #include #include #include #include "..\svgacc\svgacc.h" #include "txtrtes.h" int cur_x = 1; int cur_y = 1; int cur_vis = 1; struct pfont_str *cur_pfont; RasterBlock *cursor; RasterBlock *cursor_bg; /* LOAD_PFONT loads a font as image blocks from a pcx file */ load_pfont(char *fontpcx, char *fontname, struct pfont_str *fnt) { FILE *df; int i, font_x, font_y; char datafname[13]; pcxput(SET, 0, 0, fontpcx); cursor = (RasterBlock*)farmalloc(8 * 1 + 4); cursor_bg = (RasterBlock*)farmalloc(8 * 1 + 4); blkget(30, 65, 30 + 8 - 1, 65 + 1 - 1, cursor); strcpy(datafname, fontname); strcat(datafname, ".fdf"); df = fopen(datafname, "rt"); for(i = 0; i < 256; i++) { fscanf(df, "%d %d %d %d %d\n", &font_x, &font_y, &(fnt->c_width[i]), &(fnt->c_height[i]), &(fnt->c_offs[i])); if(fnt->c_width[i] != 0) { fnt->c_img[i] = (RasterBlock*)farmalloc(fnt->c_width[i] * \ fnt->c_height[i] + 4); blkget(font_x, font_y, font_x + fnt->c_width[i] - 1, font_y + fnt->c_height[i] - 1, fnt->c_img[i]); } } fclose(df); cur_pfont = fnt; } /* PFONTSET sets the active proportional font */ pfontset(struct pfont_str *fnt) { cur_pfont = fnt; } /* DRWPSTRING draws a string with proportional font */ drwpstring(int x, int y, unsigned char *s) { int i, asc; for(i = 0; i < strlen(s); i++) { asc = s[i]; if(cur_pfont->c_width[asc] != 0) { spriteput(SET, 15, x, y + cur_pfont->c_offs[asc], cur_pfont->c_img[asc]); x += (cur_pfont->c_width[asc] + 1); } } } int edgets(char *s, int maxlen, int mk_upper) { char temp[82]; int insert = 1, done = 0, pos, len, i, j, c, zeroflag; char curstart[2] = {6,4}; xprintf(s); strcpy(temp,s); pos = strlen(s); len = strlen(s); while (!done) { zeroflag = 0; if ((c = getch()) == 0) { zeroflag = 1; c = getch(); } /* if(mk_upper) c = toupper(c); */ switch (c) { case ESC : if (len == 0) break; for (i = pos; i < len; i++) xputch(' '); for (i = len-1; i >= 0; i--) { xputch(BACKSPC); xputch(' '); xputch(BACKSPC); } pos = len = 0; break; case LEFT : if (zeroflag) { if (pos == 0) break; pos--; xputch(BACKSPC); break; } case RIGHT : if (zeroflag) { if (pos == len) break; if (pos != maxlen) { xputch(temp[pos]); pos++; } break; } case HOME : if (zeroflag) { while (pos-- > 0) xputch(BACKSPC); pos = 0; break; } case END : if (zeroflag) { while (pos < len) xputch(temp[pos++]); break; } case INSERT : if (zeroflag) { insert = (!(insert)); /* ShowCur(curstart[insert],7); */ break; } case DELETE : if (zeroflag) { if (pos == len) break; for (i = pos; i < len; i++) temp[i] = temp[i + 1]; len--; for (i = pos; i < len; i++) xputch(temp[i]); xputch(' '); for (i = len + 1; i > pos; i--) xputch(BACKSPC); break; } case BACKSPC : if (c == BACKSPC) { if (pos == 0) break; if (pos != len) { for (i = pos - 1; i < len; i++) temp[i] = temp[i + 1]; pos--; len--; xputch(BACKSPC); for (i = pos; i < len; i++) xputch(temp[i]); xputch(' '); for (i = len; i >= pos; i--) xputch(BACKSPC); } else { xputch(BACKSPC); xputch(' '); xputch(BACKSPC); pos = --len; } break; } case ENTER : if (c == ENTER) { done = 1; break; } case CTLEND : if (zeroflag) { for (i = pos; i < len; ++i) xputch(' '); for (i = pos; i < len; ++i) xputch(BACKSPC); len = pos; break; } case CTLHOME : if (zeroflag) { if (pos == 0) break; if (pos != len) { while (0 != pos) { for (i = pos - 1; i < len; i++) temp[i] = temp[i + 1]; pos--; len--; xputch(BACKSPC); for (i = pos; i < len; i++) xputch(temp[i]); xputch(' '); for (i = len; i >= pos; i--) xputch(BACKSPC); } } else { while (0 != pos) { xputch(BACKSPC); xputch(' '); xputch(BACKSPC); pos = --len; } } break; } case CTLRT : if (zeroflag) { do { if (pos == len) break; if (pos != maxlen) { xputch(temp[pos]); pos++; } } while (isspace(temp[pos])); do { if (pos == len) break; if (pos != maxlen) { xputch(temp[pos]); pos++; } } while (!isspace(temp[pos])); break; } case CTLLFT : if (zeroflag) { do { if (pos == 0) break; pos--; xputch(BACKSPC); } while (isspace(temp[pos])); do { if (pos == 0) break; pos--; xputch(BACKSPC); } while (!isspace(temp[pos])); break; } default : if (zeroflag) break; if (c == 0 || pos == maxlen) break; if ((!(insert)) || pos == len) { temp[pos++] = (char)c; if (pos > len) len++; xputch(c); } else { if(len == maxlen) break; for (i = len++; i >= pos; i--) temp[i + 1] = temp[i]; temp[pos++] = (char)c; xputch(c); for (i = pos; i < len; i++) xputch(temp[i]); for (i = len; i > pos; i--) xputch(BACKSPC); } } } temp[len] = '\0'; strcpy(s, temp); return len; } xprintf(char *s) { char tmp[80]; drwstring(SET, 0, 8, s, (cur_x - 1) * 8, (cur_y - 1) * 16); cur_x += strlen(s); do_cursor(); } xputch(int c) { char tmp[2]; tmp[0] = c; tmp[1] = 0; switch(c){ case 8 : /* Backspace */ tmp[0] = 32; spriteput(SET, 15, (cur_x - 1) * 8, ((cur_y - 1) * 16) + 15, cursor_bg); cur_x--; break; default: drwstring(SET, 0, 8, tmp, (cur_x - 1) * 8, (cur_y - 1) * 16); cur_x++; if(cur_x > 80) { cur_x = 1; cur_y ++; } } do_cursor(); } do_cursor() { if(cur_vis) spritegap(15, (cur_x - 1) * 8, ((cur_y - 1) * 16) + 15, cursor, cursor_bg); } pos_cur(int x, int y) { cur_x = x; cur_y = y; } hide_cur() { spriteput(SET, 15, (cur_x - 1) * 8, ((cur_y - 1) * 16) + 15, cursor_bg); cur_vis = 0; } show_cur() { spritegap(15, (cur_x - 1) * 8, ((cur_y - 1 ) * 16) + 15, cursor, cursor_bg); cur_vis = 1; } . 0