view dmtext.c @ 61:a33e47232161

Silence some "unused parameter" warnings.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 09:49:10 +0300
parents f28cd66356f6
children 3d9da937db69
line wrap: on
line source

/*
 * 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)
{
    SDL_Surface *text = TTF_RenderText_Blended(font, fmt, col);
    if (text)
    {
        SDL_Rect rect;
        rect.x = x;
        rect.y = y;
        rect.w = text->w;
        rect.h = text->h;
        SDL_BlitSurface(text, NULL, screen, &rect);
        SDL_FreeSurface(text);
    }
}

void dmDrawTTFTextVA(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt, va_list ap)
{
    char *tmp = dm_strdup_vprintf(fmt, ap);
    if (tmp != NULL)
    {
        dmDrawTTFTextConst(screen, font, col, x, y, tmp);
        dmFree(tmp);
    }
}

void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt, ...)
{
    va_list ap;
    
    va_start(ap, fmt);
    dmDrawTTFTextVA(screen, font, col, x, y, fmt, ap);
    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