From 610e1570ca2492a97cfc5cf6a3794c07b605df48 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 4 Jan 2014 22:07:09 +0100 Subject: [PATCH] rnd-20140104-3-src * added window scaling options to graphics setup menu --- ChangeLog | 1 + src/conftime.h | 2 +- src/files.c | 41 ++++++++------- src/libgame/sdl.c | 45 +++++++++++----- src/libgame/sdl.h | 4 ++ src/libgame/system.c | 2 + src/libgame/system.h | 9 ++++ src/screens.c | 121 +++++++++++++++++++++++++++++++++++++++---- src/tools.c | 19 ++++++- 9 files changed, 197 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 203831c4..73069a15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2014-01-04 * fixed remaining text input problems for non-ASCII keys with modifier + * added window scaling options to graphics setup menu 2014-01-03 * fixed key code problems with certain keys for SDL2 diff --git a/src/conftime.h b/src/conftime.h index 59500ab8..6b263102 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-01-04 13:44" +#define COMPILE_DATE_STRING "2014-01-04 22:06" diff --git a/src/files.c b/src/files.c index cde49741..64e204c2 100644 --- a/src/files.c +++ b/src/files.c @@ -11346,25 +11346,26 @@ void SaveScore(int nr) #define SETUP_TOKEN_TIME_LIMIT 16 #define SETUP_TOKEN_FULLSCREEN 17 #define SETUP_TOKEN_FULLSCREEN_MODE 18 -#define SETUP_TOKEN_ASK_ON_ESCAPE 19 -#define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR 20 -#define SETUP_TOKEN_QUICK_SWITCH 21 -#define SETUP_TOKEN_INPUT_ON_FOCUS 22 -#define SETUP_TOKEN_PREFER_AGA_GRAPHICS 23 -#define SETUP_TOKEN_GAME_FRAME_DELAY 24 -#define SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS 25 -#define SETUP_TOKEN_SMALL_GAME_GRAPHICS 26 -#define SETUP_TOKEN_GRAPHICS_SET 27 -#define SETUP_TOKEN_SOUNDS_SET 28 -#define SETUP_TOKEN_MUSIC_SET 29 -#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 30 -#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 31 -#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 32 -#define SETUP_TOKEN_VOLUME_SIMPLE 33 -#define SETUP_TOKEN_VOLUME_LOOPS 34 -#define SETUP_TOKEN_VOLUME_MUSIC 35 - -#define NUM_GLOBAL_SETUP_TOKENS 36 +#define SETUP_TOKEN_WINDOW_SCALING_PERCENT 19 +#define SETUP_TOKEN_ASK_ON_ESCAPE 20 +#define SETUP_TOKEN_ASK_ON_ESCAPE_EDITOR 21 +#define SETUP_TOKEN_QUICK_SWITCH 22 +#define SETUP_TOKEN_INPUT_ON_FOCUS 23 +#define SETUP_TOKEN_PREFER_AGA_GRAPHICS 24 +#define SETUP_TOKEN_GAME_FRAME_DELAY 25 +#define SETUP_TOKEN_SP_SHOW_BORDER_ELEMENTS 26 +#define SETUP_TOKEN_SMALL_GAME_GRAPHICS 27 +#define SETUP_TOKEN_GRAPHICS_SET 28 +#define SETUP_TOKEN_SOUNDS_SET 29 +#define SETUP_TOKEN_MUSIC_SET 30 +#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS 31 +#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS 32 +#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC 33 +#define SETUP_TOKEN_VOLUME_SIMPLE 34 +#define SETUP_TOKEN_VOLUME_LOOPS 35 +#define SETUP_TOKEN_VOLUME_MUSIC 36 + +#define NUM_GLOBAL_SETUP_TOKENS 37 /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH 0 @@ -11493,6 +11494,7 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_SWITCH, &si.time_limit, "time_limit" }, { TYPE_SWITCH, &si.fullscreen, "fullscreen" }, { TYPE_STRING, &si.fullscreen_mode, "fullscreen_mode" }, + { TYPE_INTEGER,&si.window_scaling_percent, "window_scaling_percent" }, { TYPE_SWITCH, &si.ask_on_escape, "ask_on_escape" }, { TYPE_SWITCH, &si.ask_on_escape_editor, "ask_on_escape_editor" }, { TYPE_SWITCH, &si.quick_switch, "quick_player_switch" }, @@ -11664,6 +11666,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->time_limit = TRUE; si->fullscreen = FALSE; si->fullscreen_mode = getStringCopy(DEFAULT_FULLSCREEN_MODE); + si->window_scaling_percent = STD_WINDOW_SCALING_PERCENT; si->ask_on_escape = TRUE; si->ask_on_escape_editor = TRUE; si->quick_switch = FALSE; diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 734307d5..cdb367fe 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -30,7 +30,7 @@ static SDL_Window *sdl_window = NULL; static SDL_Renderer *sdl_renderer = NULL; static SDL_Texture *sdl_texture = NULL; -#define USE_RENDERER 1 +#define USE_RENDERER TRUE #endif /* stuff needed to work around SDL/Windows fullscreen drawing bug */ @@ -197,6 +197,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, }; #endif SDL_Rect **modes = NULL; + boolean hardware_fullscreen_available = TRUE; int i, j; /* default: normal game window size */ @@ -206,6 +207,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, fullscreen_yoffset = 0; #if !defined(TARGET_SDL2) + /* determine required standard fullscreen mode for game screen size */ for (i = 0; screen_xy[i][0] != -1; i++) { if (screen_xy[i][0] >= video.width && screen_xy[i][1] >= video.height) @@ -228,6 +230,8 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, video.fullscreen_mode_current = NULL; #endif + video.window_scaling_percent = setup.window_scaling_percent; + #if defined(TARGET_SDL2) int num_displays = SDL_GetNumVideoDisplays(); @@ -254,17 +258,16 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, } } } - #else - /* get available hardware supported fullscreen modes */ modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); #endif if (modes == NULL) { - /* no screen modes available => no fullscreen mode support */ - video.fullscreen_available = FALSE; + /* no hardware screen modes available => no fullscreen mode support */ + // video.fullscreen_available = FALSE; + hardware_fullscreen_available = FALSE; } else if (modes == (SDL_Rect **)-1) { @@ -318,10 +321,19 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, if (num_modes == 0) { /* no appropriate screen modes available => no fullscreen mode support */ - video.fullscreen_available = FALSE; + // video.fullscreen_available = FALSE; + hardware_fullscreen_available = FALSE; } } + video.fullscreen_available = hardware_fullscreen_available; + +#if USE_DESKTOP_FULLSCREEN + // in SDL 2.0, there is always support for desktop fullscreen mode + // (in SDL 1.2, there is only support for "real" fullscreen mode) + video.fullscreen_available = TRUE; +#endif + #if defined(TARGET_SDL2) if (modes) { @@ -383,10 +395,9 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, int surface_flags_window = SURFACE_FLAGS; #if defined(TARGET_SDL2) -#if 1 +#if USE_DESKTOP_FULLSCREEN int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP; #else - // (never used with SDL2 now) int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN; #endif @@ -402,7 +413,12 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, #if defined(TARGET_SDL2) #if USE_RENDERER - float scale_factor = 1.2; + float window_scaling_factor = (float)setup.window_scaling_percent / 100; + float screen_scaling_factor = (fullscreen ? 1 : window_scaling_factor); + +#if 1 + printf("::: use window scaling factor %f\n", screen_scaling_factor); +#endif if ((*backbuffer)->surface) SDL_FreeSurface((*backbuffer)->surface); @@ -419,8 +435,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, sdl_window = SDL_CreateWindow(program.window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - (int)(scale_factor * width), - (int)(scale_factor * height), + (int)(screen_scaling_factor * width), + (int)(screen_scaling_factor * height), surface_flags); if (sdl_window != NULL) @@ -584,7 +600,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) #if defined(TARGET_SDL2) #if USE_RENDERER - float scale_factor = 1.2; + float screen_scaling_factor = 1.2; int test_fullscreen = 0; int surface_flags = (test_fullscreen ? surface_flags_fullscreen : surface_flags_window); @@ -604,8 +620,8 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) sdl_window = SDL_CreateWindow(program.window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - (int)(scale_factor * video.width), - (int)(scale_factor * video.height), + (int)(screen_scaling_factor * video.width), + (int)(screen_scaling_factor * video.height), surface_flags); if (sdl_window != NULL) @@ -697,6 +713,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) (*backbuffer)->surface = new_surface; video.fullscreen_enabled = FALSE; + video.window_scaling_percent = setup.window_scaling_percent; success = TRUE; } diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 16c62c0f..e86253e3 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -49,6 +49,10 @@ #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE +#if defined(TARGET_SDL2) +#define USE_DESKTOP_FULLSCREEN TRUE +#endif + #define CURSOR_MAX_WIDTH 32 #define CURSOR_MAX_HEIGHT 32 diff --git a/src/libgame/system.c b/src/libgame/system.c index 988a97fa..0c750452 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -449,6 +449,8 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) video.fullscreen_modes = NULL; #endif + video.window_scaling_available = TRUE; + #if defined(TARGET_SDL) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); #else diff --git a/src/libgame/system.h b/src/libgame/system.h index 9f997cf1..68a56cdd 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -644,6 +644,11 @@ gfx.draw_busy_anim_function(); \ } +/* values for window scaling */ +#define MIN_WINDOW_SCALING_PERCENT 10 +#define STD_WINDOW_SCALING_PERCENT 100 +#define MAX_WINDOW_SCALING_PERCENT 300 + /* type definitions */ #if defined(TARGET_SDL2) @@ -728,6 +733,9 @@ struct VideoSystemInfo boolean fullscreen_enabled; struct ScreenModeInfo *fullscreen_modes; char *fullscreen_mode_current; + + boolean window_scaling_available; + int window_scaling_percent; }; struct AudioSystemInfo @@ -937,6 +945,7 @@ struct SetupInfo boolean time_limit; boolean fullscreen; char *fullscreen_mode; + int window_scaling_percent; boolean ask_on_escape; boolean ask_on_escape_editor; boolean quick_switch; diff --git a/src/screens.c b/src/screens.c index 2392bcf0..fe3b75ea 100644 --- a/src/screens.c +++ b/src/screens.c @@ -59,15 +59,16 @@ /* sub-screens on the setup screen (specific) */ #define SETUP_MODE_CHOOSE_GAME_SPEED 15 #define SETUP_MODE_CHOOSE_SCREEN_MODE 16 -#define SETUP_MODE_CHOOSE_SCROLL_DELAY 17 -#define SETUP_MODE_CHOOSE_GRAPHICS 18 -#define SETUP_MODE_CHOOSE_SOUNDS 19 -#define SETUP_MODE_CHOOSE_MUSIC 20 -#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 21 -#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 22 -#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 23 +#define SETUP_MODE_CHOOSE_WINDOW_SIZE 17 +#define SETUP_MODE_CHOOSE_SCROLL_DELAY 18 +#define SETUP_MODE_CHOOSE_GRAPHICS 19 +#define SETUP_MODE_CHOOSE_SOUNDS 20 +#define SETUP_MODE_CHOOSE_MUSIC 21 +#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE 22 +#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 23 +#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 24 -#define MAX_SETUP_MODES 24 +#define MAX_SETUP_MODES 25 /* for input setup functions */ #define SETUPINPUT_SCREEN_POS_START 0 @@ -174,6 +175,9 @@ static int setup_mode = SETUP_MODE_MAIN; static TreeInfo *screen_modes = NULL; static TreeInfo *screen_mode_current = NULL; +static TreeInfo *window_sizes = NULL; +static TreeInfo *window_size_current = NULL; + static TreeInfo *scroll_delays = NULL; static TreeInfo *scroll_delay_current = NULL; @@ -192,6 +196,28 @@ static TreeInfo *volume_music_current = NULL; static TreeInfo *level_number = NULL; static TreeInfo *level_number_current = NULL; +static struct +{ + int value; + char *text; +} window_sizes_list[] = +{ + { 50, "50 %" }, + { 80, "80 %" }, + { 90, "90 %" }, + { 100, "100 % (Default)" }, + { 110, "110 %" }, + { 120, "120 %" }, + { 130, "130 %" }, + { 140, "140 %" }, + { 150, "150 %" }, + { 200, "200 %" }, + { 250, "250 %" }, + { 300, "300 %" }, + + { -1, NULL }, +}; + static struct { int value; @@ -3590,6 +3616,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED) execSetupGame(); else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE || + setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE || setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) execSetupGraphics(); else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE || @@ -3780,6 +3807,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (setup_mode == SETUP_MODE_CHOOSE_GAME_SPEED) execSetupGame(); else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE || + setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE || setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) execSetupGraphics(); else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE || @@ -4046,6 +4074,7 @@ static struct TokenInfo *setup_info; static int num_setup_info; static char *screen_mode_text; +static char *window_size_text; static char *scroll_delay_text; static char *game_speed_text; static char *graphics_set_name; @@ -4132,6 +4161,7 @@ static void execSetupEditor() static void execSetupGraphics() { + if (video.fullscreen_available && screen_modes == NULL) { int i; @@ -4188,6 +4218,55 @@ static void execSetupGraphics() screen_mode_text = screen_mode_current->name; } + if (window_sizes == NULL) + { + int i; + + for (i = 0; window_sizes_list[i].value != -1; i++) + { + TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED); + char identifier[32], name[32]; + int value = window_sizes_list[i].value; + char *text = window_sizes_list[i].text; + + ti->node_top = &window_sizes; + ti->sort_priority = value; + + sprintf(identifier, "%d", value); + sprintf(name, "%s", text); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + setString(&ti->infotext, "Window Scaling"); + + pushTreeInfo(&window_sizes, ti); + } + + /* sort window size values to start with lowest window size value */ + sortTreeInfo(&window_sizes); + + /* set current window size value to configured window size value */ + window_size_current = + getTreeInfoFromIdentifier(window_sizes, + i_to_a(setup.window_scaling_percent)); + + /* if that fails, set current window size to reliable default value */ + if (window_size_current == NULL) + window_size_current = + getTreeInfoFromIdentifier(window_sizes, + i_to_a(STD_WINDOW_SCALING_PERCENT)); + + /* if that also fails, set current window size to first available value */ + if (window_size_current == NULL) + window_size_current = window_sizes; + } + + setup.window_scaling_percent = atoi(window_size_current->identifier); + + /* needed for displaying window size text instead of identifier */ + window_size_text = window_size_current->name; + #if 1 if (scroll_delays == NULL) { @@ -4242,7 +4321,19 @@ static void execSetupGraphics() DrawSetupScreen(); } -#if !defined(TARGET_SDL2) +#if defined(TARGET_SDL2) +static void execSetupChooseWindowSize() +{ +#if 0 + if (!video.window_scaling_available) + return; +#endif + + setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE; + + DrawSetupScreen(); +} +#else static void execSetupChooseScreenMode() { if (!video.fullscreen_available) @@ -4603,7 +4694,10 @@ static struct TokenInfo setup_info_editor[] = static struct TokenInfo setup_info_graphics[] = { { TYPE_SWITCH, &setup.fullscreen, "Fullscreen:" }, -#if !defined(TARGET_SDL2) +#if defined(TARGET_SDL2) + { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" }, + { TYPE_STRING, &window_size_text, "" }, +#else { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" }, { TYPE_STRING, &screen_mode_text, "" }, #endif @@ -5127,7 +5221,8 @@ static void DrawSetupScreen_Generic() (value_ptr == &setup.sound_loops && !audio.loops_available) || (value_ptr == &setup.sound_music && !audio.music_available) || (value_ptr == &setup.fullscreen && !video.fullscreen_available) || - (value_ptr == &screen_mode_text && !video.fullscreen_available)) + (value_ptr == &screen_mode_text && !video.fullscreen_available) || + (value_ptr == &window_size_text && !video.window_scaling_available)) setup_info[i].type |= TYPE_GHOSTED; if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST)) @@ -5963,6 +6058,8 @@ void DrawSetupScreen() DrawChooseTree(&game_speed_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE) DrawChooseTree(&screen_mode_current); + else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE) + DrawChooseTree(&window_size_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) DrawChooseTree(&scroll_delay_current); else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS) @@ -5998,6 +6095,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) HandleChooseTree(mx, my, dx, dy, button, &game_speed_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE) HandleChooseTree(mx, my, dx, dy, button, &screen_mode_current); + else if (setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE) + HandleChooseTree(mx, my, dx, dy, button, &window_size_current); else if (setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY) HandleChooseTree(mx, my, dx, dy, button, &scroll_delay_current); else if (setup_mode == SETUP_MODE_CHOOSE_GRAPHICS) diff --git a/src/tools.c b/src/tools.c index bd71d0c5..eefc5cb6 100644 --- a/src/tools.c +++ b/src/tools.c @@ -8990,11 +8990,19 @@ void ToggleFullscreenIfNeeded() boolean change_fullscreen_mode = (video.fullscreen_enabled && !strEqual(setup.fullscreen_mode, video.fullscreen_mode_current)); + boolean change_window_scaling_percent = (!video.fullscreen_enabled && + setup.window_scaling_percent != + video.window_scaling_percent); - if (!video.fullscreen_available) + if (change_window_scaling_percent && video.fullscreen_enabled) return; - if (change_fullscreen || change_fullscreen_mode) + if (!change_window_scaling_percent && !video.fullscreen_available) + return; + + if (change_fullscreen || + change_fullscreen_mode || + change_window_scaling_percent) { Bitmap *tmp_backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH); @@ -9007,9 +9015,16 @@ void ToggleFullscreenIfNeeded() video.fullscreen_enabled = FALSE; /* force new fullscreen mode */ } + if (change_window_scaling_percent) + { + /* keep window mode, but change window scaling */ + video.fullscreen_enabled = TRUE; /* force new window scaling */ + } + /* toggle fullscreen */ ChangeVideoModeIfNeeded(setup.fullscreen); + /* set setup value according to successfully enabled fullscreen mode */ setup.fullscreen = video.fullscreen_enabled; /* restore backbuffer content from temporary backbuffer backup bitmap */ -- 2.34.1