From 4eab7c4387ea46d2e2144b6ceb1fbe548a95d66d Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 11 Jan 2012 22:52:25 +0100 Subject: [PATCH] Font scale option. --- config.def.h | 3 +++ general.h | 1 + gfx/gl.c | 8 ++++++-- settings.c | 4 +++- ssnes.cfg | 3 +++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index a404b4517c..4fcb3b7aec 100644 --- a/config.def.h +++ b/config.def.h @@ -170,6 +170,9 @@ static const bool crop_overscan = true; // Font size for on-screen messages. static const unsigned font_size = 48; +// Attempt to scale the font size. +// The scale factor will be window_size / desktop_size. +static const bool font_scale = true; // Offset for where messages will be placed on-screen. Values are in range [0.0, 1.0]. static const float message_pos_offset_x = 0.05; diff --git a/general.h b/general.h index abacec8e63..2d9eee2cce 100644 --- a/general.h +++ b/general.h @@ -109,6 +109,7 @@ struct settings char font_path[PATH_MAX]; unsigned font_size; bool font_enable; + bool font_scale; float msg_pos_x; float msg_pos_y; float msg_color_r; diff --git a/gfx/gl.c b/gfx/gl.c index 5a5c011644..41c43b3bac 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -756,10 +756,14 @@ static void blit_fonts(gl_t *gl, const struct font_output *head, const struct fo static void calculate_font_coords(gl_t *gl, GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8]) { + GLfloat scale_factor = g_settings.video.font_scale ? + gl->full_x / gl->vp_width : + 1.0f; + GLfloat lx = g_settings.video.msg_pos_x; - GLfloat hx = (GLfloat)gl->font_last_width / gl->vp_width + lx; + GLfloat hx = (GLfloat)gl->font_last_width / (gl->vp_width * scale_factor) + lx; GLfloat ly = g_settings.video.msg_pos_y; - GLfloat hy = (GLfloat)gl->font_last_height / gl->vp_height + ly; + GLfloat hy = (GLfloat)gl->font_last_height / (gl->vp_height * scale_factor) + ly; font_vertex[0] = lx; font_vertex[1] = ly; diff --git a/settings.c b/settings.c index b2785de339..d1988b3259 100644 --- a/settings.c +++ b/settings.c @@ -164,10 +164,11 @@ static void set_defaults(void) g_settings.video.crop_overscan = crop_overscan; g_settings.video.aspect_ratio = -1.0f; // Automatic g_settings.video.shader_type = SSNES_SHADER_AUTO; - g_settings.video.font_enable = font_enable; #ifdef HAVE_FREETYPE + g_settings.video.font_enable = font_enable; g_settings.video.font_size = font_size; + g_settings.video.font_scale = font_scale; g_settings.video.msg_pos_x = message_pos_offset_x; g_settings.video.msg_pos_y = message_pos_offset_y; @@ -366,6 +367,7 @@ static void parse_config_file(void) CONFIG_GET_STRING(video.font_path, "video_font_path"); CONFIG_GET_INT(video.font_size, "video_font_size"); CONFIG_GET_BOOL(video.font_enable, "video_font_enable"); + CONFIG_GET_BOOL(video.font_scale, "video_font_scale"); CONFIG_GET_DOUBLE(video.msg_pos_x, "video_message_pos_x"); CONFIG_GET_DOUBLE(video.msg_pos_y, "video_message_pos_y"); diff --git a/ssnes.cfg b/ssnes.cfg index 7fd1e6770e..d6059bda9b 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -89,6 +89,9 @@ # Size of the TTF font rendered. # video_font_size = 48 +# Attempt to scale the font to fit better for multiple window sizes. +# video_font_scale = true + # Enable usage of OSD messages. # video_font_enable = true