diff ppl.c @ 130:1d7dc7c8745c

Move custom bitmap font text rendering functions into PPL code itself.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Oct 2012 09:39:37 +0300
parents 7a59611f9d4f
children f721f9f7838a
line wrap: on
line diff
--- a/ppl.c	Thu Oct 04 09:39:01 2012 +0300
+++ b/ppl.c	Thu Oct 04 09:39:37 2012 +0300
@@ -158,11 +158,63 @@
 }
 
 
+void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
+{
+    const char *ptr = fmt;
+    DMUnscaledBlitFunc blit = NULL;
+
+    while (*ptr)
+    {
+        int ch = toupper(*ptr++);
+        SDL_Surface *glyph;
+
+        if (ch == '_')
+        {
+            xc += 4;
+            continue;
+        }
+        
+        if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL)
+        {
+            if (blit == NULL)
+                blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode);
+            
+            blit(glyph, xc, yc, screen);
+            xc += font->width;
+        }
+        else
+            xc += font->width;
+    }
+}
+
+
+void dmDrawBMTextVAQ(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)
+    {
+        dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp);
+        dmFree(tmp);
+    }
+}
+
+
+void dmDrawBMTextQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...)
+{
+    va_list ap;
+    
+    va_start(ap, fmt);
+    dmDrawBMTextVAQ(screen, font, mode, xc, yc, fmt, ap);
+    va_end(ap);
+}
+
+
 Uint32 dmCol(float r, float g, float b)
 {
     return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b);
 }
 
+
 BOOL dmInitializeVideo()
 {
     engine.screen = SDL_SetVideoMode(
@@ -269,7 +321,7 @@
     else
         sprintf(ptr, "..");
 
-    dmDrawBMTextConst(screen, font, DMD_TRANSPARENT, xc, yc, text);
+    dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT, xc, yc, text);
 }
 
 
@@ -300,7 +352,7 @@
         
         if (crow >= 0 && crow < pat->nrows)
         {
-            dmDrawBMText(screen, font, DMD_TRANSPARENT, x0, yc, "%03d", crow);
+            dmDrawBMTextQ(screen, font, DMD_TRANSPARENT, x0, yc, "%03d", crow);
 
             for (nchannel = 0; nchannel < qwidth; nchannel++)
             {
@@ -560,13 +612,13 @@
         dmDrawBox3D(engine.screen, 0, 0, engine.screen->w - 1, engine.screen->h - 1,
             col.boxBg, col.box1, col.box2);
         
-        dmDrawBMText(engine.screen, font, DMD_TRANSPARENT, 5, 5, "%s v%s by ccr/TNSP - (c) Copyright 2012 TNSP", dmProgDesc, dmProgVersion);
+        dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5, "%s v%s by ccr/TNSP - (c) Copyright 2012 TNSP", dmProgDesc, dmProgVersion);
 
 
         JSS_LOCK(dev);
         JSS_LOCK(plr);
 
-        dmDrawBMText(engine.screen, font, DMD_TRANSPARENT, 5, 5 + 12,
+        dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + 12,
             "Tempo: %3d | Speed: %3d | Row: %3d | Order: %d",
             plr->tempo, plr->speed, plr->row, plr->order
             );