mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-10 09:32:29 +01:00
Merge pull request #719 from IntelOrca/fullscreen-fixes
Fix fullscreen issues
This commit is contained in:
@@ -256,7 +256,7 @@ void config_write_ini_general(FILE *fp)
|
|||||||
|
|
||||||
if (gGeneral_config.fullscreen_width != -1)
|
if (gGeneral_config.fullscreen_width != -1)
|
||||||
fprintf(fp, "fullscreen_width = %d\n", gGeneral_config.fullscreen_width);
|
fprintf(fp, "fullscreen_width = %d\n", gGeneral_config.fullscreen_width);
|
||||||
if (gGeneral_config.window_height != -1)
|
if (gGeneral_config.fullscreen_height != -1)
|
||||||
fprintf(fp, "fullscreen_height = %d\n", gGeneral_config.fullscreen_height);
|
fprintf(fp, "fullscreen_height = %d\n", gGeneral_config.fullscreen_height);
|
||||||
|
|
||||||
if (gGeneral_config.window_width != -1)
|
if (gGeneral_config.window_width != -1)
|
||||||
|
|||||||
@@ -182,35 +182,35 @@ static void osinterface_create_window()
|
|||||||
{
|
{
|
||||||
SDL_SysWMinfo wmInfo;
|
SDL_SysWMinfo wmInfo;
|
||||||
HWND hWnd;
|
HWND hWnd;
|
||||||
int width, height;
|
int width, height, mode;
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
RCT2_ERROR("SDL_Init %s", SDL_GetError());
|
RCT2_ERROR("SDL_Init %s", SDL_GetError());
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stuff
|
osinterface_load_cursors();
|
||||||
{
|
RCT2_CALLPROC_EBPSAFE(0x0068371D);
|
||||||
osinterface_load_cursors();
|
|
||||||
RCT2_CALLPROC_EBPSAFE(0x0068371D);
|
|
||||||
|
|
||||||
width = gGeneral_config.window_width;
|
// Get window size
|
||||||
height = gGeneral_config.window_height;
|
width = gGeneral_config.window_width;
|
||||||
|
height = gGeneral_config.window_height;
|
||||||
if (width == -1) width = 640;
|
if (width == -1) width = 640;
|
||||||
if (height == -1) height = 480;
|
if (height == -1) height = 480;
|
||||||
}
|
|
||||||
|
|
||||||
RCT2_GLOBAL(0x009E2D8C, sint32) = 0;
|
RCT2_GLOBAL(0x009E2D8C, sint32) = 0;
|
||||||
|
|
||||||
gWindow = SDL_CreateWindow("OpenRCT2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height,
|
// Create window in window first rather than fullscreen so we have the display the window is on first
|
||||||
_fullscreen_modes[gGeneral_config.fullscreen_mode] | SDL_WINDOW_RESIZABLE);
|
gWindow = SDL_CreateWindow(
|
||||||
|
"OpenRCT2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE
|
||||||
|
);
|
||||||
if (!gWindow) {
|
if (!gWindow) {
|
||||||
RCT2_ERROR("SDL_CreateWindow failed %s", SDL_GetError());
|
RCT2_ERROR("SDL_CreateWindow failed %s", SDL_GetError());
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_VERSION(&wmInfo.version);
|
SDL_VERSION(&wmInfo.version);
|
||||||
|
|
||||||
// Get the HWND context
|
// Get the HWND context
|
||||||
if (SDL_GetWindowWMInfo(gWindow, &wmInfo) != SDL_TRUE) {
|
if (SDL_GetWindowWMInfo(gWindow, &wmInfo) != SDL_TRUE) {
|
||||||
RCT2_ERROR("SDL_GetWindowWMInfo failed %s", SDL_GetError());
|
RCT2_ERROR("SDL_GetWindowWMInfo failed %s", SDL_GetError());
|
||||||
@@ -226,8 +226,35 @@ static void osinterface_create_window()
|
|||||||
osinterface_resize(width, height);
|
osinterface_resize(width, height);
|
||||||
|
|
||||||
platform_update_fullscreen_resolutions();
|
platform_update_fullscreen_resolutions();
|
||||||
|
osinterface_set_fullscreen_mode(gGeneral_config.fullscreen_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void osinterface_set_fullscreen_mode(int mode)
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
mode = _fullscreen_modes[mode];
|
||||||
|
|
||||||
|
// HACK Changing window size when in fullscreen usually has no effect
|
||||||
|
if (mode == SDL_WINDOW_FULLSCREEN)
|
||||||
|
SDL_SetWindowFullscreen(gWindow, 0);
|
||||||
|
|
||||||
|
// Set window size
|
||||||
|
if (mode == SDL_WINDOW_FULLSCREEN) {
|
||||||
|
platform_update_fullscreen_resolutions();
|
||||||
|
platform_get_closest_resolution(gGeneral_config.fullscreen_width, gGeneral_config.fullscreen_height, &width, &height);
|
||||||
|
SDL_SetWindowSize(gWindow, width, height);
|
||||||
|
} else if (mode == 0) {
|
||||||
|
SDL_SetWindowSize(gWindow, gGeneral_config.window_width, gGeneral_config.window_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_SetWindowFullscreen(gWindow, mode)) {
|
||||||
|
RCT2_ERROR("SDL_SetWindowFullscreen %s", SDL_GetError());
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
// TODO try another display mode rather than just exiting the game
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void osinterface_resize(int width, int height)
|
static void osinterface_resize(int width, int height)
|
||||||
{
|
{
|
||||||
@@ -526,51 +553,6 @@ void osinterface_free()
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void osinterface_set_fullscreen_mode(int mode)
|
|
||||||
{
|
|
||||||
int i, destinationArea, areaDiff, closestAreaDiff, closestWidth, closestHeight;
|
|
||||||
|
|
||||||
if (mode == SDL_WINDOW_FULLSCREEN)
|
|
||||||
SDL_SetWindowFullscreen(gWindow, 0);
|
|
||||||
|
|
||||||
if (mode == SDL_WINDOW_FULLSCREEN) {
|
|
||||||
platform_update_fullscreen_resolutions();
|
|
||||||
|
|
||||||
closestAreaDiff = -1;
|
|
||||||
destinationArea = gGeneral_config.fullscreen_width * gGeneral_config.fullscreen_height;
|
|
||||||
for (i = 0; i < gNumResolutions; i++) {
|
|
||||||
// Check if exact match
|
|
||||||
if (gResolutions[i].width == gGeneral_config.fullscreen_width && gResolutions[i].height == gGeneral_config.fullscreen_height) {
|
|
||||||
closestWidth = gResolutions[i].width;
|
|
||||||
closestHeight = gResolutions[i].height;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if area is closer to best match
|
|
||||||
areaDiff = abs((gResolutions[i].width * gResolutions[i].height) - destinationArea);
|
|
||||||
if (closestAreaDiff == -1 || areaDiff < closestAreaDiff) {
|
|
||||||
closestAreaDiff = areaDiff;
|
|
||||||
closestWidth = gResolutions[i].width;
|
|
||||||
closestHeight = gResolutions[i].height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closestAreaDiff != -1)
|
|
||||||
SDL_SetWindowSize(gWindow, closestWidth, closestHeight);
|
|
||||||
} else if (mode == 0) {
|
|
||||||
SDL_SetWindowSize(gWindow, gGeneral_config.window_width, gGeneral_config.window_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SDL_SetWindowFullscreen(gWindow, _fullscreen_modes[mode])){
|
|
||||||
RCT2_ERROR("SDL_SetWindowFullscreen %s", SDL_GetError());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
gGeneral_config.fullscreen_mode = mode;
|
|
||||||
|
|
||||||
config_save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* rct2: 0x00407978
|
* rct2: 0x00407978
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ extern SDL_Window *gWindow;
|
|||||||
|
|
||||||
// Platform shared definitions
|
// Platform shared definitions
|
||||||
void platform_update_fullscreen_resolutions();
|
void platform_update_fullscreen_resolutions();
|
||||||
|
void platform_get_closest_resolution(int inWidth, int inHeight, int *outWidth, int *outHeight);
|
||||||
|
|
||||||
// Platform specific definitions
|
// Platform specific definitions
|
||||||
char platform_get_path_separator();
|
char platform_get_path_separator();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
int gNumResolutions;
|
int gNumResolutions = 0;
|
||||||
resolution *gResolutions = NULL;
|
resolution *gResolutions = NULL;
|
||||||
|
|
||||||
SDL_Window *gWindow;
|
SDL_Window *gWindow;
|
||||||
@@ -95,4 +95,36 @@ void platform_update_fullscreen_resolutions()
|
|||||||
gGeneral_config.fullscreen_width = gResolutions[gNumResolutions - 1].width;
|
gGeneral_config.fullscreen_width = gResolutions[gNumResolutions - 1].width;
|
||||||
gGeneral_config.fullscreen_height = gResolutions[gNumResolutions - 1].height;
|
gGeneral_config.fullscreen_height = gResolutions[gNumResolutions - 1].height;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_get_closest_resolution(int inWidth, int inHeight, int *outWidth, int *outHeight)
|
||||||
|
{
|
||||||
|
int i, destinationArea, areaDiff, closestAreaDiff, closestWidth, closestHeight;
|
||||||
|
|
||||||
|
closestAreaDiff = -1;
|
||||||
|
destinationArea = inWidth * inHeight;
|
||||||
|
for (i = 0; i < gNumResolutions; i++) {
|
||||||
|
// Check if exact match
|
||||||
|
if (gResolutions[i].width == inWidth && gResolutions[i].height == inHeight) {
|
||||||
|
closestWidth = gResolutions[i].width;
|
||||||
|
closestHeight = gResolutions[i].height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if area is closer to best match
|
||||||
|
areaDiff = abs((gResolutions[i].width * gResolutions[i].height) - destinationArea);
|
||||||
|
if (closestAreaDiff == -1 || areaDiff < closestAreaDiff) {
|
||||||
|
closestAreaDiff = areaDiff;
|
||||||
|
closestWidth = gResolutions[i].width;
|
||||||
|
closestHeight = gResolutions[i].height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closestAreaDiff != -1) {
|
||||||
|
*outWidth = closestWidth;
|
||||||
|
*outHeight = closestHeight;
|
||||||
|
} else {
|
||||||
|
*outWidth = 640;
|
||||||
|
*outHeight = 480;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -574,6 +574,9 @@ static void window_options_dropdown()
|
|||||||
w->disabled_widgets &= ~(1 << WIDX_RESOLUTION);
|
w->disabled_widgets &= ~(1 << WIDX_RESOLUTION);
|
||||||
}
|
}
|
||||||
osinterface_set_fullscreen_mode(dropdownIndex);
|
osinterface_set_fullscreen_mode(dropdownIndex);
|
||||||
|
|
||||||
|
gGeneral_config.fullscreen_mode = (uint8)dropdownIndex;
|
||||||
|
config_save();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WIDX_TEMPERATURE_DROPDOWN:
|
case WIDX_TEMPERATURE_DROPDOWN:
|
||||||
|
|||||||
Reference in New Issue
Block a user