From c2a270f893a8cc08865f0093b02bc35c2b727dc6 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 23 Apr 2009 18:18:43 +0000 Subject: Add small textscreen font for low resolution displays, based on the Atari-Small font by Tom Fine. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1501 --- textscreen/txt_sdl.c | 80 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 13 deletions(-) (limited to 'textscreen/txt_sdl.c') diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 823685a1..2a7e4de0 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -35,15 +35,23 @@ #include "txt_main.h" #include "txt_sdl.h" -#include "txt_font.h" - -#define CHAR_W 8 -#define CHAR_H 16 #if defined(_MSC_VER) && !defined(__cplusplus) #define inline __inline #endif +typedef struct +{ + unsigned char *data; + unsigned int w; + unsigned int h; +} txt_font_t; + +// Fonts: + +#include "txt_font.h" +#include "txt_smallfont.h" + // Time between character blinks in ms #define BLINK_PERIOD 250 @@ -55,6 +63,10 @@ static int key_mapping = 1; static TxtSDLEventCallbackFunc event_callback; static void *event_callback_data; +// Font we are using: + +static txt_font_t *font; + //#define TANGO #ifndef TANGO @@ -107,6 +119,45 @@ static SDL_Color ega_colors[] = #endif +// +// Select the font to use, based on screen resolution +// +// If the highest screen resolution available is less than +// 640x480, use the small font. +// + +static void ChooseFont(void) +{ + SDL_Rect **modes; + int i; + + font = &main_font; + + // Check all modes + + modes = SDL_ListModes(NULL, SDL_FULLSCREEN); + + // If in doubt and we can't get a list, always prefer to + // fall back to the normal font: + + if (modes == NULL || modes == (SDL_Rect **) -1 || *modes == NULL) + { + return; + } + + for (i=0; modes[i] != NULL; ++i) + { + if (0 && modes[i]->w >= 640 && modes[i]->h >= 480) + { + return; + } + } + + // No large mode found. + + font = &small_font; +} + // // Initialise text mode screen // @@ -116,8 +167,11 @@ static SDL_Color ega_colors[] = int TXT_Init(void) { SDL_InitSubSystem(SDL_INIT_VIDEO); - - screen = SDL_SetVideoMode(TXT_SCREEN_W * CHAR_W, TXT_SCREEN_H * CHAR_H, 8, 0); + + ChooseFont(); + + screen = SDL_SetVideoMode(TXT_SCREEN_W * font->w, + TXT_SCREEN_H * font->h, 8, 0); if (screen == NULL) return 0; @@ -177,16 +231,16 @@ static inline void UpdateCharacter(int x, int y) } } - p = &int10_font_16[character * CHAR_H]; + p = &font->data[character * font->h]; s = ((unsigned char *) screen->pixels) - + (y * CHAR_H * screen->pitch) + (x * CHAR_W); + + (y * font->h * screen->pitch) + (x * font->w); - for (y1=0; y1h; ++y1) { s1 = s; - for (x1=0; x1w; ++x1) { if (*p & (1 << (7-x1))) { @@ -215,7 +269,7 @@ void TXT_UpdateScreenArea(int x, int y, int w, int h) } } - SDL_UpdateRect(screen, x * CHAR_W, y * CHAR_H, w * CHAR_W, h * CHAR_H); + SDL_UpdateRect(screen, x * font->w, y * font->h, w * font->w, h * font->h); } void TXT_UpdateScreen(void) @@ -227,8 +281,8 @@ void TXT_GetMousePosition(int *x, int *y) { SDL_GetMouseState(x, y); - *x /= CHAR_W; - *y /= CHAR_H; + *x /= font->w; + *y /= font->h; } // -- cgit v1.2.3 From 40d03a9c38d63f7b7f6a0453f103f18cfd156029 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 23 Apr 2009 18:19:52 +0000 Subject: Oops. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1502 --- textscreen/txt_sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'textscreen/txt_sdl.c') diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 2a7e4de0..1bc42d7c 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -147,7 +147,7 @@ static void ChooseFont(void) for (i=0; modes[i] != NULL; ++i) { - if (0 && modes[i]->w >= 640 && modes[i]->h >= 480) + if (modes[i]->w >= 640 && modes[i]->h >= 480) { return; } -- cgit v1.2.3