diff dmtext_bm.c @ 64:ad1ef3f0d474

More work on the text subsystem.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 11:03:10 +0300
parents dmtext.c@3d9da937db69
children 03375aa0ef2b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmtext_bm.c	Mon Oct 01 11:03:10 2012 +0300
@@ -0,0 +1,49 @@
+/*
+ * DMLib
+ * -- Bitmap and TTF text & font support
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2012 Tecnic Software productions (TNSP)
+ */
+#include "dmtext.h"
+
+
+void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
+{
+    const char *ptr = fmt;
+    DMScaledBlitFunc blit = dmGetScaledBlitFunc(screen->format, font->glyphs[0]->format, mode);
+    while (*ptr)
+    {
+        char ch = *ptr++;
+
+        if (isprint(ch) && ch != ' ' && ch != '\t')
+        {
+            SDL_Surface *glyph = font->glyphs[(unsigned char) ch];
+            blit(glyph, xc, yc, glyph->w, glyph->h, screen);
+            xc += glyph->w;
+        }
+        else
+            xc += font->width;
+    }
+}
+
+
+void dmDrawBMTextVA(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap)
+{
+    char *tmp = dm_strdup_vprintf(fmt, ap);
+    if (tmp != NULL)
+    {
+        dmDrawBMTextConst(screen, font, mode, xc, yc, tmp);
+        dmFree(tmp);
+    }
+}
+
+
+void dmDrawBMText(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...)
+{
+    va_list ap;
+    
+    va_start(ap, fmt);
+    dmDrawBMTextVA(screen, font, mode, xc, yc, fmt, ap);
+    va_end(ap);
+}
+