[Scummvm-git-logs] scummvm master -> 658a9ddb050694451cd1cb13910f53b284f90167

dreammaster noreply at scummvm.org
Wed Mar 23 05:32:28 UTC 2022


This automated email contains information about 11 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1ad9fe0a37 AGS: Deprecated "ScreenSizeDefinition" option as overcomplicating
d7727eb964 AGS: Separate configs for fullscreen and windowed modes
c4e7bd355b AGS: Distinct "real fullscreen" and "desktop fullscreen" window mode
dc3ce9f70a AGS: Renamed few font functions for consistent naming style
df29806aec AGS: Replaced the remaining wgettextheight() with get_font_height()
e9c153ad4a AGS: Removed unused function getfontlinegap()
977925d105 AGS: Some fixes of namespace Common to be Shared
d42b639142 AGS: Always precalculate and save font linespacing (as outlined)
ba47a913bf AGS: Add missing code from 43425f738dc6beb7d0758e256a840c5f37a4d38a
3e6c42ab8d AGS: get_font_height() returns compatible height
658a9ddb05 AGS: Wrap unused function in ifdef check


Commit: 1ad9fe0a377299e902b9bf5000b1d11f39e7123c
    https://github.com/scummvm/scummvm/commit/1ad9fe0a377299e902b9bf5000b1d11f39e7123c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:12-07:00

Commit Message:
AGS: Deprecated "ScreenSizeDefinition" option as overcomplicating

>From upstream 997170c80c6189b0f4d6940cc1817dabcd77fe30

Changed paths:
    engines/ags/engine/ac/game_setup.cpp
    engines/ags/engine/main/config.cpp
    engines/ags/engine/main/config.h
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/graphics_mode.cpp
    engines/ags/engine/main/graphics_mode.h


