diff options
author | Simon Howard | 2008-02-09 22:04:13 +0000 |
---|---|---|
committer | Simon Howard | 2008-02-09 22:04:13 +0000 |
commit | aadc860d70492ca5d966864a0b6fb3f49dbc4001 (patch) | |
tree | d851bb5ac0cbd9dac584a8118f8ef53bf68cbb84 | |
parent | 2a464e0d569e651e4bd660c995702b263c8741c4 (diff) | |
download | chocolate-doom-aadc860d70492ca5d966864a0b6fb3f49dbc4001.tar.gz chocolate-doom-aadc860d70492ca5d966864a0b6fb3f49dbc4001.tar.bz2 chocolate-doom-aadc860d70492ca5d966864a0b6fb3f49dbc4001.zip |
Set the SDL_VIDEODRIVER in setup, so that we get the correct modes list
(different video drivers can give different results). Restart textscreen
when the video driver is changed.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1067
-rw-r--r-- | setup/display.c | 146 | ||||
-rw-r--r-- | setup/display.h | 1 | ||||
-rw-r--r-- | setup/mainmenu.c | 2 |
3 files changed, 116 insertions, 33 deletions
diff --git a/setup/display.c b/setup/display.c index 1f48a9a6..78abafdf 100644 --- a/setup/display.c +++ b/setup/display.c @@ -81,40 +81,48 @@ int show_endoom = 1; static int selected_screen_width = 0, selected_screen_height; -#ifdef _WIN32 +static int system_video_env_set; -static int win32_video_driver = 0; +// Set the SDL_VIDEODRIVER environment variable -static char *win32_video_drivers[] = +void SetDisplayDriver(void) { - "DirectX", - "Windows GDI", -}; + static int first_time = 1; -static void SetWin32VideoDriver(void) -{ - if (!strcmp(video_driver, "windib")) + if (first_time) { - win32_video_driver = 1; + system_video_env_set = getenv("SDL_VIDEODRIVER") != NULL; + + first_time = 0; } - else + + // Don't override the command line environment, if it has been set. + + if (system_video_env_set) { - win32_video_driver = 0; + return; } -} -static void UpdateVideoDriver(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) -{ - char *drivers[] = + // Use the value from the configuration file, if it has been set. + + if (strcmp(video_driver, "") != 0) { - "", - "windib", - }; + char *env_string; - video_driver = drivers[win32_video_driver]; -} + env_string = malloc(strlen(video_driver) + 30); + sprintf(env_string, "SDL_VIDEODRIVER=%s", video_driver); + putenv(env_string); + free(env_string); + } + else + { +#ifdef _WIN32 + // On Windows, use DirectX over windib by default. + putenv("SDL_VIDEODRIVER=directx"); #endif + } +} static void ModeSelected(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(mode)) { @@ -167,9 +175,11 @@ static void BuildFullscreenModesList(void) int num_modes; int i; + // Free the existing modes list, if one exists + if (screen_modes_fullscreen != NULL) { - return; + free(screen_modes_fullscreen); } // Get a list of fullscreen modes and find out how many @@ -250,7 +260,11 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget), if (fullscreen) { - BuildFullscreenModesList(); + if (screen_modes_fullscreen == NULL) + { + BuildFullscreenModesList(); + } + modes = screen_modes_fullscreen; } else if (aspect_ratio_correct) @@ -291,6 +305,66 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget), screen_height = modes[vidmode].h; } +#ifdef _WIN32 + +static int win32_video_driver = 0; + +static char *win32_video_drivers[] = +{ + "DirectX", + "Windows GDI", +}; + +// Restart the textscreen library. Used when the video_driver variable +// is changed. + +static void RestartTextscreen(void) +{ + TXT_Shutdown(); + + SetDisplayDriver(); + + TXT_Init(); +} + +static void SetWin32VideoDriver(void) +{ + if (!strcmp(video_driver, "windib")) + { + win32_video_driver = 1; + } + else + { + win32_video_driver = 0; + } +} + +static void UpdateVideoDriver(TXT_UNCAST_ARG(widget), + TXT_UNCAST_ARG(modes_table)) +{ + TXT_CAST_ARG(txt_table_t, modes_table); + char *drivers[] = + { + "", + "windib", + }; + + video_driver = drivers[win32_video_driver != 0]; + + // When the video driver is changed, we need to restart the textscreen + // library. + + RestartTextscreen(); + + // Rebuild the video modes list + + BuildFullscreenModesList(); + GenerateModesTable(NULL, modes_table); +} + +#endif + + void ConfigDisplay(void) { txt_window_t *window; @@ -318,6 +392,11 @@ void ConfigDisplay(void) &aspect_ratio_correct), NULL); + modes_table = TXT_NewTable(3); + + // On Windows, there is an extra control to change between + // the Windows GDI and DirectX video drivers. + #ifdef _WIN32 { txt_table_t *driver_table; @@ -325,27 +404,28 @@ void ConfigDisplay(void) driver_table = TXT_NewTable(2); - TXT_SetColumnWidths(driver_table, 25, 0); - - driver_list = TXT_NewDropdownList(&win32_video_driver, - win32_video_drivers, - 2); - - TXT_SignalConnect(driver_list, "changed", UpdateVideoDriver, NULL); - SetWin32VideoDriver(); + TXT_SetColumnWidths(driver_table, 20, 0); TXT_AddWidgets(driver_table, TXT_NewLabel("Video driver"), - driver_list, + driver_list = TXT_NewDropdownList(&win32_video_driver, + win32_video_drivers, + 2), NULL); + TXT_SignalConnect(driver_list, "changed", + UpdateVideoDriver, modes_table); + SetWin32VideoDriver(); + TXT_AddWidget(window, driver_table); } #endif + // Screen modes list + TXT_AddWidgets(window, TXT_NewSeparator("Screen mode"), - modes_table = TXT_NewTable(3), + modes_table, TXT_NewSeparator("Misc."), TXT_NewCheckBox("Show ENDOOM screen", &show_endoom), NULL); diff --git a/setup/display.h b/setup/display.h index d8dcce7f..f0c76184 100644 --- a/setup/display.h +++ b/setup/display.h @@ -31,6 +31,7 @@ extern int show_endoom; extern char *video_driver; void ConfigDisplay(void); +void SetDisplayDriver(void); #endif /* #ifndef SETUP_DISPLAY_H */ diff --git a/setup/mainmenu.c b/setup/mainmenu.c index 335bd61b..4ff5b449 100644 --- a/setup/mainmenu.c +++ b/setup/mainmenu.c @@ -172,6 +172,8 @@ static void SetIcon(void) static void RunGUI(void) { + SetDisplayDriver(); + if (!TXT_Init()) { fprintf(stderr, "Failed to initialise GUI\n"); |