foxygit / doom Log in
commit 83fb03a0e09920ec324734e9ae3a6cd15fb041e7
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Mon Jan 31 01:25:47 2011 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Mon Jan 31 01:25:47 2011 +0000

    When large numbers of screen resolutions are detected, increase the
    number of columns in the mode list to fit them all on-screen. Remove
    superfluous left-side spacing from the checkbox and radio button widgets
    so that the modes can be packed closer together.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 2242
---
 setup/display.c              | 42 +++++++++++++++++++++++++++++++++++++-----
 textscreen/txt_checkbox.c    |  8 ++++----
 textscreen/txt_radiobutton.c |  8 ++++----
 3 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/setup/display.c b/setup/display.c
index ca22824c..f4a82520 100644
--- a/setup/display.c
+++ b/setup/display.c
@@ -89,6 +89,7 @@ static screen_mode_t screen_modes_scaled[] =
 // List of fullscreen modes generated at runtime

 static screen_mode_t *screen_modes_fullscreen = NULL;
+static int num_screen_modes_fullscreen;

 static int vidmode = 0;

@@ -403,6 +404,8 @@ static void BuildFullscreenModesList(void)
         memcpy(m1, m2, sizeof(screen_mode_t));
         memcpy(m2, &m, sizeof(screen_mode_t));
     }
+
+    num_screen_modes_fullscreen = num_modes;
 }

 static int FindBestMode(screen_mode_t *modes)
@@ -469,7 +472,7 @@ static void GenerateModesTable(TXT_UNCAST_ARG(widget),
     // Build the table

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

     for (i=0; modes[i].w != 0; ++i)
     {
@@ -573,6 +576,8 @@ void ConfigDisplay(void)
     txt_checkbox_t *fs_checkbox;
     txt_checkbox_t *ar_checkbox;
     txt_dropdown_list_t *bpp_selector;
+    int num_columns;
+    int window_y;

     // What color depths are supported?  Generate supported_bpps array
     // and set selected_bpp to match the current value of screen_bpp.
@@ -592,16 +597,43 @@ void ConfigDisplay(void)

     window = TXT_NewWindow("Display Configuration");

-    TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP,
-                                  TXT_SCREEN_W / 2, 5);
-
     TXT_AddWidgets(window,
                    fs_checkbox = TXT_NewCheckBox("Fullscreen", &fullscreen),
                    ar_checkbox = TXT_NewCheckBox("Correct aspect ratio",
                                                  &aspect_ratio_correct),
                    NULL);

-    modes_table = TXT_NewTable(3);
+    // Some machines can have lots of video modes.  This tries to
+    // keep a limit of six lines by increasing the number of
+    // columns.  In extreme cases, the window is moved up slightly.
+
+    BuildFullscreenModesList();
+
+    window_y = 5;
+
+    if (num_screen_modes_fullscreen <= 18)
+    {
+        num_columns = 3;
+    }
+    else if (num_screen_modes_fullscreen <= 24)
+    {
+        num_columns = 4;
+    }
+    else
+    {
+        num_columns = 5;
+        window_y -= 3;
+    }
+
+    modes_table = TXT_NewTable(num_columns);
+
+    // The window is set at a fixed vertical position.  This keeps
+    // the top of the window stationary when switching between
+    // fullscreen and windowed mode (which causes the window's
+    // height to change).
+
+    TXT_SetWindowPosition(window, TXT_HORIZ_CENTER, TXT_VERT_TOP,
+                                  TXT_SCREEN_W / 2, window_y);

     // On Windows, there is an extra control to change between
     // the Windows GDI and DirectX video drivers.
diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c
index 75afa986..35c5739d 100644
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -34,9 +34,9 @@ static void TXT_CheckBoxSizeCalc(TXT_UNCAST_ARG(checkbox))
 {
     TXT_CAST_ARG(txt_checkbox_t, checkbox);

-    // Minimum width is the string length + two spaces for padding
+    // Minimum width is the string length + right-side space for padding

-    checkbox->widget.w = strlen(checkbox->label) + 6;
+    checkbox->widget.w = strlen(checkbox->label) + 5;
     checkbox->widget.h = 1;
 }

@@ -50,7 +50,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox), int selected)

     TXT_BGColor(TXT_COLOR_BLUE, 0);
     TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
-    TXT_DrawString(" (");
+    TXT_DrawString("(");

     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);

@@ -76,7 +76,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox), int selected)

     TXT_DrawString(checkbox->label);

-    for (i=strlen(checkbox->label); i < w-6; ++i)
+    for (i=strlen(checkbox->label); i < w-5; ++i)
     {
         TXT_DrawString(" ");
     }
diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c
index efebbf9e..00c2c4fc 100644
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -34,9 +34,9 @@ static void TXT_RadioButtonSizeCalc(TXT_UNCAST_ARG(radiobutton))
 {
     TXT_CAST_ARG(txt_radiobutton_t, radiobutton);

-    // Minimum width is the string length + two spaces for padding
+    // Minimum width is the string length + right-side spaces for padding

-    radiobutton->widget.w = strlen(radiobutton->label) + 6;
+    radiobutton->widget.w = strlen(radiobutton->label) + 5;
     radiobutton->widget.h = 1;
 }

@@ -50,7 +50,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton), int selected)

     TXT_BGColor(TXT_COLOR_BLUE, 0);
     TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
-    TXT_DrawString(" (");
+    TXT_DrawString("(");

     TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);

@@ -76,7 +76,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton), int selected)

     TXT_DrawString(radiobutton->label);

-    for (i=strlen(radiobutton->label); i < w-6; ++i)
+    for (i=strlen(radiobutton->label); i < w-5; ++i)
     {
         TXT_DrawString(" ");
     }