summaryrefslogtreecommitdiff
path: root/textscreen/txt_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'textscreen/txt_sdl.c')
-rw-r--r--textscreen/txt_sdl.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 40fb9ff8..29f8de4c 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -50,6 +50,7 @@ typedef struct
// Fonts:
#include "txt_font.h"
+#include "txt_largefont.h"
#include "txt_smallfont.h"
// Time between character blinks in ms
@@ -131,6 +132,10 @@ static txt_font_t *FontForName(char *name)
{
return &main_font;
}
+ else if (!strcmp(name, "large"))
+ {
+ return &large_font;
+ }
else
{
return NULL;
@@ -171,27 +176,35 @@ static void ChooseFont(void)
// If in doubt and we can't get a list, always prefer to
// fall back to the normal font:
- font = &main_font;
-
if (modes == NULL || modes == (SDL_Rect **) -1 || *modes == NULL)
{
#ifdef _WIN32_WCE
font = &small_font;
+#else
+ font = &main_font;
#endif
return;
}
+ // Scan through the list of modes. If we find no modes that are at
+ // least 640x480 in side, default to the small font. If we find one
+ // mode that is at least 1920x1080, this is a modern high-resolution
+ // display, and we can use the large font.
+
+ font = &small_font;
+
for (i=0; modes[i] != NULL; ++i)
{
- if (modes[i]->w >= 640 && modes[i]->h >= 480)
+ if (modes[i]->w >= 1920 && modes[i]->h >= 1080)
{
- return;
+ font = &large_font;
+ break;
+ }
+ else if (modes[i]->w >= 640 && modes[i]->h >= 480)
+ {
+ font = &main_font;
}
}
-
- // No large mode found.
-
- font = &small_font;
}
//
@@ -254,6 +267,7 @@ static inline void UpdateCharacter(int x, int y)
unsigned char character;
unsigned char *p;
unsigned char *s, *s1;
+ unsigned int bit, bytes;
int bg, fg;
unsigned int x1, y1;
@@ -275,18 +289,22 @@ static inline void UpdateCharacter(int x, int y)
}
}
- p = &font->data[character * font->h];
+ // How many bytes per line?
+ bytes = (font->w + 7) / 8;
+ p = &font->data[character * font->h * bytes];
- s = ((unsigned char *) screen->pixels)
- + (y * font->h * screen->pitch) + (x * font->w);
+ s = ((unsigned char *) screen->pixels)
+ + (y * font->h * screen->pitch)
+ + (x * font->w);
for (y1=0; y1<font->h; ++y1)
{
s1 = s;
+ bit = 0;
for (x1=0; x1<font->w; ++x1)
{
- if (*p & (1 << (7-x1)))
+ if (*p & (1 << (7-bit)))
{
*s1++ = fg;
}
@@ -294,9 +312,20 @@ static inline void UpdateCharacter(int x, int y)
{
*s1++ = bg;
}
+
+ ++bit;
+ if (bit == 8)
+ {
+ ++p;
+ bit = 0;
+ }
+ }
+
+ if (bit != 0)
+ {
+ ++p;
}
- ++p;
s += screen->pitch;
}
}