shithub: choc

Download patch

ref: af3e4412d301cc27e04c352c0283ce6861f33f0c
parent: 56824b130b786aab49876a71c6c768a17c5a4f1c
author: Simon Howard <[email protected]>
date: Fri Dec 10 15:43:05 EST 2010

Change alignment of actions in a window's action area so that there is
equal space either side of the center widget. This is more aesthetically
pleasing.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2208

--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -140,7 +140,16 @@
 static void LayoutActionArea(txt_window_t *window)
 {
     txt_widget_t *widget;
+    int space_available;
+    int space_left_offset;
 
+    // We need to calculate the available horizontal space for the center
+    // action widget, so that we can center it within it.
+    // To start with, we have the entire action area available.
+
+    space_available = window->window_w;
+    space_left_offset = 0;
+
     // Left action
 
     if (window->actions[TXT_HORIZ_LEFT] != NULL)
@@ -151,29 +160,43 @@
 
         widget->x = window->window_x + 2;
         widget->y = window->window_y + window->window_h - widget->h - 1;
+
+        // Adjust available space:
+
+        space_available -= widget->w;
+        space_left_offset += widget->w;
     }
 
-    // Draw the center action
+    // Draw the right action
 
-    if (window->actions[TXT_HORIZ_CENTER] != NULL)
+    if (window->actions[TXT_HORIZ_RIGHT] != NULL)
     {
-        widget = (txt_widget_t *) window->actions[TXT_HORIZ_CENTER];
+        widget = (txt_widget_t *) window->actions[TXT_HORIZ_RIGHT];
 
         TXT_CalcWidgetSize(widget);
 
-        widget->x = window->window_x + (window->window_w - widget->w - 2) / 2;
+        widget->x = window->window_x + window->window_w - 2 - widget->w;
         widget->y = window->window_y + window->window_h - widget->h - 1;
+
+        // Adjust available space:
+
+        space_available -= widget->w;
     }
 
-    // Draw the right action
+    // Draw the center action
 
-    if (window->actions[TXT_HORIZ_RIGHT] != NULL)
+    if (window->actions[TXT_HORIZ_CENTER] != NULL)
     {
-        widget = (txt_widget_t *) window->actions[TXT_HORIZ_RIGHT];
+        widget = (txt_widget_t *) window->actions[TXT_HORIZ_CENTER];
 
         TXT_CalcWidgetSize(widget);
 
-        widget->x = window->window_x + window->window_w - 2 - widget->w;
+        // The left and right widgets have left a space sandwiched between
+        // them.  Center this widget within that space.
+
+        widget->x = window->window_x
+                  + space_left_offset
+                  + (space_available - widget->w) / 2;
         widget->y = window->window_y + window->window_h - widget->h - 1;
     }
 }