# HG changeset patch # User Matti Hamalainen # Date 1349078590 -10800 # Node ID ad1ef3f0d474a49f4be89dc49a451fee891f8c1a # Parent 3d9da937db6984efcc7847ce7a91e1b3f7bec43c More work on the text subsystem. diff -r 3d9da937db69 -r ad1ef3f0d474 Makefile.gen --- a/Makefile.gen Mon Oct 01 10:42:56 2012 +0300 +++ b/Makefile.gen Mon Oct 01 11:03:10 2012 +0300 @@ -68,12 +68,12 @@ ifeq ($(DM_GFX_BM_TEXT),yes) DM_CFLAGS += -DDM_GFX_BM_TEXT -DMLIB_OBJS += dmtext.o +DMLIB_OBJS += dmtext_bm.o endif ifeq ($(DM_GFX_TTF_TEXT),yes) DM_CFLAGS += -DDM_GFX_TTF_TEXT -DMLIB_OBJS += dmtext.o +DMLIB_OBJS += dmtext_ttf.o ifeq ($(DM_BUILD_TESTS),yes) ifeq ($(DM_GFX_BLITS),yes) diff -r 3d9da937db69 -r ad1ef3f0d474 dmtext.c --- a/dmtext.c Mon Oct 01 10:42:56 2012 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * 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 xc, int yc, const char *fmt) -{ - SDL_Surface *text = TTF_RenderText_Blended(font, fmt, col); - if (text) - { - SDL_Rect rect; - rect.x = xc; - rect.y = yc; - 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 xc, int yc, const char *fmt, va_list ap) -{ - char *tmp = dm_strdup_vprintf(fmt, ap); - if (tmp != NULL) - { - dmDrawTTFTextConst(screen, font, col, xc, yc, tmp); - dmFree(tmp); - } -} - -void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int xc, int yc, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - dmDrawTTFTextVA(screen, font, col, xc, yc, 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->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); -} - -#endif diff -r 3d9da937db69 -r ad1ef3f0d474 dmtext_bm.c --- /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); +} + diff -r 3d9da937db69 -r ad1ef3f0d474 dmtext_ttf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmtext_ttf.c Mon Oct 01 11:03:10 2012 +0300 @@ -0,0 +1,42 @@ +/* + * 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 dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int xc, int yc, const char *fmt) +{ + SDL_Surface *text = TTF_RenderText_Blended(font, fmt, col); + if (text) + { + SDL_Rect rect; + rect.x = xc; + rect.y = yc; + 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 xc, int yc, const char *fmt, va_list ap) +{ + char *tmp = dm_strdup_vprintf(fmt, ap); + if (tmp != NULL) + { + dmDrawTTFTextConst(screen, font, col, xc, yc, tmp); + dmFree(tmp); + } +} + +void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int xc, int yc, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + dmDrawTTFTextVA(screen, font, col, xc, yc, fmt, ap); + va_end(ap); +}