/** * Print text in the AGI engine screen. */ void TextMan::print_text(const char *msg, int f, int x, int y, int len, int fg, int bg) { f *= CHAR_COLS; x *= CHAR_COLS; y *= CHAR_LINES; debugC(4, kDebugLevelText, "%s, %d, %d, %d, %d, %d, %d", msg, f, x, y, len, fg, bg); print_text2(0, agi_sprintf(msg), f, x, y, len, fg, bg); }
static test_result c (int cmd, char *test, char *res, int expected, UINT8 *p) { char result[MAX_LEN]; int numres; int match; sprintf (result, "%s", agi_sprintf (test)); test_report ("(%d)%s %s = ", cmd, logic_names_cmd[cmd].name, result); execute_agi_command (cmd, p); sprintf (result, "%s", agi_sprintf (res)); test_report ("%s", result); numres = strtoul (result, NULL, 0); if (!(match = (expected == numres))) { test_report (" [Expected: %d]", expected); } return match ? TEST_OK : TEST_FAIL; }
/* len is in characters, not pixels!! */ void TextMan::blit_textbox(const char *p, int y, int x, int len) { /* if x | y = -1, then centre the box */ int xoff, yoff, lin, h, w; char *msg, *m; debugC(3, kDebugLevelText, "x=%d, y=%d, len=%d", x, y, len); if (game.window.active) close_window(); if (x == 0 && y == 0 && len == 0) x = y = -1; if (len <= 0 || len >= 40) len = 32; xoff = x * CHAR_COLS; yoff = y * CHAR_LINES; len--; m = msg = word_wrap_string(agi_sprintf(p), &len); for (lin = 1; *m; m++) { /* Test \r for MacOS 8 */ if (*m == '\n' || *m == '\r') lin++; } if (lin * CHAR_LINES > GFX_HEIGHT) lin = (GFX_HEIGHT / CHAR_LINES); w = (len + 2) * CHAR_COLS; h = (lin + 2) * CHAR_LINES; if (xoff < 0) xoff = (GFX_WIDTH - w - CHAR_COLS) / 2; else xoff -= CHAR_COLS; if (yoff < 0) yoff = (GFX_HEIGHT - 3 * CHAR_LINES - h) / 2; draw_window(xoff, yoff, xoff + w - 1, yoff + h - 1); print_text2(2, msg, 0, CHAR_COLS + xoff, CHAR_LINES + yoff, len + 1, MSG_BOX_TEXT, MSG_BOX_COLOUR); free(msg); do_update(); }
/** * Print user input prompt. */ void TextMan::write_prompt() { int l, fg, bg, pos; if (!game.input_enabled || game.input_mode != INPUT_NORMAL) return; l = game.line_user_input; fg = game.color_fg; bg = game.color_bg; pos = game.cursor_pos; debugC(4, kDebugLevelText, "erase line %d", l); clear_lines(l, l, game.color_bg); debugC(4, kDebugLevelText, "prompt = '%s'", agi_sprintf(game.strings[0])); print_text(game.strings[0], 0, 0, l, 1, fg, bg); print_text((char *)game.input_buffer, 0, 1, l, pos + 1, fg, bg); print_character(pos + 1, l, game.cursor_char, fg, bg); flush_lines(l, l); do_update(); }
char *TextMan::agi_sprintf(const char *s) { static char y[MAX_LEN]; char x[MAX_LEN]; char z[16], *p; debugC(3, kDebugLevelText, "logic %d, '%s'", game.lognum, s); p = x; for (*p = 0; *s;) { switch (*s) { case '\\': s++; goto literal; case '%': s++; switch (*s++) { int i; case 'v': i = strtoul(s, NULL, 10); while (*s >= '0' && *s <= '9') s++; sprintf(z, "%015i", getvar(i)); i = 99; if (*s == '|') { s++; i = strtoul(s, NULL, 10); while (*s >= '0' && *s <= '9') s++; } if (i == 99) { /* remove all leading 0 */ /* don't remove the 3rd zero if 000 */ for (i = 0; z[i] == '0' && i < 14; i++); } else { i = 15 - i; } safe_strcat(p, z + i); break; case '0': i = strtoul(s, NULL, 10) - 1; safe_strcat(p, object_name(i)); break; case 'g': i = strtoul(s, NULL, 10) - 1; safe_strcat(p, game.logics[0].texts[i]); break; case 'w': i = strtoul(s, NULL, 10) - 1; safe_strcat(p, game.ego_words[i].word); break; case 's': i = strtoul(s, NULL, 10); safe_strcat(p, game.strings[i]); break; case 'm': i = strtoul(s, NULL, 10) - 1; if (game.logics[game.lognum].num_texts > i) safe_strcat(p, agi_sprintf(game. logics[game.lognum].texts[i])); break; } while (*s >= '0' && *s <= '9') s++; while (*p) p++; break; default: literal: assert(p < x + MAX_LEN); *p++ = *s++; *p = 0; break; } } strcpy(y, x); return y; }