diff options
Diffstat (limited to 'textscreen/txt_sdl.c')
-rw-r--r-- | textscreen/txt_sdl.c | 98 |
1 files changed, 84 insertions, 14 deletions
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 823685a1..367ed095 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 @@ -108,6 +120,48 @@ 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) + { +#ifdef _WIN32_WCE + font = &small_font; +#endif + return; + } + + for (i=0; modes[i] != NULL; ++i) + { + if (modes[i]->w >= 640 && modes[i]->h >= 480) + { + return; + } + } + + // No large mode found. + + font = &small_font; +} + +// // Initialise text mode screen // // Returns 1 if successful, 0 if an error occurred @@ -115,9 +169,15 @@ 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); + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) + { + return 0; + } + + ChooseFont(); + + screen = SDL_SetVideoMode(TXT_SCREEN_W * font->w, + TXT_SCREEN_H * font->h, 8, 0); if (screen == NULL) return 0; @@ -177,16 +237,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; y1<CHAR_H; ++y1) + for (y1=0; y1<font->h; ++y1) { s1 = s; - for (x1=0; x1<CHAR_W; ++x1) + for (x1=0; x1<font->w; ++x1) { if (*p & (1 << (7-x1))) { @@ -215,7 +275,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 +287,8 @@ void TXT_GetMousePosition(int *x, int *y) { SDL_GetMouseState(x, y); - *x /= CHAR_W; - *y /= CHAR_H; + *x /= font->w; + *y /= font->h; } // @@ -308,6 +368,15 @@ static int TranslateKey(SDL_keysym *sym) case SDLK_PAGEUP: return KEY_PGUP; case SDLK_PAGEDOWN: return KEY_PGDN; +#ifdef SDL_HAVE_APP_KEYS + case SDLK_APP1: return KEY_F1; + case SDLK_APP2: return KEY_F2; + case SDLK_APP3: return KEY_F3; + case SDLK_APP4: return KEY_F4; + case SDLK_APP5: return KEY_F5; + case SDLK_APP6: return KEY_F6; +#endif + default: break; } @@ -448,6 +517,7 @@ static char *SpecialKeyName(int key) case KEYP_MINUS: return "PAD-"; case KEYP_DIVIDE: return "PAD/"; */ + default: return NULL; } } |