diff --git a/inc/lzy.h b/inc/lzy.h index d64bef5..9509bdf 100644 --- a/inc/lzy.h +++ b/inc/lzy.h @@ -96,7 +96,8 @@ int LZY_DrawTile(unsigned int id, int x, int y); int LZY_DrawTileEx(unsigned int id, int x, int y, unsigned int w, unsigned int h); int LZY_DrawChar(unsigned char chr, int x, int y); -int LZY_DrawText(const char *text, int x, int y); +int LZY_DrawText(int x, int y, const char *text); +int LZY_DrawTextF(int x, int y, const char *fmt, ...); LZY_Music *LZY_MusicLoad(const char *path); int LZY_MusicDestroy(LZY_Music *music); int LZY_MusicPlay(LZY_Music *music, int loops); @@ -146,6 +147,7 @@ const char *LZY_GetError(void); #ifndef LZY_FIRST_CHR #define LZY_FIRST_CHR ' ' #endif +#include int LZY_DrawLine(int x0, int y0, int x1, int y1) { int dx, dy, sx, sy, err, e2; @@ -180,6 +182,17 @@ int LZY_DrawLine(int x0, int y0, int x1, int y1) { return rc; } +int LZY_DrawTextF(int x, int y, const char *fmt, ...) { + char buf[256] = {0}; + + va_list args; + va_start(args, fmt); + vsnprintf(buf, sizeof(buf) - 1, fmt, args); + va_end(args); + + return LZY_DrawText(x, y, buf); +} + #ifdef FXCG50 #include #include @@ -373,7 +386,7 @@ int LZY_DrawChar(unsigned char chr, int x, int y) { #endif } -int LZY_DrawText(const char *text, int x, int y) { +int LZY_DrawText(int x, int y, const char *text) { #ifndef LZY_GINT_FONT LZY_UNUSED(text); LZY_UNUSED(x); @@ -483,6 +496,7 @@ const char *LZY_GetError(void) { #include LZY_SDL_MIXER_INCLUDE #include #include +#include #include #include @@ -882,7 +896,7 @@ int LZY_DrawChar(unsigned char chr, int x, int y) { return 0; } -int LZY_DrawText(const char *text, int x, int y) { +int LZY_DrawText(int x, int y, const char *text) { int err = 0; if (text == NULL) { diff --git a/src/main.c b/src/main.c index 584e725..008bb84 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ int main(int argc, const char **argv) { if (LZY_Init(argc, argv, "lzy example", 30, "res/tset.png", "res/font.png")) { - LZY_Log(LZY_GetError()); + LZY_Log("LZY_Init failed: %s", LZY_GetError()); LZY_Quit(); return 1; } @@ -50,6 +50,8 @@ int main(int argc, const char **argv) { LZY_Log(LZY_GetError()); if (LZY_DrawTile(1, x, y)) LZY_Log(LZY_GetError()); + + LZY_DrawTextF(0, 0, "%d ; %d", x, y); } LZY_DrawEnd(); }