draw formatted text

This commit is contained in:
KikooDX 2022-04-12 11:58:12 +02:00
parent cefa79506f
commit 2eb6438878
2 changed files with 20 additions and 4 deletions

View File

@ -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 <stdio.h>
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 <gint/cpu.h>
#include <gint/display.h>
@ -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 <libgen.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -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) {

View File

@ -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();
}