diff --git a/engines/ags/engine/ac/game_setup.cpp b/engines/ags/engine/ac/game_setup.cpp
index e41aa0dbd1c..e17e9241ed4 100644
--- a/engines/ags/engine/ac/game_setup.cpp
+++ b/engines/ags/engine/ac/game_setup.cpp
@@ -40,8 +40,6 @@ GameSetup::GameSetup() {
 	RenderAtScreenRes = false;
 	Supersampling = 1;
 
-	Screen.DisplayMode.ScreenSize.MatchDeviceRatio = true;
-	Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_MaxDisplay;
 	Screen.DisplayMode.RefreshRate = 0;
 	Screen.DisplayMode.VSync = false;
 	Screen.DisplayMode.Windowed = false;
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index 233d32013c8..6697462350c 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -94,14 +94,23 @@ void INIwritestring(ConfigTree &cfg, const String &sectn, const String &item, co
 	cfg[sectn][item] = value;
 }
 
-ScreenSizeDefinition parse_screendef(const String &option, ScreenSizeDefinition def_value) {
+// Legacy screen size definition
+enum ScreenSizeDefinition {
+	kScreenDef_Undefined = -1,
+	kScreenDef_Explicit,        // define by width & height
+	kScreenDef_ByGameScaling,   // define by game scale factor
+	kScreenDef_MaxDisplay,      // set to maximal supported (desktop/device screen size)
+	kNumScreenDef
+};
+
+ScreenSizeDefinition parse_screendef(const String &option) {
 	const char *screen_sz_def_options[kNumScreenDef] = { "explicit", "scaling", "max" };
 	for (int i = 0; i < kNumScreenDef; ++i) {
 		if (option.CompareNoCase(screen_sz_def_options[i]) == 0) {
 			return (ScreenSizeDefinition)i;
 		}
 	}
-	return def_value;
+	return kScreenDef_Undefined;
 }
 
 FrameScaleDef parse_scaling_option(const String &option) {
@@ -172,15 +181,10 @@ int convert_fp_to_scaling(uint32_t scaling) {
 void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, FrameScaleDef &frame) {
 	scsz_setup.Size = Size();
 	if (windowed) {
-		// For the windowed we define mode by the scaled game.
-		scsz_setup.SizeDef = kScreenDef_ByGameScaling;
-		scsz_setup.MatchDeviceRatio = false;
+		scsz_setup = ScreenSizeSetup();
 		frame = _GP(usetup).Screen.WinGameFrame;
 	} else {
-		// For the fullscreen we set current desktop resolution, which
-		// corresponds to most comfortable fullscreen mode for the driver.
-		scsz_setup.SizeDef = kScreenDef_MaxDisplay;
-		scsz_setup.MatchDeviceRatio = true;
+		scsz_setup = ScreenSizeSetup();
 		frame = _GP(usetup).Screen.FsGameFrame;
 	}
 }
@@ -223,32 +227,51 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 		String legacy_filter = INIreadstring(cfg, "misc", "gfxfilter");
 		if (!legacy_filter.IsEmpty()) {
 			// NOTE: legacy scaling config is applied only to windowed setting
-			if (_GP(usetup).Screen.DisplayMode.Windowed)
-				_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
 			int scale_factor; // FIXME
 			parse_legacy_frame_config(legacy_filter, _GP(usetup).Screen.Filter.ID, _GP(usetup).Screen.WinGameFrame,
 				scale_factor);
 
 			// AGS 3.2.1 and 3.3.0 aspect ratio preferences
 			if (!_GP(usetup).Screen.DisplayMode.Windowed) {
+				/* FIXME --- set FsGameFrame?
 				_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio =
 					(INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
-						INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
+					 INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
+				*/
 			}
 		}
 
 		// AGS 3.4.0 - 3.4.1-rc uniform scaling option
 		String uniform_frame_scale = INIreadstring(cfg, "graphics", "game_scale");
+		int src_scale = 1;
 		if (!uniform_frame_scale.IsEmpty()) {
-			int scale;
-			FrameScaleDef frame = parse_legacy_scaling_option(uniform_frame_scale, scale);
+			FrameScaleDef frame = parse_legacy_scaling_option(uniform_frame_scale, src_scale);
 			_GP(usetup).Screen.FsGameFrame = frame;
 			_GP(usetup).Screen.WinGameFrame = frame;
 		}
+
+		// AGS 3.5.* gfx mode with screen definition
+		ScreenSizeDefinition scr_def = parse_screendef(INIreadstring(cfg, "graphics", "screen_def"));
+		switch (scr_def) {
+		case kScreenDef_Explicit:
+			_GP(usetup).Screen.DisplayMode.ScreenSize.Size = Size(
+				INIreadint(cfg, "graphics", "screen_width"),
+				INIreadint(cfg, "graphics", "screen_height"));
+			break;
+		case kScreenDef_ByGameScaling:
+			INIreadint(cfg, "graphics", "windowed") ?
+				parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win"), src_scale) :
+				parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs"), src_scale);
+			_GP(usetup).Screen.DisplayMode.ScreenSize.Scale = src_scale;
+			break;
+		default:
+			// set nothing
+			break;
 		}
+	}
 
 	_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "misc", "refresh");
-	}
+}
 
 void override_config_ext(ConfigTree &cfg) {
 	// Mobile ports always run in fullscreen mode
@@ -304,7 +327,7 @@ void override_config_ext(ConfigTree &cfg) {
 
 	INIwriteint(cfg, "misc", "antialias", _G(psp_gfx_smooth_sprites) != 0);
 	INIwritestring(cfg, "language", "translation", _G(psp_translation));
-	}
+}
 
 void apply_config(const ConfigTree &cfg) {
 	{
@@ -318,13 +341,6 @@ void apply_config(const ConfigTree &cfg) {
 		_GP(usetup).Screen.DriverID = INIreadstring(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
 
 		_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
-		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = _GP(usetup).Screen.DisplayMode.Windowed ? kScreenDef_ByGameScaling : kScreenDef_MaxDisplay;
-		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = parse_screendef(INIreadstring(cfg, "graphics", "screen_def"),
-			_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef);
-
-		_GP(usetup).Screen.DisplayMode.ScreenSize.Size = Size(INIreadint(cfg, "graphics", "screen_width"),
-			INIreadint(cfg, "graphics", "screen_height"));
-		_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio = INIreadint(cfg, "graphics", "match_device_ratio", 1) != 0;
 		// TODO: move to config overrides (replace values during config load)
 #if AGS_PLATFORM_OS_MACOS
 		_GP(usetup).Screen.Filter.ID = "none";
diff --git a/engines/ags/engine/main/config.h b/engines/ags/engine/main/config.h
index 8aebc32baeb..20ec8e43d1c 100644
--- a/engines/ags/engine/main/config.h
+++ b/engines/ags/engine/main/config.h
@@ -47,7 +47,6 @@ void post_config();
 
 void save_config_file();
 
-ScreenSizeDefinition parse_screendef(const String &option, ScreenSizeDefinition def_value);
 FrameScaleDef parse_scaling_option(const String &option);
 String make_scaling_option(FrameScaleDef scale_def);
 uint32_t convert_scaling_to_fp(int scale_factor);
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index be8713cf393..c938d32ecf9 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -180,10 +180,10 @@ void engine_force_window() {
 	// TODO: actually overwrite config tree instead
 	if (_G(force_window) == 1) {
 		_GP(usetup).Screen.DisplayMode.Windowed = true;
-		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_ByGameScaling;
+		_GP(usetup).Screen.DisplayMode.ScreenSize = ScreenSizeSetup();
 	} else if (_G(force_window) == 2) {
 		_GP(usetup).Screen.DisplayMode.Windowed = false;
-		_GP(usetup).Screen.DisplayMode.ScreenSize.SizeDef = kScreenDef_MaxDisplay;
+		_GP(usetup).Screen.DisplayMode.ScreenSize = ScreenSizeSetup();
 	}
 }
 
diff --git a/engines/ags/engine/main/graphics_mode.cpp b/engines/ags/engine/main/graphics_mode.cpp
index 051dab4b7e1..e0f314bed08 100644
--- a/engines/ags/engine/main/graphics_mode.cpp
+++ b/engines/ags/engine/main/graphics_mode.cpp
@@ -49,11 +49,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-ScreenSizeSetup::ScreenSizeSetup()
-	: SizeDef(kScreenDef_MaxDisplay)
-	, MatchDeviceRatio(true) {
-}
-
 DisplayModeSetup::DisplayModeSetup()
 	: RefreshRate(0)
 	, VSync(false)
@@ -203,47 +198,29 @@ Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup
 #if AGS_PLATFORM_SCUMMVM
 	return game_size;
 #else
-	Size screen_size, frame_size;
-	Size device_size = get_max_display_size(dm_setup.Windowed);
-
 	// Set requested screen (window) size, depending on screen definition option
+	const bool windowed = dm_setup.Windowed;
 	ScreenSizeSetup scsz = dm_setup.ScreenSize;
-	switch (scsz.SizeDef) {
-	case kScreenDef_Explicit:
-		// Use resolution from user config
-		screen_size = scsz.Size;
-		if (screen_size.IsNull()) {
-			// If the configuration did not define proper screen size,
-			// use the scaled game size instead
-			frame_size = set_game_frame_after_screen_size(game_size, device_size, frame);
-			if (screen_size.Width <= 0)
-				screen_size.Width = frame_size.Width;
-			if (screen_size.Height <= 0)
-				screen_size.Height = frame_size.Height;
-		}
-		break;
-	case kScreenDef_ByGameScaling:
-		// Use game frame (scaled game) size
-		frame_size = set_game_frame_after_screen_size(game_size, device_size, frame);
-		screen_size = frame_size;
-		break;
-	case kScreenDef_MaxDisplay:
-		// Set as big as current device size
-		screen_size = device_size;
-		break;
-	default:
-		break;
+	if (!scsz.Size.IsNull()) {
+		// Use explicit resolution from user config
+		return scsz.Size;
+	} else if (scsz.Scale > 0) {
+		return get_game_frame_from_screen_size(game_size, get_max_display_size(windowed), frame, scsz.Scale);
 	}
-	return screen_size;
+	// If nothing is set, then for the fullscreen mode set as big as current device/desktop size;
+	// for the windowed mode assume maximal size inside desktop using given frame scaling
+	if (windowed)
+		return get_game_frame_from_screen_size(game_size, get_max_display_size(windowed), frame);
+	return get_max_display_size(false);
 #endif
 }
 
 // Find closest possible compatible display mode and initialize it
-bool try_init_compatible_mode(const DisplayMode &dm, const bool match_device_ratio) {
+bool try_init_compatible_mode(const DisplayMode &dm) {
 	const Size &screen_size = Size(dm.Width, dm.Height);
 	// Find nearest compatible mode and init that
 	Debug::Printf("Attempting to find nearest supported resolution for screen size %d x %d (%d-bit) %s",
-	              dm.Width, dm.Height, dm.ColorDepth, dm.Windowed ? "windowed" : "fullscreen");
+		dm.Width, dm.Height, dm.ColorDepth, dm.Windowed ? "windowed" : "fullscreen");
 	const Size device_size = get_max_display_size(dm.Windowed);
 	if (dm.Windowed)
 		Debug::Printf("Maximal allowed window size: %d x %d", device_size.Width, device_size.Height);
@@ -254,20 +231,15 @@ bool try_init_compatible_mode(const DisplayMode &dm, const bool match_device_rat
 	// Windowed mode
 	if (dm.Windowed) {
 		// If windowed mode, make the resolution stay in the generally supported limits
-		dm_compat.Width = Math::Min<int32_t>(dm_compat.Width, device_size.Width);
-		dm_compat.Height = Math::Min<int32_t>(dm_compat.Height, device_size.Height);
+		dm_compat.Width = Math::Min(dm_compat.Width, device_size.Width);
+		dm_compat.Height = Math::Min(dm_compat.Height, device_size.Height);
 	}
 	// Fullscreen mode
 	else {
-		// If told to find mode with aspect ratio matching current desktop resolution, then first
-		// try find matching one, and if failed then try any compatible one
+		// Try to find any compatible mode from the list of available ones
 		bool mode_found = false;
-		if (modes.get()) {
-			if (match_device_ratio)
-				mode_found = find_nearest_supported_mode(*modes.get(), screen_size, dm.ColorDepth, &device_size, nullptr, dm_compat);
-			if (!mode_found)
-				mode_found = find_nearest_supported_mode(*modes.get(), screen_size, dm.ColorDepth, nullptr, nullptr, dm_compat);
-		}
+		if (modes.get())
+			mode_found = find_nearest_supported_mode(*modes.get(), screen_size, dm.ColorDepth, nullptr, nullptr, dm_compat);
 		if (!mode_found)
 			Debug::Printf("Could not find compatible fullscreen mode. Will try to force-set mode requested by user and fallback to windowed mode if that fails.");
 		dm_compat.Vsync = dm.Vsync;
@@ -296,7 +268,7 @@ bool try_init_mode_using_setup(const GraphicResolution &game_res, const DisplayM
 	const Size screen_size = precalc_screen_size(game_res, dm_setup, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, col_depth),
 		dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
-	if (!try_init_compatible_mode(dm, dm_setup.ScreenSize.SizeDef == kScreenDef_Explicit ? false : dm_setup.ScreenSize.MatchDeviceRatio))
+	if (!try_init_compatible_mode(dm))
 		return false;
 
 	// Set up native size and render frame
@@ -401,7 +373,7 @@ void display_gfx_mode_error(const Size &game_size, const ScreenSetup &setup, con
 	ScreenSizeSetup scsz = setup.DisplayMode.ScreenSize;
 	PGfxFilter filter = _G(gfxDriver) ? _G(gfxDriver)->GetGraphicsFilter() : PGfxFilter();
 	Size wanted_screen;
-	if (scsz.SizeDef == kScreenDef_Explicit)
+	if (!scsz.Size.IsNull())
 		main_error.Format("There was a problem initializing graphics mode %d x %d (%d-bit), or finding nearest compatible mode, with game size %d x %d and filter '%s'.",
 		                  scsz.Size.Width, scsz.Size.Height, color_depth, game_size.Width, game_size.Height, filter ? filter->GetInfo().Id.GetCStr() : "Undefined");
 	else
@@ -422,16 +394,14 @@ bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup
 	else
 		Debug::Printf(kDbgMsg_Error, "Unable to obtain device resolution");
 
-	const char *screen_sz_def_options[kNumScreenDef] = { "explicit", "scaling", "max" };
 	ScreenSizeSetup scsz = setup.DisplayMode.ScreenSize;
-	const bool ignore_device_ratio = setup.DisplayMode.Windowed || scsz.SizeDef == kScreenDef_Explicit;
 	FrameScaleDef gameframe = setup.DisplayMode.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
 	const String scale_option = make_scaling_option(gameframe);
-	Debug::Printf(kDbgMsg_Info, "Graphic settings: driver: %s, windowed: %s, screen def: %s, screen size: %d x %d, match device ratio: %s, game scale: %s",
-	              setup.DriverID.GetCStr(),
-	              setup.DisplayMode.Windowed ? "yes" : "no", screen_sz_def_options[scsz.SizeDef],
-	              scsz.Size.Width, scsz.Size.Height,
-	              ignore_device_ratio ? "ignore" : (scsz.MatchDeviceRatio ? "yes" : "no"), scale_option.GetCStr());
+	Debug::Printf(kDbgMsg_Info, "Graphic settings: driver: %s, windowed: %s, screen size: %d x %d, game scale: %s",
+		setup.DriverID.GetCStr(),
+		setup.DisplayMode.Windowed ? "yes" : "no",
+		scsz.Size.Width, scsz.Size.Height,
+		scale_option.GetCStr());
 
 	// Prepare the list of available gfx factories, having the one requested by user at first place
 	// TODO: make factory & driver IDs case-insensitive!
@@ -448,14 +418,14 @@ bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup
 
 	// Try to create renderer and init gfx mode, choosing one factory at a time
 	bool result = false;
-	for (StringV::const_iterator sit = ids.begin(); sit != ids.end(); ++sit) {
+	for (StringV::const_iterator it = ids.begin(); it != ids.end(); ++it) {
 		result =
 #ifdef USE_SIMPLE_GFX_INIT
-		    simple_create_gfx_driver_and_init_mode
+			simple_create_gfx_driver_and_init_mode
 #else
-		    create_gfx_driver_and_init_mode_any
+			create_gfx_driver_and_init_mode_any
 #endif
-		    (*sit, game_res, setup.DisplayMode, color_depth, gameframe, setup.Filter);
+			(*it, game_res, setup.DisplayMode, color_depth, gameframe, setup.Filter);
 
 		if (result)
 			break;
@@ -490,7 +460,7 @@ bool graphics_mode_set_dm_any(const Size &game_size, const DisplayModeSetup &dm_
 	const Size screen_size = precalc_screen_size(game_size, dm_setup, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, color_depth.Bits),
 	               dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
-	return try_init_compatible_mode(dm, dm_setup.ScreenSize.MatchDeviceRatio);
+	return try_init_compatible_mode(dm);
 }
 
 bool graphics_mode_set_dm(const DisplayMode &dm) {
diff --git a/engines/ags/engine/main/graphics_mode.h b/engines/ags/engine/main/graphics_mode.h
index a124276f7e0..81e9d6fff66 100644
--- a/engines/ags/engine/main/graphics_mode.h
+++ b/engines/ags/engine/main/graphics_mode.h
@@ -60,20 +60,14 @@ enum FrameScaleDef {
 	kNumFrameScaleDef
 };
 
-enum ScreenSizeDefinition {
-	kScreenDef_Explicit,        // define by width & height
-	kScreenDef_ByGameScaling,   // define by game scale factor
-	kScreenDef_MaxDisplay,      // set to maximal supported (desktop/device screen size)
-	kNumScreenDef
-};
-
 // Configuration that is used to determine the size of the screen
 struct ScreenSizeSetup {
-	ScreenSizeDefinition SizeDef;       // a method used to determine screen size
-	AGS3::Size           Size;          // explicitly defined screen metrics
-	bool                 MatchDeviceRatio; // whether to choose resolution matching device aspect ratio
+	AGS3::Size           Size;      // explicit screen metrics
+	int                  Scale = 0; // explicit game scale factor
 
-	ScreenSizeSetup();
+	ScreenSizeSetup() = default;
+	ScreenSizeSetup(const AGS3::Size & sz, int scale = 0) : Size(sz), Scale(scale) {
+	}
 };
 
 // Display mode configuration


Commit: d7727eb96492fb6fa25508f5a25d54d3e94ced74
    https://github.com/scummvm/scummvm/commit/d7727eb96492fb6fa25508f5a25d54d3e94ced74
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:13-07:00

Commit Message:
AGS: Separate configs for fullscreen and windowed modes

>From upstream 96a1868fcf5d5aa0c070feaebc912c969348db0f

Changed paths:
    engines/ags/engine/ac/game_setup.cpp
    engines/ags/engine/ac/game_setup.h
    engines/ags/engine/main/config.cpp
    engines/ags/engine/main/config.h
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/engine.h
    engines/ags/engine/main/graphics_mode.cpp
    engines/ags/engine/main/graphics_mode.h


diff --git a/engines/ags/engine/ac/game_setup.cpp b/engines/ags/engine/ac/game_setup.cpp
index e17e9241ed4..ff6c7a52439 100644
--- a/engines/ags/engine/ac/game_setup.cpp
+++ b/engines/ags/engine/ac/game_setup.cpp
@@ -40,9 +40,9 @@ GameSetup::GameSetup() {
 	RenderAtScreenRes = false;
 	Supersampling = 1;
 
-	Screen.DisplayMode.RefreshRate = 0;
-	Screen.DisplayMode.VSync = false;
-	Screen.DisplayMode.Windowed = false;
+	Screen.Params.RefreshRate = 0;
+	Screen.Params.VSync = false;
+	Screen.Windowed = false;
 	Screen.FsGameFrame = kFrame_Proportional;
 	Screen.WinGameFrame = kFrame_Round;
 }
diff --git a/engines/ags/engine/ac/game_setup.h b/engines/ags/engine/ac/game_setup.h
index 16933b6efc9..d165bd62f71 100644
--- a/engines/ags/engine/ac/game_setup.h
+++ b/engines/ags/engine/ac/game_setup.h
@@ -83,7 +83,7 @@ struct GameSetup {
 	bool  RenderAtScreenRes; // render sprites at screen resolution, as opposed to native one
 	int   Supersampling;
 
-	ScreenSetup Screen;
+	DisplayModeSetup Screen;
 
 	GameSetup();
 };
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index 6697462350c..3bb52d222a1 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -178,17 +178,6 @@ int convert_fp_to_scaling(uint32_t scaling) {
 	return scaling >= kUnit ? (scaling >> kShift) : -kUnit / (int32_t)scaling;
 }
 
-void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, FrameScaleDef &frame) {
-	scsz_setup.Size = Size();
-	if (windowed) {
-		scsz_setup = ScreenSizeSetup();
-		frame = _GP(usetup).Screen.WinGameFrame;
-	} else {
-		scsz_setup = ScreenSizeSetup();
-		frame = _GP(usetup).Screen.FsGameFrame;
-	}
-}
-
 String find_default_cfg_file() {
 	return Path::ConcatPaths(_GP(usetup).startup_dir, DefaultConfigFileName);
 }
@@ -220,7 +209,7 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 		_GP(usetup).override_upscale = true; // run low-res game in high-res mode
 	}
 
-	_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
+	_GP(usetup).Screen.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
 	_GP(usetup).Screen.DriverID = INIreadstring(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
 
 	{
@@ -232,7 +221,7 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 				scale_factor);
 
 			// AGS 3.2.1 and 3.3.0 aspect ratio preferences
-			if (!_GP(usetup).Screen.DisplayMode.Windowed) {
+			if (!_GP(usetup).Screen.Windowed) {
 				/* FIXME --- set FsGameFrame?
 				_GP(usetup).Screen.DisplayMode.ScreenSize.MatchDeviceRatio =
 					(INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
@@ -254,15 +243,17 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 		ScreenSizeDefinition scr_def = parse_screendef(INIreadstring(cfg, "graphics", "screen_def"));
 		switch (scr_def) {
 		case kScreenDef_Explicit:
-			_GP(usetup).Screen.DisplayMode.ScreenSize.Size = Size(
-				INIreadint(cfg, "graphics", "screen_width"),
-				INIreadint(cfg, "graphics", "screen_height"));
+			_GP(usetup).Screen.FsSetup =
+				_GP(usetup).Screen.WinSetup = WindowSetup(Size(
+					INIreadint(cfg, "graphics", "screen_width"),
+					INIreadint(cfg, "graphics", "screen_height")));
 			break;
 		case kScreenDef_ByGameScaling:
 			INIreadint(cfg, "graphics", "windowed") ?
 				parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win"), src_scale) :
 				parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs"), src_scale);
-			_GP(usetup).Screen.DisplayMode.ScreenSize.Scale = src_scale;
+			_GP(usetup).Screen.FsSetup =
+				_GP(usetup).Screen.WinSetup = WindowSetup(src_scale);
 			break;
 		default:
 			// set nothing
@@ -270,7 +261,7 @@ void read_legacy_graphics_config(const ConfigTree &cfg) {
 		}
 	}
 
-	_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "misc", "refresh");
+	_GP(usetup).Screen.Params.RefreshRate = INIreadint(cfg, "misc", "refresh");
 }
 
 void override_config_ext(ConfigTree &cfg) {
@@ -340,7 +331,7 @@ void apply_config(const ConfigTree &cfg) {
 		// Graphics mode
 		_GP(usetup).Screen.DriverID = INIreadstring(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
 
-		_GP(usetup).Screen.DisplayMode.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
+		_GP(usetup).Screen.Windowed = INIreadint(cfg, "graphics", "windowed") > 0;
 		// TODO: move to config overrides (replace values during config load)
 #if AGS_PLATFORM_OS_MACOS
 		_GP(usetup).Screen.Filter.ID = "none";
@@ -352,8 +343,8 @@ void apply_config(const ConfigTree &cfg) {
 			parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "round"));
 #endif
 
-		_GP(usetup).Screen.DisplayMode.RefreshRate = INIreadint(cfg, "graphics", "refresh");
-		_GP(usetup).Screen.DisplayMode.VSync = INIreadint(cfg, "graphics", "vsync") > 0;
+		_GP(usetup).Screen.Params.RefreshRate = INIreadint(cfg, "graphics", "refresh");
+		_GP(usetup).Screen.Params.VSync = INIreadint(cfg, "graphics", "vsync") > 0;
 		_GP(usetup).RenderAtScreenRes = INIreadint(cfg, "graphics", "render_at_screenres") > 0;
 		_GP(usetup).Supersampling = INIreadint(cfg, "graphics", "supersampling", 1);
 
diff --git a/engines/ags/engine/main/config.h b/engines/ags/engine/main/config.h
index 20ec8e43d1c..15a41d39a13 100644
--- a/engines/ags/engine/main/config.h
+++ b/engines/ags/engine/main/config.h
@@ -51,8 +51,6 @@ FrameScaleDef parse_scaling_option(const String &option);
 String make_scaling_option(FrameScaleDef scale_def);
 uint32_t convert_scaling_to_fp(int scale_factor);
 int convert_fp_to_scaling(uint32_t scaling);
-// Fill in setup structs with default settings for the given mode (windowed or fullscreen)
-void graphics_mode_get_defaults(bool windowed, ScreenSizeSetup &scsz_setup, FrameScaleDef &frame);
 
 bool INIreaditem(const ConfigTree &cfg, const String &sectn, const String &item, String &value);
 int INIreadint(const ConfigTree &cfg, const String &sectn, const String &item, int def_value = 0);
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index c938d32ecf9..c31748a1ad5 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -179,11 +179,9 @@ void engine_force_window() {
 	// Force to run in a window, override the config file
 	// TODO: actually overwrite config tree instead
 	if (_G(force_window) == 1) {
-		_GP(usetup).Screen.DisplayMode.Windowed = true;
-		_GP(usetup).Screen.DisplayMode.ScreenSize = ScreenSizeSetup();
+		_GP(usetup).Screen.Windowed = true;
 	} else if (_G(force_window) == 2) {
-		_GP(usetup).Screen.DisplayMode.Windowed = false;
-		_GP(usetup).Screen.DisplayMode.ScreenSize = ScreenSizeSetup();
+		_GP(usetup).Screen.Windowed = false;
 	}
 }
 
@@ -523,7 +521,7 @@ int engine_check_disk_space() {
 
 int engine_check_font_was_loaded() {
 	if (!font_first_renderer_loaded()) {
-		_G(platform)->DisplayAlert("No game fonts found. At least one font is required to run the game.");
+		_G(platform)->DisplayAlert("No game fonts found. At least one font is required to run the _GP(game).");
 		_G(proper_exit) = 1;
 		return EXIT_ERROR;
 	}
@@ -1236,7 +1234,7 @@ int initialize_engine(const ConfigTree &startup_opts) {
 	return EXIT_NORMAL;
 }
 
-bool engine_try_set_gfxmode_any(const ScreenSetup &setup) {
+bool engine_try_set_gfxmode_any(const DisplayModeSetup &setup) {
 	engine_shutdown_gfxmode();
 
 	const Size init_desktop = get_desktop_size();
@@ -1260,10 +1258,10 @@ bool engine_try_switch_windowed_gfxmode() {
 	engine_pre_gfxmode_release();
 
 	Size init_desktop = get_desktop_size();
-	bool switch_to_windowed = !old_dm.Windowed;
-	ActiveDisplaySetting setting = graphics_mode_get_last_setting(switch_to_windowed);
+	bool windowed = !old_dm.Windowed;
+	ActiveDisplaySetting setting = graphics_mode_get_last_setting(windowed);
 	DisplayMode last_opposite_mode = setting.Dm;
-	FrameScaleDef use_frame_setup = setting.Frame;
+	FrameScaleDef frame = setting.Frame;
 
 	// If there are saved parameters for given mode (fullscreen/windowed)
 	// then use them, if there are not, get default setup for the new mode.
@@ -1271,21 +1269,20 @@ bool engine_try_switch_windowed_gfxmode() {
 	if (last_opposite_mode.IsValid()) {
 		res = graphics_mode_set_dm(last_opposite_mode);
 	} else {
-		// we need to clone from initial config, because not every parameter is set by graphics_mode_get_defaults()
-		DisplayModeSetup dm_setup = _GP(usetup).Screen.DisplayMode;
-		dm_setup.Windowed = !old_dm.Windowed;
-		graphics_mode_get_defaults(dm_setup.Windowed, dm_setup.ScreenSize, use_frame_setup);
-		res = graphics_mode_set_dm_any(_GP(game).GetGameRes(), dm_setup, old_dm.ColorDepth, use_frame_setup);
+		WindowSetup ws = windowed ? _GP(usetup).Screen.WinSetup : _GP(usetup).Screen.FsSetup;
+		frame = windowed ? _GP(usetup).Screen.WinGameFrame : _GP(usetup).Screen.FsGameFrame;
+		res = graphics_mode_set_dm_any(_GP(game).GetGameRes(), ws, old_dm.ColorDepth, windowed,
+			frame, _GP(usetup).Screen.Params);
 	}
 
 	// Apply corresponding frame render method
 	if (res)
-		res = graphics_mode_set_render_frame(use_frame_setup);
+		res = graphics_mode_set_render_frame(frame);
 
 	if (!res) {
 		// If failed, try switching back to previous gfx mode
 		res = graphics_mode_set_dm(old_dm) &&
-		      graphics_mode_set_render_frame(old_frame);
+			graphics_mode_set_render_frame(old_frame);
 	}
 
 	if (res) {
diff --git a/engines/ags/engine/main/engine.h b/engines/ags/engine/main/engine.h
index 1e24a8700fd..01c2bf65958 100644
--- a/engines/ags/engine/main/engine.h
+++ b/engines/ags/engine/main/engine.h
@@ -32,11 +32,11 @@ void        show_preload();
 void        engine_init_game_settings();
 int         initialize_engine(const AGS::Shared::ConfigTree &startup_opts);
 
-struct ScreenSetup;
+struct DisplayModeSetup;
 // Try to set new graphics mode deduced from given configuration;
 // if requested mode fails, tries to find any compatible mode close to the
 // requested one.
-bool        engine_try_set_gfxmode_any(const ScreenSetup &setup);
+bool        engine_try_set_gfxmode_any(const DisplayModeSetup &setup);
 // Tries to switch between fullscreen and windowed mode; uses previously saved
 // setup if it is available, or default settings for the new mode
 bool        engine_try_switch_windowed_gfxmode();
diff --git a/engines/ags/engine/main/graphics_mode.cpp b/engines/ags/engine/main/graphics_mode.cpp
index e0f314bed08..94394d7b586 100644
--- a/engines/ags/engine/main/graphics_mode.cpp
+++ b/engines/ags/engine/main/graphics_mode.cpp
@@ -49,13 +49,6 @@ namespace AGS3 {
 using namespace AGS::Shared;
 using namespace AGS::Engine;
 
-DisplayModeSetup::DisplayModeSetup()
-	: RefreshRate(0)
-	, VSync(false)
-	, Windowed(false) {
-}
-
-
 Size get_desktop_size() {
 	Size sz;
 	sys_get_desktop_resolution(sz.Width, sz.Height);
@@ -194,18 +187,16 @@ Size get_game_frame_from_screen_size(const Size &game_size, const Size screen_si
 	return Size();
 }
 
-Size precalc_screen_size(const Size &game_size, const DisplayModeSetup &dm_setup, const FrameScaleDef &frame) {
+Size precalc_screen_size(const Size &game_size, const WindowSetup &ws, bool windowed, const FrameScaleDef frame) {
 #if AGS_PLATFORM_SCUMMVM
 	return game_size;
 #else
 	// Set requested screen (window) size, depending on screen definition option
-	const bool windowed = dm_setup.Windowed;
-	ScreenSizeSetup scsz = dm_setup.ScreenSize;
-	if (!scsz.Size.IsNull()) {
+	if (!ws.Size.IsNull()) {
 		// Use explicit resolution from user config
-		return scsz.Size;
-	} else if (scsz.Scale > 0) {
-		return get_game_frame_from_screen_size(game_size, get_max_display_size(windowed), frame, scsz.Scale);
+		return ws.Size;
+	} else if (ws.Scale > 0) {
+		return get_game_frame_from_screen_size(game_size, get_max_display_size(windowed), frame, ws.Scale);
 	}
 	// If nothing is set, then for the fullscreen mode set as big as current device/desktop size;
 	// for the windowed mode assume maximal size inside desktop using given frame scaling
@@ -261,13 +252,13 @@ bool try_init_compatible_mode(const DisplayMode &dm) {
 }
 
 // Try to find and initialize compatible display mode as close to given setup as possible
-bool try_init_mode_using_setup(const GraphicResolution &game_res, const DisplayModeSetup &dm_setup,
-	const int col_depth, const FrameScaleDef &frame,
-	const GfxFilterSetup &filter_setup) {
+bool try_init_mode_using_setup(const GraphicResolution &game_res,
+		const WindowSetup &ws, const int col_depth, bool windowed, const FrameScaleDef frame,
+		const GfxFilterSetup &filter, const DisplaySetupEx &params) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_res, dm_setup, frame);
+	const Size screen_size = precalc_screen_size(game_res, ws, windowed, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, col_depth),
-		dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
+		windowed, params.RefreshRate, params.VSync);
 	if (!try_init_compatible_mode(dm))
 		return false;
 
@@ -276,7 +267,7 @@ bool try_init_mode_using_setup(const GraphicResolution &game_res, const DisplayM
 		return false;
 
 	// Set up graphics filter
-	if (!graphics_mode_set_filter_any(filter_setup))
+	if (!graphics_mode_set_filter_any(filter))
 		return false;
 	return true;
 }
@@ -312,8 +303,7 @@ void log_out_driver_modes(const int color_depth) {
 // if the given setup fails, gets default setup for the opposite type of mode (fullscreen/windowed) and tries that instead.
 bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	const GraphicResolution &game_res,
-	const DisplayModeSetup &dm_setup, const ColorDepthOption &color_depth,
-	const FrameScaleDef &frame, const GfxFilterSetup &filter_setup) {
+	const DisplayModeSetup &setup, const ColorDepthOption &color_depth) {
 	if (!graphics_mode_create_renderer(gfx_driver_id))
 		return false;
 
@@ -322,25 +312,24 @@ bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	// Log out supported driver modes
 	log_out_driver_modes(use_col_depth);
 
-	bool result = try_init_mode_using_setup(game_res, dm_setup, use_col_depth, frame, filter_setup);
+	bool windowed = setup.Windowed;
+	WindowSetup ws = windowed ? setup.WinSetup : setup.FsSetup;
+	FrameScaleDef frame = windowed ? setup.WinGameFrame : setup.FsGameFrame;
+	bool result = try_init_mode_using_setup(game_res, ws, use_col_depth, windowed, frame, setup.Filter, setup.Params);
 	// Try windowed mode if fullscreen failed, and vice versa
 	if (!result && _G(editor_debugging_enabled) == 0) {
-		// we need to clone from initial config, because not every parameter is set by graphics_mode_get_defaults()
-		DisplayModeSetup dm_setup_alt = dm_setup;
-		dm_setup_alt.Windowed = !dm_setup.Windowed;
-		FrameScaleDef frame_alt;
-		graphics_mode_get_defaults(dm_setup_alt.Windowed, dm_setup_alt.ScreenSize, frame_alt);
-		result = try_init_mode_using_setup(game_res, dm_setup_alt, use_col_depth, frame_alt, filter_setup);
+		windowed = !windowed;
+		ws = windowed ? setup.WinSetup : setup.FsSetup;
+		frame = windowed ? setup.WinGameFrame : setup.FsGameFrame;
+		result = try_init_mode_using_setup(game_res, ws, use_col_depth, windowed, frame, setup.Filter, setup.Params);
 	}
 	return result;
 }
 
 bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 	const GraphicResolution &game_res,
-	const DisplayModeSetup &dm_setup,
-	const ColorDepthOption &color_depth,
-	const FrameScaleDef &frame,
-	const GfxFilterSetup &filter_setup) {
+	const DisplayModeSetup &setup,
+	const ColorDepthOption &color_depth) {
 	if (!graphics_mode_create_renderer(gfx_driver_id)) {
 		return false;
 	}
@@ -348,7 +337,8 @@ bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 	const int col_depth = _G(gfxDriver)->GetDisplayDepthForNativeDepth(color_depth.Bits);
 
 	DisplayMode dm(GraphicResolution(game_res.Width, game_res.Height, col_depth),
-		dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
+		setup.Windowed, setup.Params.RefreshRate, setup.Params.VSync);
+	const FrameScaleDef frame = setup.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
 
 	if (!graphics_mode_set_dm(dm)) {
 		return false;
@@ -359,34 +349,33 @@ bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 	if (!graphics_mode_set_render_frame(frame)) {
 		return false;
 	}
-	if (!graphics_mode_set_filter_any(filter_setup)) {
+	if (!graphics_mode_set_filter_any(setup.Filter)) {
 		return false;
 	}
 
 	return true;
 }
 
-void display_gfx_mode_error(const Size &game_size, const ScreenSetup &setup, const int color_depth) {
+void display_gfx_mode_error(const Size &game_size, const WindowSetup &ws, const int color_depth,
+	const GfxFilterSetup &filter_setup) {
 	_G(proper_exit) = 1;
 
 	String main_error;
-	ScreenSizeSetup scsz = setup.DisplayMode.ScreenSize;
 	PGfxFilter filter = _G(gfxDriver) ? _G(gfxDriver)->GetGraphicsFilter() : PGfxFilter();
 	Size wanted_screen;
-	if (!scsz.Size.IsNull())
+	if (!ws.Size.IsNull())
 		main_error.Format("There was a problem initializing graphics mode %d x %d (%d-bit), or finding nearest compatible mode, with game size %d x %d and filter '%s'.",
-		                  scsz.Size.Width, scsz.Size.Height, color_depth, game_size.Width, game_size.Height, filter ? filter->GetInfo().Id.GetCStr() : "Undefined");
+			ws.Size.Width, ws.Size.Height, color_depth, game_size.Width, game_size.Height, filter ? filter->GetInfo().Id.GetCStr() : "Undefined");
 	else
 		main_error.Format("There was a problem finding and/or creating valid graphics mode for game size %d x %d (%d-bit) and requested filter '%s'.",
-		                  game_size.Width, game_size.Height, color_depth, setup.Filter.UserRequest.IsEmpty() ? "Undefined" : setup.Filter.UserRequest.GetCStr());
+			game_size.Width, game_size.Height, color_depth, filter_setup.UserRequest.IsEmpty() ? "Undefined" : filter_setup.UserRequest.GetCStr());
 
 	_G(platform)->DisplayAlert("%s\n"
-	                           "Try to correct the problem, or seek help from the AGS homepage."
-	                           "%s",
-	                           main_error.GetCStr(), _G(platform)->GetGraphicsTroubleshootingText());
+		"%s",
+		main_error.GetCStr(), _G(platform)->GetGraphicsTroubleshootingText());
 }
 
-bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup &setup, const ColorDepthOption &color_depth) {
+bool graphics_mode_init_any(const GraphicResolution &game_res, const DisplayModeSetup &setup, const ColorDepthOption &color_depth) {
 	// Log out display information
 	Size device_size;
 	if (sys_get_desktop_resolution(device_size.Width, device_size.Height) == 0)
@@ -394,13 +383,13 @@ bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup
 	else
 		Debug::Printf(kDbgMsg_Error, "Unable to obtain device resolution");
 
-	ScreenSizeSetup scsz = setup.DisplayMode.ScreenSize;
-	FrameScaleDef gameframe = setup.DisplayMode.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
+	WindowSetup ws = setup.Windowed ? setup.WinSetup : setup.FsSetup;
+	FrameScaleDef gameframe = setup.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
 	const String scale_option = make_scaling_option(gameframe);
 	Debug::Printf(kDbgMsg_Info, "Graphic settings: driver: %s, windowed: %s, screen size: %d x %d, game scale: %s",
 		setup.DriverID.GetCStr(),
-		setup.DisplayMode.Windowed ? "yes" : "no",
-		scsz.Size.Width, scsz.Size.Height,
+		setup.Windowed ? "yes" : "no",
+		ws.Size.Width, ws.Size.Height,
 		scale_option.GetCStr());
 
 	// Prepare the list of available gfx factories, having the one requested by user at first place
@@ -418,22 +407,22 @@ bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup
 
 	// Try to create renderer and init gfx mode, choosing one factory at a time
 	bool result = false;
-	for (StringV::const_iterator it = ids.begin(); it != ids.end(); ++it) {
+	for (StringV::const_iterator it2 = ids.begin(); it2 != ids.end(); ++it2) {
 		result =
 #ifdef USE_SIMPLE_GFX_INIT
-			simple_create_gfx_driver_and_init_mode
+			simple_create_gfx_driver_and_init_mode(*it2, game_res, setup, color_depth);
 #else
-			create_gfx_driver_and_init_mode_any
+			create_gfx_driver_and_init_mode_any(*it2, game_res, setup, color_depth);
 #endif
-			(*it, game_res, setup.DisplayMode, color_depth, gameframe, setup.Filter);
 
 		if (result)
 			break;
 		graphics_mode_shutdown();
 	}
+
 	// If all possibilities failed, display error message and quit
 	if (!result) {
-		display_gfx_mode_error(game_res, setup, color_depth.Bits);
+		display_gfx_mode_error(game_res, ws, color_depth.Bits, setup.Filter);
 		return false;
 	}
 	return true;
@@ -454,12 +443,13 @@ bool graphics_mode_create_renderer(const String &driver_id) {
 	return true;
 }
 
-bool graphics_mode_set_dm_any(const Size &game_size, const DisplayModeSetup &dm_setup,
-                              const ColorDepthOption &color_depth, const FrameScaleDef &frame) {
+bool graphics_mode_set_dm_any(const Size &game_size, const WindowSetup &ws,
+		const ColorDepthOption &color_depth, bool windowed,
+		const FrameScaleDef frame, const DisplaySetupEx &params) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_size, dm_setup, frame);
+	const Size screen_size = precalc_screen_size(game_size, ws, windowed, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, color_depth.Bits),
-	               dm_setup.Windowed, dm_setup.RefreshRate, dm_setup.VSync);
+		windowed, params.RefreshRate, params.VSync);
 	return try_init_compatible_mode(dm);
 }
 
diff --git a/engines/ags/engine/main/graphics_mode.h b/engines/ags/engine/main/graphics_mode.h
index 81e9d6fff66..2d684f7a38c 100644
--- a/engines/ags/engine/main/graphics_mode.h
+++ b/engines/ags/engine/main/graphics_mode.h
@@ -61,36 +61,38 @@ enum FrameScaleDef {
 };
 
 // Configuration that is used to determine the size of the screen
-struct ScreenSizeSetup {
+struct WindowSetup {
 	AGS3::Size           Size;      // explicit screen metrics
 	int                  Scale = 0; // explicit game scale factor
 
-	ScreenSizeSetup() = default;
-	ScreenSizeSetup(const AGS3::Size & sz, int scale = 0) : Size(sz), Scale(scale) {
-	}
+	WindowSetup() = default;
+	WindowSetup(const AGS3::Size & sz) : Size(sz), Scale(0) {}
+	WindowSetup(int scale) : Scale(scale) {}
 };
 
-// Display mode configuration
-struct DisplayModeSetup {
-	ScreenSizeSetup      ScreenSize;
-
-	int                  RefreshRate;   // gfx mode refresh rate
-	bool                 VSync;         // vertical sync
-	bool                 Windowed;      // is mode windowed
-
-	DisplayModeSetup();
+// Additional parameters for the display mode setup
+struct DisplaySetupEx {
+	int                  RefreshRate = 0;  // gfx mode refresh rate
+	bool                 VSync = false;    // vertical sync
 };
 
-// Full graphics configuration
-struct ScreenSetup {
+// Full graphics configuration, contains graphics driver selection,
+// alternate settings for windowed and fullscreen modes and gfx filter setup.
+struct DisplayModeSetup {
 	String               DriverID;      // graphics driver ID
-	DisplayModeSetup     DisplayMode;   // definition of the initial display mode
 
-	// Definitions for the fullscreen and windowed scaling methods.
+	// Definitions for the fullscreen and windowed modes and scaling methods.
 	// When the initial display mode is set, corresponding scaling method from this pair is used.
 	// The second method is meant to be saved and used if display mode is switched at runtime.
-	FrameScaleDef       FsGameFrame;   // how the game frame should be scaled/positioned in fullscreen mode
-	FrameScaleDef       WinGameFrame;  // how the game frame should be scaled/positioned in windowed mode
+	WindowSetup          FsSetup;       // definition of the fullscreen mode
+	WindowSetup          WinSetup;      // definition of the windowed mode
+	FrameScaleDef        FsGameFrame =  // how the game frame should be scaled/positioned in fullscreen mode
+		kFrame_Undefined;
+	FrameScaleDef        WinGameFrame = // how the game frame should be scaled/positioned in windowed mode
+		kFrame_Undefined;
+
+	bool                 Windowed = false; // initial mode
+	DisplaySetupEx       Params;
 
 	GfxFilterSetup       Filter;        // graphics filter definition
 };
@@ -110,19 +112,20 @@ struct ColorDepthOption {
 // which is useful if you need to save active settings and reapply them later.
 struct ActiveDisplaySetting {
 	DisplayMode     Dm;
-	FrameScaleDef  Frame;
+	FrameScaleDef  Frame = kFrame_Undefined;
 };
 
 // Initializes any possible gfx mode, using user config as a recommendation;
 // may try all available renderers and modes before succeeding (or failing)
-bool graphics_mode_init_any(const GraphicResolution &game_res, const ScreenSetup &setup, const ColorDepthOption &color_depth);
+bool graphics_mode_init_any(const GraphicResolution &game_res, const DisplayModeSetup &setup, const ColorDepthOption &color_depth);
 // Return last saved display mode of the given kind
 ActiveDisplaySetting graphics_mode_get_last_setting(bool windowed);
 // Creates graphics driver of given id
 bool graphics_mode_create_renderer(const String &driver_id);
 // Try to find and initialize compatible display mode as close to given setup as possible
-bool graphics_mode_set_dm_any(const Size &game_size, const DisplayModeSetup &dm_setup,
-                              const ColorDepthOption &color_depth, const FrameScaleDef &frame_setup);
+bool graphics_mode_set_dm_any(const Size &game_size, const WindowSetup &ws,
+	const ColorDepthOption &color_depth, bool windowed,
+	const FrameScaleDef frame, const DisplaySetupEx &params);
 // Set the display mode with given parameters
 bool graphics_mode_set_dm(const AGS::Engine::DisplayMode &dm);
 // Set the native image size


Commit: c4e7bd355b6f420a49148955334e35d36cc03ecf
    https://github.com/scummvm/scummvm/commit/c4e7bd355b6f420a49148955334e35d36cc03ecf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:13-07:00

Commit Message:
AGS: Distinct "real fullscreen" and "desktop fullscreen" window mode

>From upstream e7763cea241d46e360ed48dcb07bc8c75e591a8c

Changed paths:
    engines/ags/engine/ac/global_debug.cpp
    engines/ags/engine/gfx/gfx_defines.h
    engines/ags/engine/main/engine.cpp
    engines/ags/engine/main/engine_setup.cpp
    engines/ags/engine/main/graphics_mode.cpp
    engines/ags/engine/main/graphics_mode.h
    engines/ags/engine/platform/base/sys_main.cpp
    engines/ags/engine/platform/base/sys_main.h


diff --git a/engines/ags/engine/ac/global_debug.cpp b/engines/ags/engine/ac/global_debug.cpp
index 67e3e34b18f..b825b911bd6 100644
--- a/engines/ags/engine/ac/global_debug.cpp
+++ b/engines/ags/engine/ac/global_debug.cpp
@@ -62,7 +62,7 @@ String GetRuntimeInfo() {
 	                         "Sprite cache size: %d KB (limit %d KB; %d locked)",
 	                         _G(EngineVersion).LongString.GetCStr(), _GP(game).GetGameRes().Width, _GP(game).GetGameRes().Height, _GP(game).GetColorDepth(),
 	                         mode.Width, mode.Height, mode.ColorDepth, (_G(convert_16bit_bgr)) ? " BGR" : "",
-	                         mode.Windowed ? " W" : "",
+	                         mode.IsWindowed() ? " W" : "",
 	                         _G(gfxDriver)->GetDriverName(), filter->GetInfo().Name.GetCStr(),
 	                         render_frame.GetWidth(), render_frame.GetHeight(),
 	                         _GP(spriteset).GetCacheSize() / 1024, _GP(spriteset).GetMaxCacheSize() / 1024, _GP(spriteset).GetLockedSize() / 1024);
diff --git a/engines/ags/engine/gfx/gfx_defines.h b/engines/ags/engine/gfx/gfx_defines.h
index 2f67cf0eeb1..bfc88ab94c3 100644
--- a/engines/ags/engine/gfx/gfx_defines.h
+++ b/engines/ags/engine/gfx/gfx_defines.h
@@ -58,23 +58,33 @@ struct GraphicResolution : Size {
 	}
 };
 
+enum WindowMode {
+	kWnd_Windowed,      // regular resizable window with a border and a caption
+	kWnd_Fullscreen,    // real (aka exclusive) fullscreen mode
+	kWnd_FullDesktop    // borderless window filling whole desktop
+};
+
 // DisplayMode struct provides extended description of display mode
 struct DisplayMode : public GraphicResolution {
-	int32_t RefreshRate;
-	bool    Vsync;
-	bool    Windowed;
+	int32_t RefreshRate = 0;
+	bool Vsync = false;
+	WindowMode Mode = kWnd_Windowed;
 
-	DisplayMode()
-		: RefreshRate(0)
-		, Vsync(false)
-		, Windowed(false) {
+	// Tells if this is logically a normal windowed mode
+	inline bool IsWindowed() const {
+		return Mode == kWnd_Windowed;
+	}
+	// Tells if this mode defines a real fullscreen, which would require gfx driver to support it
+	inline bool IsRealFullscreen() const {
+		return Mode == kWnd_Fullscreen;
 	}
 
-	DisplayMode(const GraphicResolution &res, bool windowed = false, int32_t refresh = 0, bool vsync = false)
+	DisplayMode() = default;
+	DisplayMode(const GraphicResolution & res, WindowMode mode = kWnd_Windowed, int32_t refresh = 0, bool vsync = false)
 		: GraphicResolution(res)
 		, RefreshRate(refresh)
 		, Vsync(vsync)
-		, Windowed(windowed) {
+		, Mode(mode) {
 	}
 };
 
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index c31748a1ad5..c7ec7de90fb 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -1258,7 +1258,7 @@ bool engine_try_switch_windowed_gfxmode() {
 	engine_pre_gfxmode_release();
 
 	Size init_desktop = get_desktop_size();
-	bool windowed = !old_dm.Windowed;
+	bool windowed = !old_dm.IsWindowed();
 	ActiveDisplaySetting setting = graphics_mode_get_last_setting(windowed);
 	DisplayMode last_opposite_mode = setting.Dm;
 	FrameScaleDef frame = setting.Frame;
@@ -1271,7 +1271,7 @@ bool engine_try_switch_windowed_gfxmode() {
 	} else {
 		WindowSetup ws = windowed ? _GP(usetup).Screen.WinSetup : _GP(usetup).Screen.FsSetup;
 		frame = windowed ? _GP(usetup).Screen.WinGameFrame : _GP(usetup).Screen.FsGameFrame;
-		res = graphics_mode_set_dm_any(_GP(game).GetGameRes(), ws, old_dm.ColorDepth, windowed,
+		res = graphics_mode_set_dm_any(_GP(game).GetGameRes(), ws, old_dm.ColorDepth,
 			frame, _GP(usetup).Screen.Params);
 	}
 
@@ -1288,7 +1288,7 @@ bool engine_try_switch_windowed_gfxmode() {
 	if (res) {
 		// If succeeded (with any case), update engine objects that rely on
 		// active display mode.
-		if (_G(gfxDriver)->GetDisplayMode().Windowed)
+		if (!_G(gfxDriver)->GetDisplayMode().IsRealFullscreen())
 			init_desktop = get_desktop_size();
 		engine_post_gfxmode_setup(init_desktop);
 	}
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index a7a67c8ef45..fa9e32edc15 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -273,7 +273,7 @@ void engine_pre_gfxmode_mouse_cleanup() {
 // Fill in _GP(scsystem) struct with display mode parameters
 void engine_setup_scsystem_screen(const DisplayMode &dm) {
 	_GP(scsystem).coldepth = dm.ColorDepth;
-	_GP(scsystem).windowed = dm.Windowed;
+	_GP(scsystem).windowed = dm.IsWindowed();
 	_GP(scsystem).vsync = dm.Vsync;
 }
 
diff --git a/engines/ags/engine/main/graphics_mode.cpp b/engines/ags/engine/main/graphics_mode.cpp
index 94394d7b586..7c38955601a 100644
--- a/engines/ags/engine/main/graphics_mode.cpp
+++ b/engines/ags/engine/main/graphics_mode.cpp
@@ -187,10 +187,11 @@ Size get_game_frame_from_screen_size(const Size &game_size, const Size screen_si
 	return Size();
 }
 
-Size precalc_screen_size(const Size &game_size, const WindowSetup &ws, bool windowed, const FrameScaleDef frame) {
+static Size precalc_screen_size(const Size &game_size, const WindowSetup &ws, const FrameScaleDef frame) {
 #if AGS_PLATFORM_SCUMMVM
 	return game_size;
 #else
+	const bool windowed = ws.Mode == kWnd_Windowed;
 	// Set requested screen (window) size, depending on screen definition option
 	if (!ws.Size.IsNull()) {
 		// Use explicit resolution from user config
@@ -211,16 +212,16 @@ bool try_init_compatible_mode(const DisplayMode &dm) {
 	const Size &screen_size = Size(dm.Width, dm.Height);
 	// Find nearest compatible mode and init that
 	Debug::Printf("Attempting to find nearest supported resolution for screen size %d x %d (%d-bit) %s",
-		dm.Width, dm.Height, dm.ColorDepth, dm.Windowed ? "windowed" : "fullscreen");
-	const Size device_size = get_max_display_size(dm.Windowed);
-	if (dm.Windowed)
+		dm.Width, dm.Height, dm.ColorDepth, dm.IsWindowed() ? "windowed" : "fullscreen");
+	const Size device_size = get_max_display_size(dm.IsWindowed());
+	if (dm.IsWindowed())
 		Debug::Printf("Maximal allowed window size: %d x %d", device_size.Width, device_size.Height);
 	DisplayMode dm_compat = dm;
 
 	std::unique_ptr<IGfxModeList> modes(_G(gfxDriver)->GetSupportedModeList(dm.ColorDepth));  // TODO: use unique_ptr when available
 
 	// Windowed mode
-	if (dm.Windowed) {
+	if (dm.IsWindowed()) {
 		// If windowed mode, make the resolution stay in the generally supported limits
 		dm_compat.Width = Math::Min(dm_compat.Width, device_size.Width);
 		dm_compat.Height = Math::Min(dm_compat.Height, device_size.Height);
@@ -234,17 +235,17 @@ bool try_init_compatible_mode(const DisplayMode &dm) {
 		if (!mode_found)
 			Debug::Printf("Could not find compatible fullscreen mode. Will try to force-set mode requested by user and fallback to windowed mode if that fails.");
 		dm_compat.Vsync = dm.Vsync;
-		dm_compat.Windowed = false;
+		dm_compat.Mode = dm.Mode;
 	}
 
 	bool result = graphics_mode_set_dm(dm_compat);
-	if (!result && dm.Windowed) {
+	if (!result && dm.IsWindowed()) {
 		// When initializing windowed mode we could start with any random window size;
 		// if that did not work, try to find nearest supported mode, as with fullscreen mode,
 		// except refering to max window size as an upper bound
 		if (find_nearest_supported_mode(*modes.get(), screen_size, dm.ColorDepth, nullptr, &device_size, dm_compat)) {
 			dm_compat.Vsync = dm.Vsync;
-			dm_compat.Windowed = true;
+			dm_compat.Mode = kWnd_Windowed;
 			result = graphics_mode_set_dm(dm_compat);
 		}
 	}
@@ -252,13 +253,13 @@ bool try_init_compatible_mode(const DisplayMode &dm) {
 }
 
 // Try to find and initialize compatible display mode as close to given setup as possible
-bool try_init_mode_using_setup(const GraphicResolution &game_res,
-		const WindowSetup &ws, const int col_depth, bool windowed, const FrameScaleDef frame,
+static bool try_init_mode_using_setup(const GraphicResolution &game_res, const WindowSetup &ws,
+		const int col_depth, const FrameScaleDef frame,
 		const GfxFilterSetup &filter, const DisplaySetupEx &params) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_res, ws, windowed, frame);
+	const Size screen_size = precalc_screen_size(game_res, ws, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, col_depth),
-		windowed, params.RefreshRate, params.VSync);
+		ws.Mode, params.RefreshRate, params.VSync);
 	if (!try_init_compatible_mode(dm))
 		return false;
 
@@ -315,30 +316,30 @@ bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	bool windowed = setup.Windowed;
 	WindowSetup ws = windowed ? setup.WinSetup : setup.FsSetup;
 	FrameScaleDef frame = windowed ? setup.WinGameFrame : setup.FsGameFrame;
-	bool result = try_init_mode_using_setup(game_res, ws, use_col_depth, windowed, frame, setup.Filter, setup.Params);
+	bool result = try_init_mode_using_setup(game_res, ws, use_col_depth, frame, setup.Filter, setup.Params);
 	// Try windowed mode if fullscreen failed, and vice versa
 	if (!result && _G(editor_debugging_enabled) == 0) {
 		windowed = !windowed;
 		ws = windowed ? setup.WinSetup : setup.FsSetup;
 		frame = windowed ? setup.WinGameFrame : setup.FsGameFrame;
-		result = try_init_mode_using_setup(game_res, ws, use_col_depth, windowed, frame, setup.Filter, setup.Params);
+		result = try_init_mode_using_setup(game_res, ws, use_col_depth, frame, setup.Filter, setup.Params);
 	}
 	return result;
 }
 
-bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
-	const GraphicResolution &game_res,
-	const DisplayModeSetup &setup,
-	const ColorDepthOption &color_depth) {
+static bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
+		const GraphicResolution &game_res, const DisplayModeSetup &setup,
+		const ColorDepthOption &color_depth) {
 	if (!graphics_mode_create_renderer(gfx_driver_id)) {
 		return false;
 	}
 
 	const int col_depth = _G(gfxDriver)->GetDisplayDepthForNativeDepth(color_depth.Bits);
+	const WindowSetup ws = setup.Windowed ? setup.WinSetup : setup.FsSetup;
+	const FrameScaleDef frame = setup.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
 
 	DisplayMode dm(GraphicResolution(game_res.Width, game_res.Height, col_depth),
-		setup.Windowed, setup.Params.RefreshRate, setup.Params.VSync);
-	const FrameScaleDef frame = setup.Windowed ? setup.WinGameFrame : setup.FsGameFrame;
+		ws.Mode, setup.Params.RefreshRate, setup.Params.VSync);
 
 	if (!graphics_mode_set_dm(dm)) {
 		return false;
@@ -444,18 +445,18 @@ bool graphics_mode_create_renderer(const String &driver_id) {
 }
 
 bool graphics_mode_set_dm_any(const Size &game_size, const WindowSetup &ws,
-		const ColorDepthOption &color_depth, bool windowed,
-		const FrameScaleDef frame, const DisplaySetupEx &params) {
+		const ColorDepthOption &color_depth, const FrameScaleDef frame,
+		const DisplaySetupEx &params) {
 	// We determine the requested size of the screen using setup options
-	const Size screen_size = precalc_screen_size(game_size, ws, windowed, frame);
+	const Size screen_size = precalc_screen_size(game_size, ws, frame);
 	DisplayMode dm(GraphicResolution(screen_size.Width, screen_size.Height, color_depth.Bits),
-		windowed, params.RefreshRate, params.VSync);
+		ws.Mode, params.RefreshRate, params.VSync);
 	return try_init_compatible_mode(dm);
 }
 
 bool graphics_mode_set_dm(const DisplayMode &dm) {
 	Debug::Printf("Attempt to switch gfx mode to %d x %d (%d-bit) %s",
-	              dm.Width, dm.Height, dm.ColorDepth, dm.Windowed ? "windowed" : "fullscreen");
+		dm.Width, dm.Height, dm.ColorDepth, dm.IsWindowed() ? "windowed" : "fullscreen");
 
 	// Tell Allegro new default bitmap color depth (must be done before set_gfx_mode)
 	// TODO: this is also done inside ALSoftwareGraphicsDriver implementation; can remove one?
@@ -467,12 +468,12 @@ bool graphics_mode_set_dm(const DisplayMode &dm) {
 	}
 
 	DisplayMode rdm = _G(gfxDriver)->GetDisplayMode();
-	if (rdm.Windowed)
+	if (rdm.IsWindowed())
 		_GP(SavedWindowedSetting).Dm = rdm;
 	else
 		_GP(SavedFullscreenSetting).Dm = rdm;
 	Debug::Printf("Succeeded. Using gfx mode %d x %d (%d-bit) %s",
-	              rdm.Width, rdm.Height, rdm.ColorDepth, rdm.Windowed ? "windowed" : "fullscreen");
+		rdm.Width, rdm.Height, rdm.ColorDepth, rdm.IsWindowed() ? "windowed" : "fullscreen");
 	return true;
 }
 
@@ -520,7 +521,7 @@ bool graphics_mode_set_render_frame(const FrameScaleDef &frame) {
 	if (frame < 0 || frame >= kNumFrameScaleDef)
 		return false;
 	_G(CurFrameSetup) = frame;
-	if (_G(gfxDriver)->GetDisplayMode().Windowed)
+	if (_G(gfxDriver)->GetDisplayMode().IsWindowed())
 		_GP(SavedWindowedSetting).Frame = frame;
 	else
 		_GP(SavedWindowedSetting).Frame = frame;
diff --git a/engines/ags/engine/main/graphics_mode.h b/engines/ags/engine/main/graphics_mode.h
index 2d684f7a38c..03a74c5e0f2 100644
--- a/engines/ags/engine/main/graphics_mode.h
+++ b/engines/ags/engine/main/graphics_mode.h
@@ -32,6 +32,7 @@ namespace AGS3 {
 using AGS::Shared::String;
 using AGS::Engine::GraphicResolution;
 using AGS::Engine::DisplayMode;
+using AGS::Engine::WindowMode;
 
 Size get_desktop_size();
 
@@ -60,14 +61,19 @@ enum FrameScaleDef {
 	kNumFrameScaleDef
 };
 
-// Configuration that is used to determine the size of the screen
-struct WindowSetup {
-	AGS3::Size           Size;      // explicit screen metrics
-	int                  Scale = 0; // explicit game scale factor
-
-	WindowSetup() = default;
-	WindowSetup(const AGS3::Size & sz) : Size(sz), Scale(0) {}
-	WindowSetup(int scale) : Scale(scale) {}
+// Configuration that is used to determine the size and style of the window
+struct WindowSetup
+{
+    AGS3::Size           Size;      // explicit screen metrics
+    int                  Scale = 0; // explicit game scale factor
+    WindowMode           Mode = AGS::Engine::kWnd_Windowed; // window mode
+
+    WindowSetup() = default;
+    WindowSetup(const AGS3::Size &sz, WindowMode mode = AGS::Engine::kWnd_Windowed)
+        : Size(sz), Scale(0), Mode(mode) {}
+    WindowSetup(int scale, WindowMode mode = AGS::Engine::kWnd_Windowed)
+        : Scale(scale), Mode(mode) {}
+    WindowSetup(WindowMode mode) : Scale(0), Mode(mode) {}
 };
 
 // Additional parameters for the display mode setup
@@ -124,7 +130,7 @@ ActiveDisplaySetting graphics_mode_get_last_setting(bool windowed);
 bool graphics_mode_create_renderer(const String &driver_id);
 // Try to find and initialize compatible display mode as close to given setup as possible
 bool graphics_mode_set_dm_any(const Size &game_size, const WindowSetup &ws,
-	const ColorDepthOption &color_depth, bool windowed,
+	const ColorDepthOption &color_depth,
 	const FrameScaleDef frame, const DisplaySetupEx &params);
 // Set the display mode with given parameters
 bool graphics_mode_set_dm(const AGS::Engine::DisplayMode &dm);
diff --git a/engines/ags/engine/platform/base/sys_main.cpp b/engines/ags/engine/platform/base/sys_main.cpp
index f6063b0e27c..79dfb565513 100644
--- a/engines/ags/engine/platform/base/sys_main.cpp
+++ b/engines/ags/engine/platform/base/sys_main.cpp
@@ -26,7 +26,7 @@
 
 namespace AGS3 {
 
-namespace ags = AGS::Shared;
+using namespace AGS::Engine;
 
 // ----------------------------------------------------------------------------
 // INIT / SHUTDOWN
@@ -91,25 +91,26 @@ void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms) {
 #ifdef TODO
 static SDL_Window *window = nullptr;
 
-SDL_Window *sys_window_create(const char *window_title, int w, int h, bool windowed, int ex_flags) {
+SDL_Window *sys_window_create(const char *window_title, int w, int h, WindowMode mode, int ex_flags) {
 	if (window) {
 		sys_window_destroy();
 	}
 	// TODO: support display index selection (?)
-	// TODO: support separate fullscreen and desktop (borderless fullscreen window) modes
-	Uint32 flags = SDL_WINDOW_RESIZABLE;
-	if (!windowed) {
-		flags |= SDL_WINDOW_FULLSCREEN_DESKTOP/*SDL_WINDOW_FULLSCREEN*/;
+	Uint32 flags = 0;
+	switch (mode) {
+	case kWnd_Windowed: flags |= SDL_WINDOW_RESIZABLE; break;
+	case kWnd_Fullscreen: flags |= SDL_WINDOW_FULLSCREEN; break;
+	case kWnd_FullDesktop: flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; break;
 	}
 	flags |= ex_flags;
 	window = SDL_CreateWindow(
-	             window_title,
-	             SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
-	             SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
-	             w,
-	             h,
-	             flags
-	         );
+		window_title,
+		SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
+		SDL_WINDOWPOS_CENTERED_DISPLAY(DEFAULT_DISPLAY_INDEX),
+		w,
+		h,
+		flags
+	);
 	return window;
 }
 #else
@@ -124,12 +125,15 @@ SDL_Window *sys_get_window() {
 	return nullptr;
 }
 
-void sys_window_set_style(bool windowed) {
+void sys_window_set_style(WindowMode mode, int /*ex_flags*/) {
 #ifdef TODO
 	if (!window) return;
-	// TODO: support separate fullscreen and desktop (borderless fullscreen window) modes
-	// TODO: support resizable window later, might need callback for engine and/or gfx renderer
-	SDL_SetWindowFullscreen(window, windowed ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
+	Uint32 flags = 0;
+	switch (mode) {
+	case kWnd_Fullscreen: flags = SDL_WINDOW_FULLSCREEN; break;
+	case kWnd_FullDesktop: flags = SDL_WINDOW_FULLSCREEN_DESKTOP; break;
+}
+	SDL_SetWindowFullscreen(window, flags);
 #endif
 }
 
diff --git a/engines/ags/engine/platform/base/sys_main.h b/engines/ags/engine/platform/base/sys_main.h
index c80f02abcc6..c248010818e 100644
--- a/engines/ags/engine/platform/base/sys_main.h
+++ b/engines/ags/engine/platform/base/sys_main.h
@@ -55,11 +55,11 @@ void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms);
 //
 struct SDL_Window;
 // Create a new single game window.
-SDL_Window *sys_window_create(const char *window_title, int w, int h, bool windowed, int ex_flags = 0);
+SDL_Window *sys_window_create(const char *window_title, int w, int h, AGS::Engine::WindowMode mode, int ex_flags = 0);
 // Returns current game window, if one exists, or null.
 SDL_Window *sys_get_window();
 // Sets current window style, does nothing if window was not created.
-void sys_window_set_style(bool windowed);
+void sys_window_set_style(AGS::Engine::WindowMode mode, int ex_flags = 0);
 // Set new window size; optionally center new window on screen
 bool sys_window_set_size(int w, int h, bool center);
 // Shows or hides system cursor when it's in the game window


Commit: dc3ce9f70a6f13d31675a57c8aa09e042402ebb2
    https://github.com/scummvm/scummvm/commit/dc3ce9f70a6f13d31675a57c8aa09e042402ebb2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:13-07:00

Commit Message:
AGS: Renamed few font functions for consistent naming style

>From upstream 9c355da410b734edc79212009a5e1be0b502c3b0

Changed paths:
    engines/ags/engine/ac/dialog.cpp
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/display.h
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/drawing_surface.cpp
    engines/ags/engine/ac/global_gui.cpp
    engines/ags/engine/ac/string.cpp
    engines/ags/engine/game/game_init.cpp
    engines/ags/engine/gui/csci_dialog.cpp
    engines/ags/engine/gui/gui_engine.cpp
    engines/ags/engine/gui/my_push_button.cpp
    engines/ags/engine/gui/my_textbox.cpp
    engines/ags/plugins/ags_plugin.cpp
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/font/fonts.h
    engines/ags/shared/gui/gui_label.cpp
    engines/ags/shared/gui/gui_listbox.cpp
    engines/ags/shared/gui/gui_main.cpp
    engines/ags/shared/gui/gui_main.h
    engines/ags/shared/gui/gui_textbox.cpp


diff --git a/engines/ags/engine/ac/dialog.cpp b/engines/ags/engine/ac/dialog.cpp
index 0e262a32300..0034da65cfb 100644
--- a/engines/ags/engine/ac/dialog.cpp
+++ b/engines/ags/engine/ac/dialog.cpp
@@ -473,7 +473,7 @@ void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground) {
 
 	// numbered options, leave space for the numbers
 	if (_GP(game).options[OPT_DIALOGNUMBERED] == kDlgOptNumbering)
-		bullet_wid += wgettextwidth_compensate("9. ", usingfont);
+		bullet_wid += get_text_width_outlined("9. ", usingfont);
 
 	_G(said_text) = 0;
 
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 0a76d29caac..f221d005448 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -120,7 +120,7 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
 	if (_GP(topBar).wantIt) {
 		// ensure that the window is wide enough to display
 		// any top bar text
-		int topBarWid = wgettextwidth_compensate(_GP(topBar).text, _GP(topBar).font);
+		int topBarWid = get_text_width_outlined(_GP(topBar).text, _GP(topBar).font);
 		topBarWid += data_to_game_coord(_GP(play).top_bar_borderwidth + 2) * 2;
 		if (_G(longestline) < topBarWid)
 			_G(longestline) = topBarWid;
@@ -215,7 +215,7 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
 			alphaChannel = true;
 
 		for (size_t ee = 0; ee < _GP(Lines).Count(); ee++) {
-			//int ttxp=wii/2 - wgettextwidth_compensate(lines[ee], usingfont)/2;
+			//int ttxp=wii/2 - get_text_width_outlined(lines[ee], usingfont)/2;
 			int ttyp = ttxtop + ee * disp.linespacing;
 			// asspch < 0 means that it's inside a text box so don't
 			// centre the text
@@ -468,7 +468,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
 	if (antialias) // This is to make sure TTFs render proper alpha channel in 16-bit games too
 		color |= makeacol32(0, 0, 0, 0xff);
 
-	size_t const t_width = wgettextwidth(texx, font);
+	size_t const t_width = get_text_width(texx, font);
 	size_t const t_height = wgettextheight(texx, font);
 	if (t_width == 0 || t_height == 0)
 		return;
@@ -544,9 +544,9 @@ void wouttext_outline(Shared::Bitmap *ds, int xxp, int yyp, int font, color_t te
 void wouttext_aligned(Bitmap *ds, int usexp, int yy, int oriwid, int usingfont, color_t text_color, const char *text, HorAlignment align) {
 
 	if (align & kMAlignHCenter)
-		usexp = usexp + (oriwid / 2) - (wgettextwidth_compensate(text, usingfont) / 2);
+		usexp = usexp + (oriwid / 2) - (get_text_width_outlined(text, usingfont) / 2);
 	else if (align & kMAlignRight)
-		usexp = usexp + (oriwid - wgettextwidth_compensate(text, usingfont));
+		usexp = usexp + (oriwid - get_text_width_outlined(text, usingfont));
 
 	wouttext_outline(ds, usexp, yy, usingfont, text_color, text);
 }
@@ -564,13 +564,13 @@ int get_font_outline_padding(int font) {
 }
 
 int getfontheight_outlined(int font) {
-	return getfontheight(font) + 2 * get_font_outline_padding(font);
+	return get_font_height(font) + 2 * get_font_outline_padding(font);
 }
 
 int getfontspacing_outlined(int font) {
 	return use_default_linespacing(font) ?
 	       getfontheight_outlined(font) :
-	       getfontlinespacing(font);
+	       get_font_linespacing(font);
 }
 
 int getfontlinegap(int font) {
@@ -581,8 +581,8 @@ int getheightoflines(int font, int numlines) {
 	return getfontspacing_outlined(font) * (numlines - 1) + getfontheight_outlined(font);
 }
 
-int wgettextwidth_compensate(const char *tex, int font) {
-	return wgettextwidth(tex, font) + 2 * get_font_outline_padding(font);
+int get_text_width_outlined(const char *tex, int font) {
+	return get_text_width(tex, font) + 2 * get_font_outline_padding(font);
 }
 
 void do_corner(Bitmap *ds, int sprn, int x, int y, int offx, int offy) {
@@ -782,7 +782,7 @@ void draw_text_window_and_bar(Bitmap **text_window_ds, bool should_free_ds,
 		}
 
 		// draw the text
-		int textx = (ds->GetWidth() / 2) - wgettextwidth_compensate(_GP(topBar).text, _GP(topBar).font) / 2;
+		int textx = (ds->GetWidth() / 2) - get_text_width_outlined(_GP(topBar).text, _GP(topBar).font) / 2;
 		color_t text_color = ds->GetCompatibleColor(_GP(play).top_bar_textcolor);
 		wouttext_outline(ds, textx, _GP(play).top_bar_borderwidth + get_fixed_pixel_size(1), _GP(topBar).font, text_color, _GP(topBar).text);
 
diff --git a/engines/ags/engine/ac/display.h b/engines/ags/engine/ac/display.h
index 73b4ba51581..66dbaec145b 100644
--- a/engines/ags/engine/ac/display.h
+++ b/engines/ags/engine/ac/display.h
@@ -65,7 +65,7 @@ int getfontlinegap(int font);
 // Gets the total maximal height of the given number of lines printed with the given font
 int getheightoflines(int font, int numlines);
 // Get the maximal width of the given font, with corresponding outlining
-int wgettextwidth_compensate(const char *tex, int font);
+int get_text_width_outlined(const char *tex, int font);
 void do_corner(Shared::Bitmap *ds, int sprn, int xx1, int yy1, int typx, int typy);
 // Returns the image of a button control on the GUI under given child index
 int get_but_pic(GUIMain *guo, int indx);
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 2f407abade0..bc53df21573 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -644,7 +644,7 @@ void mark_current_background_dirty() {
 
 void draw_and_invalidate_text(Bitmap *ds, int x1, int y1, int font, color_t text_color, const char *text) {
 	wouttext_outline(ds, x1, y1, font, text_color, text);
-	invalidate_rect(x1, y1, x1 + wgettextwidth_compensate(text, font), y1 + getfontheight_outlined(font) + get_fixed_pixel_size(1), false);
+	invalidate_rect(x1, y1, x1 + get_text_width_outlined(text, font), y1 + getfontheight_outlined(font) + get_fixed_pixel_size(1), false);
 }
 
 // Renders black borders for the legacy boxed game mode,
diff --git a/engines/ags/engine/ac/drawing_surface.cpp b/engines/ags/engine/ac/drawing_surface.cpp
index 5ccd8d16c59..2af4bb49493 100644
--- a/engines/ags/engine/ac/drawing_surface.cpp
+++ b/engines/ags/engine/ac/drawing_surface.cpp
@@ -347,9 +347,9 @@ void DrawingSurface_DrawStringWrapped(ScriptDrawingSurface *sds, int xx, int yy,
 		int drawAtX = xx;
 
 		if (alignment & kMAlignHCenter) {
-			drawAtX = xx + ((wid / 2) - wgettextwidth(_GP(Lines)[i].GetCStr(), font) / 2);
+			drawAtX = xx + ((wid / 2) - get_text_width(_GP(Lines)[i].GetCStr(), font) / 2);
 		} else if (alignment & kMAlignRight) {
-			drawAtX = (xx + wid) - wgettextwidth(_GP(Lines)[i].GetCStr(), font);
+			drawAtX = (xx + wid) - get_text_width(_GP(Lines)[i].GetCStr(), font);
 		}
 
 		wouttext_outline(ds, drawAtX, yy + linespacing * i, font, text_color, _GP(Lines)[i].GetCStr());
diff --git a/engines/ags/engine/ac/global_gui.cpp b/engines/ags/engine/ac/global_gui.cpp
index 020d1081139..53f46fa22ae 100644
--- a/engines/ags/engine/ac/global_gui.cpp
+++ b/engines/ags/engine/ac/global_gui.cpp
@@ -177,7 +177,7 @@ int GetTextWidth(const char *text, int fontnum) {
 	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
 		quit("!GetTextWidth: invalid font number.");
 
-	return game_to_data_coord(wgettextwidth_compensate(text, fontnum));
+	return game_to_data_coord(get_text_width_outlined(text, fontnum));
 }
 
 int GetTextHeight(const char *text, int fontnum, int width) {
diff --git a/engines/ags/engine/ac/string.cpp b/engines/ags/engine/ac/string.cpp
index 323aed5c089..461798c36fa 100644
--- a/engines/ags/engine/ac/string.cpp
+++ b/engines/ags/engine/ac/string.cpp
@@ -284,12 +284,12 @@ size_t break_up_text_into_lines(const char *todis, SplitLines &lines, int wii, i
 			(get_uformat() == U_UTF8) ?
 				lines[rr].ReverseUTF8() :
 				lines[rr].Reverse();
-			line_length = wgettextwidth_compensate(lines[rr].GetCStr(), fonnt);
+			line_length = get_text_width_outlined(lines[rr].GetCStr(), fonnt);
 			if (line_length > _G(longestline))
 				_G(longestline) = line_length;
 		} else
 			for (size_t rr = 0; rr < lines.Count(); rr++) {
-				line_length = wgettextwidth_compensate(lines[rr].GetCStr(), fonnt);
+				line_length = get_text_width_outlined(lines[rr].GetCStr(), fonnt);
 				if (line_length > _G(longestline))
 					_G(longestline) = line_length;
 			}
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index f9db2548181..109d9761085 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -277,7 +277,7 @@ void LoadFonts(GameDataVersion data_ver) {
 		// and there's no custom linespacing, then set linespacing = formal height.
 		if (!is_bitmap_font(i)) {
 			int req_height = _GP(game).fonts[i].SizePt * _GP(game).fonts[i].SizeMultiplier;
-			int height = getfontheight(i);
+			int height = get_font_height(i);
 			if ((height != req_height) && (_GP(game).fonts[i].LineSpacing == 0)) {
 				set_font_linespacing(i, req_height + get_font_outline_padding(i));
 			}
diff --git a/engines/ags/engine/gui/csci_dialog.cpp b/engines/ags/engine/gui/csci_dialog.cpp
index e65d96859c1..083ba25f808 100644
--- a/engines/ags/engine/gui/csci_dialog.cpp
+++ b/engines/ags/engine/gui/csci_dialog.cpp
@@ -193,7 +193,7 @@ int CSCICreateControl(int typeandflags, int xx, int yy, int wii, int hii, const
 	int type = typeandflags & 0x00ff;     // 256 control types
 	if (type == CNT_PUSHBUTTON) {
 		if (wii == -1)
-			wii = wgettextwidth(title, _G(cbuttfont)) + 20;
+			wii = get_text_width(title, _G(cbuttfont)) + 20;
 
 		_G(vobjs)[usec] = new MyPushButton(xx, yy, wii, hii, title);
 
diff --git a/engines/ags/engine/gui/gui_engine.cpp b/engines/ags/engine/gui/gui_engine.cpp
index a6e7e7eb030..10193dff03a 100644
--- a/engines/ags/engine/gui/gui_engine.cpp
+++ b/engines/ags/engine/gui/gui_engine.cpp
@@ -124,8 +124,8 @@ void GUITextBox::DrawTextBoxContents(Bitmap *ds, color_t text_color) {
 	wouttext_outline(ds, X + 1 + get_fixed_pixel_size(1), Y + 1 + get_fixed_pixel_size(1), Font, text_color, Text.GetCStr());
 	if (IsGUIEnabled(this)) {
 		// draw a cursor
-		int draw_at_x = wgettextwidth(Text.GetCStr(), Font) + X + 3;
-		int draw_at_y = Y + 1 + getfontheight(Font);
+		int draw_at_x = get_text_width(Text.GetCStr(), Font) + X + 3;
+		int draw_at_y = Y + 1 + get_font_height(Font);
 		ds->DrawRect(Rect(draw_at_x, draw_at_y, draw_at_x + get_fixed_pixel_size(5), draw_at_y + (get_fixed_pixel_size(1) - 1)), text_color);
 	}
 }
diff --git a/engines/ags/engine/gui/my_push_button.cpp b/engines/ags/engine/gui/my_push_button.cpp
index e10fdb56473..5779b3c9f93 100644
--- a/engines/ags/engine/gui/my_push_button.cpp
+++ b/engines/ags/engine/gui/my_push_button.cpp
@@ -61,7 +61,7 @@ void MyPushButton::draw(Bitmap *ds) {
 
 	ds->DrawLine(Line(x, y, x + wid - 1, y), draw_color);
 	ds->DrawLine(Line(x, y, x, y + hit - 1), draw_color);
-	wouttextxy(ds, x + (wid / 2 - wgettextwidth(text, _G(cbuttfont)) / 2), y + 2, _G(cbuttfont), text_color, text);
+	wouttextxy(ds, x + (wid / 2 - get_text_width(text, _G(cbuttfont)) / 2), y + 2, _G(cbuttfont), text_color, text);
 	if (typeandflags & CNF_DEFAULT)
 		draw_color = ds->GetCompatibleColor(0);
 	else
diff --git a/engines/ags/engine/gui/my_textbox.cpp b/engines/ags/engine/gui/my_textbox.cpp
index 052baf87b2e..87a7bfaf9cc 100644
--- a/engines/ags/engine/gui/my_textbox.cpp
+++ b/engines/ags/engine/gui/my_textbox.cpp
@@ -51,7 +51,7 @@ void MyTextBox::draw(Bitmap *ds) {
 	wouttextxy(ds, x + 2, y + 1, _G(cbuttfont), text_color, text);
 
 	char tbu[2] = "_";
-	wouttextxy(ds, x + 2 + wgettextwidth(text, _G(cbuttfont)), y + 1, _G(cbuttfont), text_color, tbu);
+	wouttextxy(ds, x + 2 + get_text_width(text, _G(cbuttfont)), y + 1, _G(cbuttfont), text_color, tbu);
 }
 
 int MyTextBox::pressedon(int mousex, int mousey) {
@@ -72,7 +72,7 @@ int MyTextBox::processmessage(int mcode, int wParam, NumberPtr lParam) {
 			drawandmouse();
 		} else if (strlen(text) >= TEXTBOX_MAXLEN - 1)
 			;
-		else if (wgettextwidth(text, _G(cbuttfont)) >= wid - 5)
+		else if (get_text_width(text, _G(cbuttfont)) >= wid - 5)
 			;
 		else if (wParam > 127)
 			;  // font only has 128 chars
diff --git a/engines/ags/plugins/ags_plugin.cpp b/engines/ags/plugins/ags_plugin.cpp
index 0d3f4c69f58..85e69eba5a7 100644
--- a/engines/ags/plugins/ags_plugin.cpp
+++ b/engines/ags/plugins/ags_plugin.cpp
@@ -482,9 +482,9 @@ void IAGSEngine::GetTextExtent(int32 font, const char *text, int32 *width, int32
 	}
 
 	if (width != nullptr)
-		width[0] = wgettextwidth_compensate(text, font);
+		width[0] = get_text_width_outlined(text, font);
 	if (height != nullptr)
-		height[0] = wgettextheight(text, font);
+		height[0] = wgettextheight((char *)text, font);
 }
 void IAGSEngine::PrintDebugConsole(const char *text) {
 	debug_script_log("[PLUGIN] %s", text);
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 49bb4438bba..0acace1de26 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -129,7 +129,7 @@ int get_font_scaling_mul(size_t fontNumber) {
 	return _GP(fonts)[fontNumber].Info.SizeMultiplier;
 }
 
-int wgettextwidth(const char *texx, size_t fontNumber) {
+int get_text_width(const char *texx, size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
 		return 0;
 	return _GP(fonts)[fontNumber].Renderer->GetTextWidth(texx, fontNumber);
@@ -172,19 +172,19 @@ void set_font_outline(size_t font_number, int outline_type,
 	_GP(fonts)[font_number].Info.AutoOutlineThickness = thickness;
 }
 
-int getfontheight(size_t fontNumber) {
+int get_font_height(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
 		return 0;
 	return _GP(fonts)[fontNumber].Metrics.RealHeight;
 }
 
-int getfontlinespacing(size_t fontNumber) {
+int get_font_linespacing(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size())
 		return 0;
 	int spacing = _GP(fonts)[fontNumber].Info.LineSpacing;
 	// If the spacing parameter is not provided, then return default
 	// spacing, that is font's height.
-	return spacing > 0 ? spacing : getfontheight(fontNumber);
+	return spacing > 0 ? spacing : get_font_height(fontNumber);
 }
 
 void set_font_linespacing(size_t fontNumber, int spacing) {
@@ -199,7 +199,7 @@ bool use_default_linespacing(size_t fontNumber) {
 }
 
 // Project-dependent implementation
-extern int wgettextwidth_compensate(const char *tex, int font);
+extern int get_text_width_outlined(const char *tex, int font);
 
 namespace AGS {
 namespace Common {
@@ -278,7 +278,7 @@ size_t split_lines(const char *todis, SplitLines &lines, int wii, int fonnt, siz
 			const int next_chwas = ugetc(next_ptr);
 			*next_ptr = 0;
 
-			if (wgettextwidth_compensate(theline, fonnt) > wii) {
+			if (get_text_width_outlined(theline, fonnt) > wii) {
 				// line is too wide, order the split
 				if (last_whitespace)
 					// revert to the last whitespace
diff --git a/engines/ags/shared/font/fonts.h b/engines/ags/shared/font/fonts.h
index b09c5d1fb84..6779aa0adf4 100644
--- a/engines/ags/shared/font/fonts.h
+++ b/engines/ags/shared/font/fonts.h
@@ -83,13 +83,13 @@ void ensure_text_valid_for_font(char *text, size_t fontnum);
 // Get font's scaling multiplier
 int get_font_scaling_mul(size_t fontNumber);
 // Calculate actual width of a line of text
-int wgettextwidth(const char *texx, size_t fontNumber);
+int get_text_width(const char *texx, size_t fontNumber);
 // Calculates actual height of a line of text
 int wgettextheight(const char *text, size_t fontNumber);
 // Get font's height (maximal height of any line of text printed with this font)
-int getfontheight(size_t fontNumber);
+int get_font_height(size_t fontNumber);
 // Get font's line spacing
-int getfontlinespacing(size_t fontNumber);
+int get_font_linespacing(size_t fontNumber);
 // Set font's line spacing
 void set_font_linespacing(size_t fontNumber, int spacing);
 // Get is font is meant to use default line spacing
diff --git a/engines/ags/shared/gui/gui_label.cpp b/engines/ags/shared/gui/gui_label.cpp
index ef54e2300fa..bf7fa675062 100644
--- a/engines/ags/shared/gui/gui_label.cpp
+++ b/engines/ags/shared/gui/gui_label.cpp
@@ -56,7 +56,7 @@ void GUILabel::Draw(Shared::Bitmap *ds) {
 		return;
 
 	color_t text_color = ds->GetCompatibleColor(TextColor);
-	const int linespacing = getfontlinespacing(Font) + 1;
+	const int linespacing = get_font_linespacing(Font) + 1;
 	// < 2.72 labels did not limit vertical size of text
 	const bool limit_by_label_frame = _G(loaded_game_file_version) >= kGameVersion_272;
 	int at_y = Y;
diff --git a/engines/ags/shared/gui/gui_listbox.cpp b/engines/ags/shared/gui/gui_listbox.cpp
index 0e9d7bd7635..1f1cffb5bf3 100644
--- a/engines/ags/shared/gui/gui_listbox.cpp
+++ b/engines/ags/shared/gui/gui_listbox.cpp
@@ -267,7 +267,7 @@ void GUIListBox::OnResized() {
 }
 
 void GUIListBox::UpdateMetrics() {
-	RowHeight = getfontheight(Font) + get_fixed_pixel_size(2);
+	RowHeight = get_font_height(Font) + get_fixed_pixel_size(2);
 	VisibleItemCount = Height / RowHeight;
 	if (ItemCount <= VisibleItemCount)
 		TopItem = 0; // reset scroll if all items are visible
diff --git a/engines/ags/shared/gui/gui_main.cpp b/engines/ags/shared/gui/gui_main.cpp
index ca9790647cc..100db82b689 100644
--- a/engines/ags/shared/gui/gui_main.cpp
+++ b/engines/ags/shared/gui/gui_main.cpp
@@ -648,12 +648,12 @@ void DrawTextAligned(Bitmap *ds, const char *text, int font, color_t text_color,
 	int text_height = wgettextheight(text, font);
 	if (align & kMAlignVCenter)
 		text_height++; // CHECKME
-	Rect item = AlignInRect(frame, RectWH(0, 0, wgettextwidth(text, font), text_height), align);
+	Rect item = AlignInRect(frame, RectWH(0, 0, get_text_width(text, font), text_height), align);
 	wouttext_outline(ds, item.Left, item.Top, font, text_color, text);
 }
 
 void DrawTextAlignedHor(Bitmap *ds, const char *text, int font, color_t text_color, int x1, int x2, int y, FrameAlignment align) {
-	int x = AlignInHRange(x1, x2, 0, wgettextwidth(text, font), align);
+	int x = AlignInHRange(x1, x2, 0, get_text_width(text, font), align);
 	wouttext_outline(ds, x, y, font, text_color, text);
 }
 
diff --git a/engines/ags/shared/gui/gui_main.h b/engines/ags/shared/gui/gui_main.h
index c451bc0e2f3..2ebdc60f0a8 100644
--- a/engines/ags/shared/gui/gui_main.h
+++ b/engines/ags/shared/gui/gui_main.h
@@ -242,7 +242,7 @@ extern int get_adjusted_spriteheight(int spr);
 extern bool is_sprite_alpha(int spr);
 
 // Those function have distinct implementations in Engine and Editor
-extern int wgettextwidth_compensate(Shared::Bitmap *ds, const char *tex, int font);
+extern int get_text_width_outlined(Shared::Bitmap *ds, const char *tex, int font);
 
 #define SET_EIP(x) set_our_eip(x);
 extern void set_eip_guiobj(int eip);
diff --git a/engines/ags/shared/gui/gui_textbox.cpp b/engines/ags/shared/gui/gui_textbox.cpp
index 3e1c0dd41df..3e390683ebe 100644
--- a/engines/ags/shared/gui/gui_textbox.cpp
+++ b/engines/ags/shared/gui/gui_textbox.cpp
@@ -92,7 +92,7 @@ void GUITextBox::OnKeyPress(const KeyInput &ki) {
 
 	Text.AppendChar(keycode);
 	// if the new string is too long, remove the new character
-	if (wgettextwidth(Text.GetCStr(), Font) > (Width - (6 + get_fixed_pixel_size(5))))
+	if (get_text_width(Text.GetCStr(), Font) > (Width - (6 + get_fixed_pixel_size(5))))
 		Backspace(Text);
 }
 


Commit: df29806aec718c81dfbae08e664e6a47ad76d545
    https://github.com/scummvm/scummvm/commit/df29806aec718c81dfbae08e664e6a47ad76d545
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:13-07:00

Commit Message:
AGS: Replaced the remaining wgettextheight() with get_font_height()

>From upstream d9c4a0306a6718cb03ccd6e84c1e63d093d9a64a

Changed paths:
    engines/ags/engine/ac/display.cpp
    engines/ags/plugins/ags_plugin.cpp
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/font/fonts.h
    engines/ags/shared/gui/gui_main.cpp


diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index f221d005448..a8b7be94c67 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -469,7 +469,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
 		color |= makeacol32(0, 0, 0, 0xff);
 
 	size_t const t_width = get_text_width(texx, font);
-	size_t const t_height = wgettextheight(texx, font);
+	size_t const t_height = get_font_height(font);
 	if (t_width == 0 || t_height == 0)
 		return;
 
diff --git a/engines/ags/plugins/ags_plugin.cpp b/engines/ags/plugins/ags_plugin.cpp
index 85e69eba5a7..3bea1f9dc56 100644
--- a/engines/ags/plugins/ags_plugin.cpp
+++ b/engines/ags/plugins/ags_plugin.cpp
@@ -484,7 +484,7 @@ void IAGSEngine::GetTextExtent(int32 font, const char *text, int32 *width, int32
 	if (width != nullptr)
 		width[0] = get_text_width_outlined(text, font);
 	if (height != nullptr)
-		height[0] = wgettextheight((char *)text, font);
+		height[0] = get_font_height(font);
 }
 void IAGSEngine::PrintDebugConsole(const char *text) {
 	debug_script_log("[PLUGIN] %s", text);
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 0acace1de26..7cb76b106be 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -135,12 +135,6 @@ int get_text_width(const char *texx, size_t fontNumber) {
 	return _GP(fonts)[fontNumber].Renderer->GetTextWidth(texx, fontNumber);
 }
 
-int wgettextheight(const char *text, size_t fontNumber) {
-	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
-		return 0;
-	return _GP(fonts)[fontNumber].Renderer->GetTextHeight(text, fontNumber);
-}
-
 int get_font_outline(size_t font_number) {
 	if (font_number >= _GP(fonts).size())
 		return FONT_OUTLINE_NONE;
diff --git a/engines/ags/shared/font/fonts.h b/engines/ags/shared/font/fonts.h
index 6779aa0adf4..5562c13da50 100644
--- a/engines/ags/shared/font/fonts.h
+++ b/engines/ags/shared/font/fonts.h
@@ -84,8 +84,6 @@ void ensure_text_valid_for_font(char *text, size_t fontnum);
 int get_font_scaling_mul(size_t fontNumber);
 // Calculate actual width of a line of text
 int get_text_width(const char *texx, size_t fontNumber);
-// Calculates actual height of a line of text
-int wgettextheight(const char *text, size_t fontNumber);
 // Get font's height (maximal height of any line of text printed with this font)
 int get_font_height(size_t fontNumber);
 // Get font's line spacing
diff --git a/engines/ags/shared/gui/gui_main.cpp b/engines/ags/shared/gui/gui_main.cpp
index 100db82b689..3d4af681c64 100644
--- a/engines/ags/shared/gui/gui_main.cpp
+++ b/engines/ags/shared/gui/gui_main.cpp
@@ -645,7 +645,7 @@ void DrawDisabledEffect(Bitmap *ds, const Rect &rc) {
 }
 
 void DrawTextAligned(Bitmap *ds, const char *text, int font, color_t text_color, const Rect &frame, FrameAlignment align) {
-	int text_height = wgettextheight(text, font);
+	int text_height = get_font_height(font);
 	if (align & kMAlignVCenter)
 		text_height++; // CHECKME
 	Rect item = AlignInRect(frame, RectWH(0, 0, get_text_width(text, font), text_height), align);


Commit: e9c153ad4a267beae93163b459910f72dd6efa4c
    https://github.com/scummvm/scummvm/commit/e9c153ad4a267beae93163b459910f72dd6efa4c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:14-07:00

Commit Message:
AGS: Removed unused function getfontlinegap()

>From upstream fa357693ba7e465a3b17b5e3bb785d7d2f9a7325

Changed paths:
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/display.h


diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index a8b7be94c67..36c019b0704 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -573,10 +573,6 @@ int getfontspacing_outlined(int font) {
 	       get_font_linespacing(font);
 }
 
-int getfontlinegap(int font) {
-	return getfontspacing_outlined(font) - getfontheight_outlined(font);
-}
-
 int getheightoflines(int font, int numlines) {
 	return getfontspacing_outlined(font) * (numlines - 1) + getfontheight_outlined(font);
 }
diff --git a/engines/ags/engine/ac/display.h b/engines/ags/engine/ac/display.h
index 66dbaec145b..504f4c2ea96 100644
--- a/engines/ags/engine/ac/display.h
+++ b/engines/ags/engine/ac/display.h
@@ -60,8 +60,6 @@ int getfontheight_outlined(int font);
 int get_font_outline_padding(int font);
 // Get line spacing for the given font, with possible outlining in mind
 int getfontspacing_outlined(int font);
-// Get the distance between bottom one one line and top of the next line (may be negative!)
-int getfontlinegap(int font);
 // Gets the total maximal height of the given number of lines printed with the given font
 int getheightoflines(int font, int numlines);
 // Get the maximal width of the given font, with corresponding outlining


Commit: 977925d105554176a7ac2f20a8115b51b5151b93
    https://github.com/scummvm/scummvm/commit/977925d105554176a7ac2f20a8115b51b5151b93
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:14-07:00

Commit Message:
AGS: Some fixes of namespace Common to be Shared

Changed paths:
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/game/tra_file.h
    engines/ags/shared/util/data_ext.cpp
    engines/ags/shared/util/geometry.cpp


diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 7cb76b106be..c9fd7bfeb69 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -196,10 +196,10 @@ bool use_default_linespacing(size_t fontNumber) {
 extern int get_text_width_outlined(const char *tex, int font);
 
 namespace AGS {
-namespace Common {
+namespace Shared {
 SplitLines Lines;
-}
-}
+} // namespace Shared
+} // namespace AGS
 
 // Replaces AGS-specific linebreak tags with common '\n'
 void unescape_script_string(const char *cstr, std::vector<char> &out) {
diff --git a/engines/ags/shared/game/tra_file.h b/engines/ags/shared/game/tra_file.h
index bf039c7cd36..f37a4974707 100644
--- a/engines/ags/shared/game/tra_file.h
+++ b/engines/ags/shared/game/tra_file.h
@@ -82,7 +82,7 @@ HError ReadTraData(Translation &tra, Stream *in);
 // Writes all translation data to the stream
 void WriteTraData(const Translation &tra, Stream *out);
 
-} // namespace Common
+} // namespace Shared
 } // namespace AGS
 } // namespace AGS3
 
diff --git a/engines/ags/shared/util/data_ext.cpp b/engines/ags/shared/util/data_ext.cpp
index 274df01e187..e70de5a50ef 100644
--- a/engines/ags/shared/util/data_ext.cpp
+++ b/engines/ags/shared/util/data_ext.cpp
@@ -150,6 +150,6 @@ void WriteExtBlock(int block, const String &ext_id, PfnWriteExtBlock writer, int
 	out->Seek(0, Shared::kSeekEnd);
 }
 
-} // namespace Common
+} // namespace Shared
 } // namespace AGS
 } // namespace AGS3
diff --git a/engines/ags/shared/util/geometry.cpp b/engines/ags/shared/util/geometry.cpp
index 64ffe1a48da..5da59792361 100644
--- a/engines/ags/shared/util/geometry.cpp
+++ b/engines/ags/shared/util/geometry.cpp
@@ -21,13 +21,8 @@
 
 #include "ags/shared/util/geometry.h"
 #include "ags/lib/std/algorithm.h"
-//include <cmath>
 
 namespace AGS3 {
-//namespace AGS
-//{
-//namespace Common
-//{
 
 bool AreRectsIntersecting(const Rect &r1, const Rect &r2) { // NOTE: remember that in AGS Y axis is pointed downwards
 	return r1.Left <= r2.Right && r1.Right >= r2.Left &&
@@ -124,6 +119,4 @@ Rect PlaceInRect(const Rect &place, const Rect &item, const RectPlacement &place
 	}
 }
 
-//} // namespace Common
-//} // namespace AGS
 } // namespace AGS3


Commit: d42b63914285ef221a041e47d28521785e68736e
    https://github.com/scummvm/scummvm/commit/d42b63914285ef221a041e47d28521785e68736e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:14-07:00

Commit Message:
AGS: Always precalculate and save font linespacing (as outlined)

>From upstream 8ba3a77e38a6dc8ace6d6393042730d73292a1a7

Changed paths:
    engines/ags/engine/ac/dialog.cpp
    engines/ags/engine/ac/display.cpp
    engines/ags/engine/ac/display.h
    engines/ags/engine/ac/draw.cpp
    engines/ags/engine/ac/drawing_surface.cpp
    engines/ags/engine/ac/global_display.cpp
    engines/ags/engine/ac/global_drawing_surface.cpp
    engines/ags/engine/ac/global_gui.cpp
    engines/ags/engine/game/game_init.cpp
    engines/ags/engine/main/engine_setup.cpp
    engines/ags/plugins/ags_plugin.cpp
    engines/ags/shared/ac/game_struct_defines.h
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/font/fonts.h


diff --git a/engines/ags/engine/ac/dialog.cpp b/engines/ags/engine/ac/dialog.cpp
index 0034da65cfb..65af26940c7 100644
--- a/engines/ags/engine/ac/dialog.cpp
+++ b/engines/ags/engine/ac/dialog.cpp
@@ -450,8 +450,8 @@ void DialogOptions::Prepare(int _dlgnum, bool _runGameLoopsInBackground) {
 
 	dlgyp = get_fixed_pixel_size(160);
 	usingfont = FONT_NORMAL;
-	lineheight = getfontheight_outlined(usingfont);
-	linespacing = getfontspacing_outlined(usingfont);
+	lineheight = get_font_height_outlined(usingfont);
+	linespacing = get_font_linespacing(usingfont);
 	curswas = _G(cur_cursor);
 	bullet_wid = 0;
 	ddb = nullptr;
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 36c019b0704..18de64d8f77 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -100,8 +100,8 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
 
 	ensure_text_valid_for_font(todis, usingfont);
 	break_up_text_into_lines(todis, _GP(Lines), wii - 2 * padding, usingfont);
-	disp.lineheight = getfontheight_outlined(usingfont);
-	disp.linespacing = getfontspacing_outlined(usingfont);
+	disp.lineheight = get_font_height_outlined(usingfont);
+	disp.linespacing = get_font_linespacing(usingfont);
 	disp.fulltxtheight = getheightoflines(usingfont, _GP(Lines).Count());
 
 	// AGS 2.x: If the screen is faded out, fade in again when displaying a message box.
@@ -563,18 +563,8 @@ int get_font_outline_padding(int font) {
 	return 0;
 }
 
-int getfontheight_outlined(int font) {
-	return get_font_height(font) + 2 * get_font_outline_padding(font);
-}
-
-int getfontspacing_outlined(int font) {
-	return use_default_linespacing(font) ?
-	       getfontheight_outlined(font) :
-	       get_font_linespacing(font);
-}
-
 int getheightoflines(int font, int numlines) {
-	return getfontspacing_outlined(font) * (numlines - 1) + getfontheight_outlined(font);
+	return get_font_linespacing(font) * (numlines - 1) + get_font_height_outlined(font);
 }
 
 int get_text_width_outlined(const char *tex, int font) {
diff --git a/engines/ags/engine/ac/display.h b/engines/ags/engine/ac/display.h
index 504f4c2ea96..38608bc358c 100644
--- a/engines/ags/engine/ac/display.h
+++ b/engines/ags/engine/ac/display.h
@@ -52,14 +52,6 @@ int GetTextDisplayTime(const char *text, int canberel = 0);
 // Draw an outline if requested, then draw the text on top
 void wouttext_outline(Shared::Bitmap *ds, int xxp, int yyp, int usingfont, color_t text_color, const char *texx);
 void wouttext_aligned(Shared::Bitmap *ds, int usexp, int yy, int oriwid, int usingfont, color_t text_color, const char *text, HorAlignment align);
-// TODO: GUI classes located in Common library do not make use of outlining,
-// need to find a way to make all code use same functions.
-// Get the maximal height of the given font, with corresponding outlining
-int getfontheight_outlined(int font);
-// Get outline's thickness addition to the font's width or height
-int get_font_outline_padding(int font);
-// Get line spacing for the given font, with possible outlining in mind
-int getfontspacing_outlined(int font);
 // Gets the total maximal height of the given number of lines printed with the given font
 int getheightoflines(int font, int numlines);
 // Get the maximal width of the given font, with corresponding outlining
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index bc53df21573..3c5ae00a406 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -644,7 +644,8 @@ void mark_current_background_dirty() {
 
 void draw_and_invalidate_text(Bitmap *ds, int x1, int y1, int font, color_t text_color, const char *text) {
 	wouttext_outline(ds, x1, y1, font, text_color, text);
-	invalidate_rect(x1, y1, x1 + get_text_width_outlined(text, font), y1 + getfontheight_outlined(font) + get_fixed_pixel_size(1), false);
+	invalidate_rect(x1, y1, x1 + get_text_width_outlined(text, font),
+		y1 + get_font_height_outlined(font) + get_fixed_pixel_size(1), false);
 }
 
 // Renders black borders for the legacy boxed game mode,
@@ -1930,7 +1931,7 @@ void draw_fps(const Rect &viewport) {
 	static Bitmap *fpsDisplay = nullptr;
 	const int font = FONT_NORMAL;
 	if (fpsDisplay == nullptr) {
-		fpsDisplay = CreateCompatBitmap(viewport.GetWidth(), (getfontheight_outlined(font) + get_fixed_pixel_size(5)), _GP(game).GetColorDepth());
+		fpsDisplay = CreateCompatBitmap(viewport.GetWidth(), (get_font_height_outlined(font) + get_fixed_pixel_size(5)));
 	}
 	fpsDisplay->ClearTransparent();
 
@@ -2266,7 +2267,7 @@ void construct_engine_overlay() {
 	if ((_GP(play).debug_mode > 0) && (_G(display_console) != 0)) {
 		const int font = FONT_NORMAL;
 		int ypp = 1;
-		int txtspacing = getfontspacing_outlined(font);
+		int txtspacing = get_font_linespacing(font);
 		int barheight = getheightoflines(font, DEBUG_CONSOLE_NUMLINES - 1) + 4;
 
 		if (_G(debugConsoleBuffer) == nullptr) {
diff --git a/engines/ags/engine/ac/drawing_surface.cpp b/engines/ags/engine/ac/drawing_surface.cpp
index 2af4bb49493..3bd8ed4f52a 100644
--- a/engines/ags/engine/ac/drawing_surface.cpp
+++ b/engines/ags/engine/ac/drawing_surface.cpp
@@ -333,7 +333,7 @@ void DrawingSurface_DrawStringWrapped_Old(ScriptDrawingSurface *sds, int xx, int
 }
 
 void DrawingSurface_DrawStringWrapped(ScriptDrawingSurface *sds, int xx, int yy, int wid, int font, int alignment, const char *msg) {
-	int linespacing = getfontspacing_outlined(font);
+	int linespacing = get_font_linespacing(font);
 	sds->PointToGameResolution(&xx, &yy);
 	sds->SizeToGameResolution(&wid);
 
diff --git a/engines/ags/engine/ac/global_display.cpp b/engines/ags/engine/ac/global_display.cpp
index 3b254ce46f7..1cad75d7aef 100644
--- a/engines/ags/engine/ac/global_display.cpp
+++ b/engines/ags/engine/ac/global_display.cpp
@@ -27,6 +27,7 @@
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/game.h"
 #include "ags/shared/ac/game_setup_struct.h"
+#include "ags/shared/font/fonts.h"
 #include "ags/engine/ac/game_state.h"
 #include "ags/engine/ac/global_character.h"
 #include "ags/engine/ac/global_display.h"
@@ -72,7 +73,7 @@ void DisplayTopBar(int ypos, int ttexcol, int backcol, const char *title, const
 
 	_GP(topBar).wantIt = 1;
 	_GP(topBar).font = FONT_NORMAL;
-	_GP(topBar).height = getfontheight_outlined(_GP(topBar).font);
+	_GP(topBar).height = get_font_height_outlined(_GP(topBar).font);
 	_GP(topBar).height += data_to_game_coord(_GP(play).top_bar_borderwidth) * 2 + get_fixed_pixel_size(1);
 
 	// they want to customize the font
diff --git a/engines/ags/engine/ac/global_drawing_surface.cpp b/engines/ags/engine/ac/global_drawing_surface.cpp
index 3eb543333ac..42ce1547d4a 100644
--- a/engines/ags/engine/ac/global_drawing_surface.cpp
+++ b/engines/ags/engine/ac/global_drawing_surface.cpp
@@ -147,7 +147,7 @@ void RawPrint(int xx, int yy, const char *text) {
 }
 void RawPrintMessageWrapped(int xx, int yy, int wid, int font, int msgm) {
 	char displbuf[3000];
-	int linespacing = getfontspacing_outlined(font);
+	const int linespacing = get_font_linespacing(font);
 	data_to_game_coords(&xx, &yy);
 	wid = data_to_game_coord(wid);
 
diff --git a/engines/ags/engine/ac/global_gui.cpp b/engines/ags/engine/ac/global_gui.cpp
index 53f46fa22ae..69a088d4b9b 100644
--- a/engines/ags/engine/ac/global_gui.cpp
+++ b/engines/ags/engine/ac/global_gui.cpp
@@ -193,13 +193,13 @@ int GetTextHeight(const char *text, int fontnum, int width) {
 int GetFontHeight(int fontnum) {
 	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
 		quit("!GetFontHeight: invalid font number.");
-	return game_to_data_coord(getfontheight_outlined(fontnum));
+	return game_to_data_coord(get_font_height_outlined(fontnum));
 }
 
 int GetFontLineSpacing(int fontnum) {
 	if ((fontnum < 0) || (fontnum >= _GP(game).numfonts))
 		quit("!GetFontLineSpacing: invalid font number.");
-	return game_to_data_coord(getfontspacing_outlined(fontnum));
+	return game_to_data_coord(get_font_linespacing(fontnum));
 }
 
 void SetGUIBackgroundPic(int guin, int slotn) {
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 109d9761085..25213d4513c 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -272,16 +272,6 @@ void LoadFonts(GameDataVersion data_ver) {
 				set_font_outline(i, FONT_OUTLINE_AUTO, FontInfo::kSquared, get_font_scaling_mul(i));
 			}
 		}
-
-		// Backward compatibility: if the real font's height != formal height
-		// and there's no custom linespacing, then set linespacing = formal height.
-		if (!is_bitmap_font(i)) {
-			int req_height = _GP(game).fonts[i].SizePt * _GP(game).fonts[i].SizeMultiplier;
-			int height = get_font_height(i);
-			if ((height != req_height) && (_GP(game).fonts[i].LineSpacing == 0)) {
-				set_font_linespacing(i, req_height + get_font_outline_padding(i));
-			}
-		}
 	}
 
 	// Additional fixups - after all the fonts are registered
@@ -301,6 +291,27 @@ void LoadFonts(GameDataVersion data_ver) {
 				set_font_outline(i, FONT_OUTLINE_AUTO);
 		}
 	}
+
+	// Precalculate and cache any additional parameters; do this after all the fixups
+	for (int i = 0; i < _GP(game).numfonts; ++i) {
+		FontInfo &finfo = _GP(game).fonts[i];
+		const int height = get_font_height(i);
+		if (finfo.LineSpacing == 0) {
+			set_font_linespacing(i, height + 2 * finfo.AutoOutlineThickness);
+
+			// WORKAROUND: For qfg2vga at least, fInfo.SizePt == 0, which causes below
+			// to screw up line spacing. Since by the current upstream HEAD this has all
+			// been replaced anyway, for now I'm adding an explicit 0 check
+			if (finfo.SizePt != 0) {
+				// Backward compatibility: if the real font's height != formal height
+				// and there's no custom linespacing, then set linespacing = formal height.
+				const int compat_height = finfo.SizePt * finfo.SizeMultiplier;
+				if (height != compat_height) {
+					set_font_linespacing(i, compat_height + 2 * finfo.AutoOutlineThickness);
+				}
+			}
+		}
+	}
 }
 
 void LoadLipsyncData() {
diff --git a/engines/ags/engine/main/engine_setup.cpp b/engines/ags/engine/main/engine_setup.cpp
index fa9e32edc15..4e8a1f47045 100644
--- a/engines/ags/engine/main/engine_setup.cpp
+++ b/engines/ags/engine/main/engine_setup.cpp
@@ -123,7 +123,7 @@ void engine_setup_system_gamesize() {
 
 void engine_init_resolution_settings(const Size game_size) {
 	Debug::Printf("Initializing resolution settings");
-	_GP(usetup).textheight = getfontheight_outlined(0) + 1;
+	_GP(usetup).textheight = get_font_height_outlined(0) + 1;
 
 	Debug::Printf(kDbgMsg_Info, "Game native resolution: %d x %d (%d bit)%s", game_size.Width, game_size.Height, _GP(game).color_depth * 8,
 	              _GP(game).IsLegacyLetterbox() ? " letterbox-by-design" : "");
diff --git a/engines/ags/plugins/ags_plugin.cpp b/engines/ags/plugins/ags_plugin.cpp
index 3bea1f9dc56..9b497229820 100644
--- a/engines/ags/plugins/ags_plugin.cpp
+++ b/engines/ags/plugins/ags_plugin.cpp
@@ -279,7 +279,7 @@ bool IAGSEngine::FSeek(soff_t offset, int origin, int32 handle) {
 
 void IAGSEngine::DrawTextWrapped(int32 xx, int32 yy, int32 wid, int32 font, int32 color, const char *text) {
 	// TODO: use generic function from the engine instead of having copy&pasted code here
-	int linespacing = getfontspacing_outlined(font);
+	const int linespacing = get_font_linespacing(font);
 
 	if (break_up_text_into_lines(text, _GP(Lines), wid, font) == 0)
 		return;
diff --git a/engines/ags/shared/ac/game_struct_defines.h b/engines/ags/shared/ac/game_struct_defines.h
index 5061973645a..b0879917887 100644
--- a/engines/ags/shared/ac/game_struct_defines.h
+++ b/engines/ags/shared/ac/game_struct_defines.h
@@ -246,7 +246,7 @@ struct FontInfo {
 	int8          Outline;
 	// Custom vertical render offset, used mainly for fixing broken fonts
 	int           YOffset;
-	// custom line spacing between two lines of text (0 = use font height)
+	// Custom line spacing between two lines of text (0 = use font height)
 	int           LineSpacing;
 	// When automatic outlining, thickness of the outline (0 = no auto outline)
 	int           AutoOutlineThickness;
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index c9fd7bfeb69..3e2d58f3d80 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -32,7 +32,6 @@
 #include "ags/shared/util/string_utils.h"
 #include "ags/globals.h"
 
-
 namespace AGS3 {
 
 using namespace AGS::Shared;
@@ -172,13 +171,17 @@ int get_font_height(size_t fontNumber) {
 	return _GP(fonts)[fontNumber].Metrics.RealHeight;
 }
 
+int get_font_height_outlined(size_t fontNumber) {
+	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
+		return 0;
+	return _GP(fonts)[fontNumber].Metrics.RealHeight
+		+ 2 * _GP(fonts)[fontNumber].Info.AutoOutlineThickness;
+}
+
 int get_font_linespacing(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size())
 		return 0;
-	int spacing = _GP(fonts)[fontNumber].Info.LineSpacing;
-	// If the spacing parameter is not provided, then return default
-	// spacing, that is font's height.
-	return spacing > 0 ? spacing : get_font_height(fontNumber);
+	return _GP(fonts)[fontNumber].Info.LineSpacing;
 }
 
 void set_font_linespacing(size_t fontNumber, int spacing) {
@@ -186,12 +189,6 @@ void set_font_linespacing(size_t fontNumber, int spacing) {
 		_GP(fonts)[fontNumber].Info.LineSpacing = spacing;
 }
 
-bool use_default_linespacing(size_t fontNumber) {
-	if (fontNumber >= _GP(fonts).size())
-		return false;
-	return _GP(fonts)[fontNumber].Info.LineSpacing == 0;
-}
-
 // Project-dependent implementation
 extern int get_text_width_outlined(const char *tex, int font);
 
diff --git a/engines/ags/shared/font/fonts.h b/engines/ags/shared/font/fonts.h
index 5562c13da50..e015a6d0b50 100644
--- a/engines/ags/shared/font/fonts.h
+++ b/engines/ags/shared/font/fonts.h
@@ -86,12 +86,14 @@ int get_font_scaling_mul(size_t fontNumber);
 int get_text_width(const char *texx, size_t fontNumber);
 // Get font's height (maximal height of any line of text printed with this font)
 int get_font_height(size_t fontNumber);
+// TODO: GUI classes located in Common library do not make use of outlining,
+// need to find a way to make all code use same functions.
+// Get the maximal height of the given font, with corresponding outlining
+int get_font_height_outlined(size_t fontNumber);
 // Get font's line spacing
 int get_font_linespacing(size_t fontNumber);
 // Set font's line spacing
 void set_font_linespacing(size_t fontNumber, int spacing);
-// Get is font is meant to use default line spacing
-bool use_default_linespacing(size_t fontNumber);
 // Get font's outline type
 int  get_font_outline(size_t font_number);
 // Get font's automatic outline thickness (if set)


Commit: ba47a913bf4d367a169ed022a1b76a7f07dda730
    https://github.com/scummvm/scummvm/commit/ba47a913bf4d367a169ed022a1b76a7f07dda730
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:14-07:00

Commit Message:
AGS: Add missing code from 43425f738dc6beb7d0758e256a840c5f37a4d38a

Changed paths:
    engines/ags/shared/font/fonts.cpp


diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 3e2d58f3d80..b6f83a468be 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -85,6 +85,9 @@ static void post_init_font(size_t fontNumber) {
 		font.Metrics.Height = height;
 		font.Metrics.RealHeight = height;
 	}
+	if (font.Info.Outline != FONT_OUTLINE_AUTO) {
+		font.Info.AutoOutlineThickness = 0;
+	}
 }
 
 IAGSFontRenderer *font_replace_renderer(size_t fontNumber, IAGSFontRenderer *renderer) {
@@ -157,7 +160,7 @@ int get_font_outline_font(size_t font_number) {
 }
 
 void set_font_outline(size_t font_number, int outline_type,
-	enum FontInfo::AutoOutlineStyle style, int thickness) {
+		enum FontInfo::AutoOutlineStyle style, int thickness) {
 	if (font_number >= _GP(fonts).size())
 		return;
 	_GP(fonts)[font_number].Info.Outline = outline_type;


Commit: 3e6c42ab8d78aef3375974409f0cd866e857208f
    https://github.com/scummvm/scummvm/commit/3e6c42ab8d78aef3375974409f0cd866e857208f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:30:14-07:00

Commit Message:
AGS: get_font_height() returns compatible height

>From upstream 61f726f71b7aee4d7e2ec09d5252061488b9aa81

Changed paths:
    engines/ags/engine/ac/display.cpp
    engines/ags/shared/font/ags_font_renderer.h
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/font/fonts.h


diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 18de64d8f77..738499f3b0f 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -469,7 +469,7 @@ void wouttextxy_AutoOutline(Bitmap *ds, size_t font, int32_t color, const char *
 		color |= makeacol32(0, 0, 0, 0xff);
 
 	size_t const t_width = get_text_width(texx, font);
-	size_t const t_height = get_font_height(font);
+	size_t const t_height = get_font_surface_height(font);
 	if (t_width == 0 || t_height == 0)
 		return;
 
diff --git a/engines/ags/shared/font/ags_font_renderer.h b/engines/ags/shared/font/ags_font_renderer.h
index 0936d2ddfdb..6eb15e61bc3 100644
--- a/engines/ags/shared/font/ags_font_renderer.h
+++ b/engines/ags/shared/font/ags_font_renderer.h
@@ -54,6 +54,7 @@ struct FontRenderParams {
 struct FontMetrics {
 	int Height = 0; // formal font height value
 	int RealHeight = 0; // real graphical height of a font
+	int CompatHeight = 0; // either formal or real height, depending on compat settings
 };
 
 // NOTE: this extending interface is not yet exposed to plugins
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index b6f83a468be..49caf9686fb 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -85,6 +85,7 @@ static void post_init_font(size_t fontNumber) {
 		font.Metrics.Height = height;
 		font.Metrics.RealHeight = height;
 	}
+	font.Metrics.CompatHeight = font.Metrics.Height;
 	if (font.Info.Outline != FONT_OUTLINE_AUTO) {
 		font.Info.AutoOutlineThickness = 0;
 	}
@@ -171,16 +172,22 @@ void set_font_outline(size_t font_number, int outline_type,
 int get_font_height(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
 		return 0;
-	return _GP(fonts)[fontNumber].Metrics.RealHeight;
+	return _GP(fonts)[fontNumber].Metrics.CompatHeight;
 }
 
 int get_font_height_outlined(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
 		return 0;
-	return _GP(fonts)[fontNumber].Metrics.RealHeight
+	return _GP(fonts)[fontNumber].Metrics.CompatHeight
 		+ 2 * _GP(fonts)[fontNumber].Info.AutoOutlineThickness;
 }
 
+int get_font_surface_height(size_t fontNumber) {
+	if (fontNumber >= _GP(fonts).size() || !_GP(fonts)[fontNumber].Renderer)
+		return 0;
+	return _GP(fonts)[fontNumber].Metrics.RealHeight;
+}
+
 int get_font_linespacing(size_t fontNumber) {
 	if (fontNumber >= _GP(fonts).size())
 		return 0;
diff --git a/engines/ags/shared/font/fonts.h b/engines/ags/shared/font/fonts.h
index e015a6d0b50..a6f9089f2b9 100644
--- a/engines/ags/shared/font/fonts.h
+++ b/engines/ags/shared/font/fonts.h
@@ -84,12 +84,17 @@ void ensure_text_valid_for_font(char *text, size_t fontnum);
 int get_font_scaling_mul(size_t fontNumber);
 // Calculate actual width of a line of text
 int get_text_width(const char *texx, size_t fontNumber);
-// Get font's height (maximal height of any line of text printed with this font)
+// Get font's height; this value is used for logical arrangement of UI elements;
+// note that this is a "formal" font height, that may have different value
+// depending on compatibility mode (used when running old games);
 int get_font_height(size_t fontNumber);
 // TODO: GUI classes located in Common library do not make use of outlining,
 // need to find a way to make all code use same functions.
 // Get the maximal height of the given font, with corresponding outlining
 int get_font_height_outlined(size_t fontNumber);
+// Get font's surface height: this always returns the height enough to accomodate
+// font letters on a bitmap or a texture; the distinction is needed for compatibility reasons
+int get_font_surface_height(size_t fontNumber);
 // Get font's line spacing
 int get_font_linespacing(size_t fontNumber);
 // Set font's line spacing


Commit: 658a9ddb050694451cd1cb13910f53b284f90167
    https://github.com/scummvm/scummvm/commit/658a9ddb050694451cd1cb13910f53b284f90167
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-03-22T22:32:14-07:00

Commit Message:
AGS: Wrap unused function in ifdef check

Changed paths:
    engines/ags/engine/main/graphics_mode.cpp


diff --git a/engines/ags/engine/main/graphics_mode.cpp b/engines/ags/engine/main/graphics_mode.cpp
index 7c38955601a..d63a25c22c1 100644
--- a/engines/ags/engine/main/graphics_mode.cpp
+++ b/engines/ags/engine/main/graphics_mode.cpp
@@ -327,6 +327,7 @@ bool create_gfx_driver_and_init_mode_any(const String &gfx_driver_id,
 	return result;
 }
 
+#ifdef USE_SIMPLE_GFX_INIT
 static bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 		const GraphicResolution &game_res, const DisplayModeSetup &setup,
 		const ColorDepthOption &color_depth) {
@@ -356,6 +357,7 @@ static bool simple_create_gfx_driver_and_init_mode(const String &gfx_driver_id,
 
 	return true;
 }
+#endif
 
 void display_gfx_mode_error(const Size &game_size, const WindowSetup &ws, const int color_depth,
 	const GfxFilterSetup &filter_setup) {




More information about the Scummvm-git-logs mailing list