diff options
author | Simon Howard | 2009-05-14 19:45:22 +0000 |
---|---|---|
committer | Simon Howard | 2009-05-14 19:45:22 +0000 |
commit | 664c35903202a2e7c56479eff1786e952718e4df (patch) | |
tree | f8e0c53b9f27f6a7c72cdb228fb041bfe1278aaf /textscreen/txt_sdl.c | |
parent | ebc8378619e9ddca26eb7cda1f4a4f2be1e98091 (diff) | |
parent | 144849eee5804a0306d23f07a5be9877f242a1bf (diff) | |
download | chocolate-doom-664c35903202a2e7c56479eff1786e952718e4df.tar.gz chocolate-doom-664c35903202a2e7c56479eff1786e952718e4df.tar.bz2 chocolate-doom-664c35903202a2e7c56479eff1786e952718e4df.zip |
Merge from trunk. Note that src/i_sdlsound.c has not yet been merged as
it contains too many conflicts at present.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1522
Diffstat (limited to 'textscreen/txt_sdl.c')
-rw-r--r-- | textscreen/txt_sdl.c | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index d695c898..ea2280d0 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,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 (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 @@ -121,9 +172,10 @@ int TXT_Init(void) flags = SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; - screen = SDL_SetVideoMode(TXT_SCREEN_W * CHAR_W, - TXT_SCREEN_H * CHAR_H, - 8, flags); + ChooseFont(); + + screen = SDL_SetVideoMode(TXT_SCREEN_W * font->w, + TXT_SCREEN_H * font->h, 8, flags); if (screen == NULL) return 0; @@ -183,16 +235,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))) { @@ -221,7 +273,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) @@ -233,8 +285,8 @@ void TXT_GetMousePosition(int *x, int *y) { SDL_GetMouseState(x, y); - *x /= CHAR_W; - *y /= CHAR_H; + *x /= font->w; + *y /= font->h; } // |