From af3e4412d301cc27e04c352c0283ce6861f33f0c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 10 Dec 2010 20:43:05 +0000 Subject: 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 --- textscreen/txt_window.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'textscreen/txt_window.c') diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c index 33f53d4a..46e71d3a 100644 --- a/textscreen/txt_window.c +++ b/textscreen/txt_window.c @@ -140,6 +140,15 @@ static void CalcWindowPosition(txt_window_t *window) 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 @@ -151,29 +160,43 @@ static void LayoutActionArea(txt_window_t *window) 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; } } -- cgit v1.2.3