diff dmtext.c @ 60:f28cd66356f6

Initial work for bitmapped fonts and text drawing. Also moved TTF header stuff to dmtext.h.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 09:46:56 +0300
parents 32250b436bca
children 3d9da937db69
line wrap: on
line diff
--- a/dmtext.c	Mon Oct 01 07:51:08 2012 +0300
+++ b/dmtext.c	Mon Oct 01 09:46:56 2012 +0300
@@ -1,4 +1,12 @@
-#include "dmlib.h"
+/*
+ * DMLib
+ * -- Bitmap and TTF text & font support
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2012 Tecnic Software productions (TNSP)
+ */
+#include "dmtext.h"
+
+#ifdef DM_GFX_TTF_TEXT
 
 void dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt)
 {
@@ -34,3 +42,48 @@
     va_end(ap);
 }
 
+#endif
+
+#ifdef DM_GFX_BM_TEXT
+
+void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
+{
+    const char *ptr = fmt;
+    DMScaledBlitFunc *blit = dmGetScaledBlitFunc(screen, font->glyphs[0], 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->width, glyph->height, screen);
+            xc += glyph->width;
+        }
+        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, col, x, y, 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, col, x, y, fmt, ap);
+    va_end(ap);
+}
+
+#endif