| author | ecalot
<ecalot> 2005-01-24 18:20:13 UTC |
| committer | ecalot
<ecalot> 2005-01-24 18:20:13 UTC |
| parent | 95f1d73641c26c634844466fa4f003178fdcd328 |
| FP/src/ker/kernel.c | +3 | -3 |
| FP/src/out/output.c | +23 | -7 |
| stuff/modtools/font/test.c | +2 | -2 |
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c index 17d84cb..ee655c2 100644 --- a/FP/src/ker/kernel.c +++ b/FP/src/ker/kernel.c @@ -122,10 +122,10 @@ int playgame(int optionflag,int level) { printf("Kernel/playgame: cheat: Pass to level %d\n",level); break; case showVersion: - fprintf(stderr,"FreePrince v"FP_VERSION"\n"); + outputDrawMessage("FreePrince v"FP_VERSION"\n"); break; case showScreens: - fprintf(stderr,"S%d L%d R%d A%d B%d\n", + outputDrawMessage("S%d L%d R%d A%d B%d\n", room.id, room.links[eLeft], room.links[eRight], @@ -134,7 +134,7 @@ int playgame(int optionflag,int level) { ); break; case showMoreScreens: - fprintf(stderr,"S%d AL%d AR%d BL%d BR%d\n", + outputDrawMessage("S%d AL%d AR%d BL%d BR%d\n", room.id, room.corners[0], room.corners[1], diff --git a/FP/src/out/output.c b/FP/src/out/output.c index 1a90881..bd819a6 100644 --- a/FP/src/out/output.c +++ b/FP/src/out/output.c @@ -63,7 +63,7 @@ vChar valid_chars[255]; static SDL_Surface *font = NULL; int font_init = 0; -#define FONT_FILE "fonts.bmp" +#define FONT_FILE "../fonts.bmp" void initText () { @@ -120,10 +120,11 @@ unsigned int outputGetTextHeight (const char *txt) return font->h; } +#define OUTPUT_TEXT_CENTERED_X -1 + /* Text Primitives*/ -void outputDrawText(int x, int y, const char *fmt, ...) +void outputvDrawText(int x, int y, const char *fmt, va_list ap) { - va_list ap; char buffer[1024]; unsigned char *s; SDL_Rect from, to; @@ -136,7 +137,6 @@ void outputDrawText(int x, int y, const char *fmt, ...) if (fmt == NULL) return; memset (buffer, 0, sizeof(buffer)); - va_start (ap, fmt); /* If vsnprintf is allowed in the standard use it */ #if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 @@ -146,16 +146,19 @@ void outputDrawText(int x, int y, const char *fmt, ...) /* ANSI X3.159-1989 (`ANSI C') and ISO/IEC 9899:1999 (`ISO C99') */ vsprintf (buffer, fmt, ap); #endif - va_end (ap); s = (unsigned char*)buffer; - current_x = x; + if (x==OUTPUT_TEXT_CENTERED_X) { + current_x = (DEF_SCREEN_WIDTH-outputGetTextWidth(buffer))/2; + } else { + current_x = x; + } while ((*s) != '\0') { if (valid_chars[*s].is_valid) { from.x = valid_chars[*s].x; from.y = 0; from.w = valid_chars[*s].w; - from.h = 12; + from.h = CHAR_SIZE; to.x = current_x; to.y = y; @@ -169,8 +172,20 @@ void outputDrawText(int x, int y, const char *fmt, ...) } } +void outputDrawText(int x, int y, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + outputvDrawText(x,y,fmt,ap); + va_end (ap); +} + void outputDrawMessage(const char* fmt, ...) { + va_list ap; + va_start (ap, fmt); + outputvDrawText(OUTPUT_TEXT_CENTERED_X,DEF_SCREEN_HEIGHT-CHAR_SIZE,fmt,ap); + va_end (ap); } void outputClearLastMessage() @@ -342,6 +357,7 @@ int outputInit() screen = SDL_SetVideoMode(DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT, 0, SDL_SWSURFACE|SDL_HWPALETTE); if (!screen) return -1; /*SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);*/ + initText(); return 0; } diff --git a/stuff/modtools/font/test.c b/stuff/modtools/font/test.c index 1971e8a..39d7d84 100644 --- a/stuff/modtools/font/test.c +++ b/stuff/modtools/font/test.c @@ -9,12 +9,12 @@ */ int main (int argc, char *argv[]) { - initText (); - outputInit (); outputDrawText (10, 0, "Texto \"Hola\" tiene %d pixels de largo", outputGetTextWidth("Hola")); outputDrawText (55, 20, "ABCD 123456 &/$# 000", 26); + + outputDrawMessage ("hola, que %s.", "tal"); outputUpdateScreen();