From db6415cf3accf2207ddd27e289340964e0176af3 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sun, 20 May 2018 21:09:54 -0400 Subject: [PATCH] SDL: Render TTF in Blended mode instead of Solid. Partly after Joachim de Groot. --- sdl1/pdcdisp.c | 23 ++++++++--------------- sdl2/pdcdisp.c | 24 +++++++----------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/sdl1/pdcdisp.c b/sdl1/pdcdisp.c index 01020ae9..9d2e1520 100644 --- a/sdl1/pdcdisp.c +++ b/sdl1/pdcdisp.c @@ -200,15 +200,14 @@ void PDC_gotoyx(int row, int col) #ifdef PDC_WIDE chstr[0] = ch & A_CHARTEXT; - pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[foregr]); + pdc_font = TTF_RenderUNICODE_Blended(pdc_ttffont, chstr, pdc_color[foregr]); if (pdc_font) { dest.h = src.h; dest.w = src.w; src.x = 0; src.y = 0; - SDL_SetColorKey(pdc_font, 0, 0); - SDL_SetPalette(pdc_font, SDL_LOGPAL, pdc_color + backgr, 0, 1); + SDL_FillRect(pdc_screen, &dest, pdc_mapped[backgr]); SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest); SDL_FreeSurface(pdc_font); pdc_font = NULL; @@ -248,15 +247,12 @@ static void _highlight(SDL_Rect *src, SDL_Rect *dest, chtype ch) if (col == -1) col = foregr; - pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[col]); + pdc_font = TTF_RenderUNICODE_Blended(pdc_ttffont, chstr, + pdc_color[col]); if (pdc_font) { src->x = 0; src->y = 0; - - if (backgr != -1) - SDL_SetColorKey(pdc_font, SDL_SRCCOLORKEY, 0); - SDL_BlitSurface(pdc_font, src, pdc_screen, dest); SDL_FreeSurface(pdc_font); pdc_font = NULL; @@ -379,17 +375,14 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) ( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ? TTF_STYLE_ITALIC : 0) ); - pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, - pdc_color[foregr]); + pdc_font = TTF_RenderUNICODE_Blended(pdc_ttffont, chstr, + pdc_color[foregr]); if (pdc_font) { if (backgr != -1) - { - SDL_SetColorKey(pdc_font, 0, 0); - SDL_SetPalette(pdc_font, SDL_LOGPAL, - pdc_color + backgr, 0, 1); - } + SDL_FillRect(pdc_screen, &dest, pdc_mapped[backgr]); + SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest); SDL_FreeSurface(pdc_font); pdc_font = NULL; diff --git a/sdl2/pdcdisp.c b/sdl2/pdcdisp.c index 6715fb3f..cf4806b5 100644 --- a/sdl2/pdcdisp.c +++ b/sdl2/pdcdisp.c @@ -163,7 +163,6 @@ void PDC_gotoyx(int row, int col) Uint16 chstr[2] = {0, 0}; #endif - PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n", row, col, SP->cursrow, SP->curscol)); @@ -201,16 +200,14 @@ void PDC_gotoyx(int row, int col) #ifdef PDC_WIDE chstr[0] = ch & A_CHARTEXT; - pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[foregr]); + pdc_font = TTF_RenderUNICODE_Blended(pdc_ttffont, chstr, pdc_color[foregr]); if (pdc_font) { dest.h = src.h; dest.w = src.w; src.x = 0; src.y = 0; - SDL_SetColorKey(pdc_font, SDL_FALSE, 0); - SDL_SetPaletteColors(pdc_font->format->palette, - pdc_color + backgr, 0, 1); + SDL_FillRect(pdc_screen, &dest, pdc_mapped[backgr]); SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest); SDL_FreeSurface(pdc_font); pdc_font = NULL; @@ -250,15 +247,11 @@ static void _highlight(SDL_Rect *src, SDL_Rect *dest, chtype ch) if (col == -1) col = foregr; - pdc_font = TTF_RenderText_Solid(pdc_ttffont, chstr, pdc_color[col]); + pdc_font = TTF_RenderText_Blended(pdc_ttffont, chstr, pdc_color[col]); if (pdc_font) { src->x = 0; src->y = 0; - - if (backgr != -1) - SDL_SetColorKey(pdc_font, SDL_TRUE, 0); - SDL_BlitSurface(pdc_font, src, pdc_screen, dest); SDL_FreeSurface(pdc_font); pdc_font = NULL; @@ -381,17 +374,14 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) ( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ? TTF_STYLE_ITALIC : 0) ); - pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, - pdc_color[foregr]); + pdc_font = TTF_RenderUNICODE_Blended(pdc_ttffont, chstr, + pdc_color[foregr]); if (pdc_font) { if (backgr != -1) - { - SDL_SetColorKey(pdc_font, SDL_FALSE, 0); - SDL_SetPaletteColors(pdc_font->format->palette, - pdc_color + backgr, 0, 1); - } + SDL_FillRect(pdc_screen, &dest, pdc_mapped[backgr]); + SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest); SDL_FreeSurface(pdc_font); pdc_font = NULL;