foxygit / doom Log in
commit 9145cb3fd770bd643fa039d29b16eca6a6f36aac
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Tue Feb 5 23:32:30 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Tue Feb 5 23:32:30 2008 +0000

    Set screen_{width,height} when finding the nearest mode. Save the last
    mode explicitly selected and use this as criteria for which mode is
    nearest. Align the display window so that the top always stays still.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 1046
---
 setup/display.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/setup/display.c b/setup/display.c
index f4e38d56..0ead83fe 100644
--- a/setup/display.c
+++ b/setup/display.c
@@ -74,6 +74,13 @@ int screen_height = 200;
 int startup_delay = 0;
 int show_endoom = 1;

+// These are the last screen width/height values that were chosen by the
+// user.  These are used when finding the "nearest" mode, so when
+// changing the fullscreen / aspect ratio options, the setting does not
+// jump around.
+
+static int selected_screen_width = 0, selected_screen_height;
+
 #ifdef _WIN32

 static int win32_video_driver = 0;
@@ -115,6 +122,11 @@ static void ModeSelected(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(mode))

     screen_width = mode->w;
     screen_height = mode->h;
+
+    // This is now the most recently selected screen width
+
+    selected_screen_width = screen_width;
+    selected_screen_height = screen_height;
 }

 static int GoodFullscreenMode(screen_mode_t *mode)
@@ -195,8 +207,10 @@ static int FindBestMode(screen_mode_t *modes)

     for (i=0; modes[i].w != 0; ++i)
     {
-        diff = (screen_width - modes[i].w) * (screen_width - modes[i].w)
-             + (screen_height - modes[i].h) * (screen_height - modes[i].h);
+        diff = (selected_screen_width - modes[i].w)
+                  * (selected_screen_width - modes[i].w)
+             + (selected_screen_height - modes[i].h)
+                  * (selected_screen_height - modes[i].h);

         if (best_mode == -1 || diff < best_mode_diff)
         {
@@ -236,7 +250,7 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget),
     // Build the table

     TXT_ClearTable(modes_table);
-    TXT_SetColumnWidths(modes_table, 14, 14, 14);
+    TXT_SetColumnWidths(modes_table, 15, 15, 15);

     for (i=0; modes[i].w != 0; ++i)
     {
@@ -257,6 +271,9 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget),
     // settings

     vidmode = FindBestMode(modes);
+
+    screen_width = modes[vidmode].w;
+    screen_height = modes[vidmode].h;
 }

 void ConfigDisplay(void)
@@ -266,10 +283,20 @@ void ConfigDisplay(void)
     txt_checkbox_t *fs_checkbox;
     txt_checkbox_t *ar_checkbox;

+    // First time in? Initialise selected_screen_{width,height}
+
+    if (selected_screen_width == 0)
+    {
+        selected_screen_width = screen_width;
+        selected_screen_height = screen_height;
+    }
+
     // Open the window

     window = TXT_NewWindow("Display Configuration");

+    TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP, 40, 5);
+
     TXT_AddWidgets(window,
                    fs_checkbox = TXT_NewCheckBox("Fullscreen", &fullscreen),
                    ar_checkbox = TXT_NewCheckBox("Correct aspect ratio",