changeset 16463:4c4c9177f5eb draft

(svn r21179) -Fix [FS#4201] (r69): if the main toolbar's location is configurable, why isn't the statusbar's location configurable?
author rubidium <rubidium@openttd.org>
date Sat, 13 Nov 2010 23:40:36 +0000
parents 506bc5c31a50
children e548eb796155
files src/lang/english.txt src/settings.cpp src/settings_gui.cpp src/settings_type.h src/statusbar_gui.cpp src/statusbar_gui.h src/table/settings.h src/window.cpp src/window_func.h
diffstat 9 files changed, 67 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1304,6 +1304,10 @@
 STR_CONFIG_SETTING_TOOLBAR_POS_LEFT                             :Left
 STR_CONFIG_SETTING_TOOLBAR_POS_CENTER                           :Centre
 STR_CONFIG_SETTING_TOOLBAR_POS_RIGHT                            :Right
+STR_CONFIG_SETTING_STATUSBAR_POS                                :{LTBLUE}Position of statusbar: {ORANGE}{STRING1}
+STR_CONFIG_SETTING_STATUSBAR_POS_LEFT                           :Left
+STR_CONFIG_SETTING_STATUSBAR_POS_CENTER                         :Centre
+STR_CONFIG_SETTING_STATUSBAR_POS_RIGHT                          :Right
 STR_CONFIG_SETTING_SNAP_RADIUS                                  :{LTBLUE}Window snap radius: {ORANGE}{STRING1} px
 STR_CONFIG_SETTING_SNAP_RADIUS_DISABLED                         :{LTBLUE}Window snap radius: {ORANGE}disabled
 STR_CONFIG_SETTING_SOFT_LIMIT                                   :{LTBLUE}Window soft limit (non-sticky): {ORANGE}{STRING1}
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -681,14 +681,22 @@
 	}
 }
 
-/* Begin - Callback Functions for the various settings
- * virtual PositionMainToolbar function, calls the right one.*/
+/* Begin - Callback Functions for the various settings. */
+
+/** Reposition the main toolbar as the setting changed. */
 static bool v_PositionMainToolbar(int32 p1)
 {
 	if (_game_mode != GM_MENU) PositionMainToolbar(NULL);
 	return true;
 }
 
+/** Reposition the statusbar as the setting changed. */
+static bool v_PositionStatusbar(int32 p1)
+{
+	if (_game_mode != GM_MENU) PositionStatusbar(NULL);
+	return true;
+}
+
 static bool PopulationInLabelActive(int32 p1)
 {
 	UpdateAllTownVirtCoords();
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1300,6 +1300,7 @@
 	SettingEntry("gui.errmsg_duration"),
 	SettingEntry("gui.hover_delay"),
 	SettingEntry("gui.toolbar_pos"),
+	SettingEntry("gui.statusbar_pos"),
 	SettingEntry("gui.pause_on_newgame"),
 	SettingEntry("gui.advanced_vehicle_list"),
 	SettingEntry("gui.timetable_in_ticks"),
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -65,6 +65,7 @@
 	uint8  loading_indicators;               ///< show loading indicators
 	uint8  default_rail_type;                ///< the default rail type for the rail GUI
 	uint8  toolbar_pos;                      ///< position of toolbars, 0=left, 1=center, 2=right
+	uint8  statusbar_pos;                    ///< position of statusbar, 0=left, 1=center, 2=right
 	uint8  window_snap_radius;               ///< windows snap at each other if closer than this
 	uint8  window_soft_limit;                ///< soft limit of maximum number of non-stickied non-vital windows (0 = no limit)
 	bool   always_build_infrastructure;      ///< always allow building of infrastructure, even when you do not have the vehicles for it
--- a/src/statusbar_gui.cpp
+++ b/src/statusbar_gui.cpp
@@ -95,11 +95,12 @@
 		this->reminder_timeout = REMINDER_STOP;
 
 		this->InitNested(desc);
+		PositionStatusbar(this);
 	}
 
 	virtual Point OnInitialPosition(const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
 	{
-		Point pt = { (_screen.width - max(sm_width, desc->default_width)) / 2, _screen.height - sm_height };
+		Point pt = { 0, _screen.height - sm_height };
 		return pt;
 	}
 
@@ -238,7 +239,7 @@
 	EndContainer(),
 };
 
-static const WindowDesc _main_status_desc(
+static WindowDesc _main_status_desc(
 	WDP_MANUAL, 640, 12,
 	WC_STATUS_BAR, WC_NONE,
 	WDF_UNCLICK_BUTTONS | WDF_NO_FOCUS,
@@ -254,6 +255,8 @@
 	return w != NULL && w->ticker_scroll < StatusBarWindow::TICKER_STOP;
 }
 
+int16 *_preferred_statusbar_size = &_main_status_desc.default_width; ///< Pointer to the default size for the status toolbar.
+
 void ShowStatusBar()
 {
 	new StatusBarWindow(&_main_status_desc);
--- a/src/statusbar_gui.h
+++ b/src/statusbar_gui.h
@@ -24,4 +24,6 @@
 bool IsNewsTickerShown();
 void ShowStatusBar();
 
+extern int16 *_preferred_statusbar_size;
+
 #endif /* STATUSBAR_GUI_H */
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -11,6 +11,7 @@
 
 /* Begin - Callback Functions for the various settings */
 static bool v_PositionMainToolbar(int32 p1);
+static bool v_PositionStatusbar(int32 p1);
 static bool PopulationInLabelActive(int32 p1);
 static bool RedrawScreen(int32 p1);
 static bool RedrawSmallmap(int32 p1);
@@ -568,6 +569,7 @@
 	  SDTC_VAR(gui.errmsg_duration,           SLE_UINT8, S,  0,     5,        0,       20, 0, STR_CONFIG_SETTING_ERRMSG_DURATION,             NULL),
 	  SDTC_VAR(gui.hover_delay,               SLE_UINT8, S, D0,     2,        1,        5, 0, STR_CONFIG_SETTING_HOVER_DELAY,                 NULL),
 	  SDTC_VAR(gui.toolbar_pos,               SLE_UINT8, S, MS,     1,        0,        2, 0, STR_CONFIG_SETTING_TOOLBAR_POS,                 v_PositionMainToolbar),
+	  SDTC_VAR(gui.statusbar_pos,             SLE_UINT8, S, MS,     1,        0,        2, 0, STR_CONFIG_SETTING_STATUSBAR_POS,               v_PositionStatusbar),
 	  SDTC_VAR(gui.window_snap_radius,        SLE_UINT8, S, D0,    10,        1,       32, 0, STR_CONFIG_SETTING_SNAP_RADIUS,                 NULL),
 	  SDTC_VAR(gui.window_soft_limit,         SLE_UINT8, S, D0,    20,        5,      255, 1, STR_CONFIG_SETTING_SOFT_LIMIT,                  NULL),
 	 SDTC_BOOL(gui.population_in_label,                  S,  0,  true,                        STR_CONFIG_SETTING_POPULATION_IN_LABEL,         PopulationInLabelActive),
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -33,6 +33,7 @@
 #include "newgrf_debug.h"
 #include "hotkeys.h"
 #include "toolbar_gui.h"
+#include "statusbar_gui.h"
 
 #include "table/sprites.h"
 
@@ -2642,25 +2643,47 @@
 }
 
 /**
- * (Re)position main toolbar window at the screen
- * @param w Window structure of the main toolbar window, may also be \c NULL
- * @return X coordinate of left edge of the repositioned toolbar window
+ * (Re)position a window at the screen.
+ * @param w       Window structure of the window, may also be \c NULL.
+ * @param clss    The class of the window to position.
+ * @param setting The actual setting used for the window's position.
+ * @return X coordinate of left edge of the repositioned window.
+ */
+static int PositionWindow(Window *w, WindowClass clss, int setting)
+{
+	if (w == NULL || w->window_class != clss) {
+		w = FindWindowById(clss, 0);
+	}
+
+	switch (setting) {
+		case 1:  w->left = (_screen.width - w->width) / 2; break;
+		case 2:  w->left = _screen.width - w->width; break;
+		default: w->left = 0; break;
+	}
+	SetDirtyBlocks(0, w->top, _screen.width, w->top + w->height); // invalidate the whole row
+	return w->left;
+}
+
+/**
+ * (Re)position main toolbar window at the screen.
+ * @param w Window structure of the main toolbar window, may also be \c NULL.
+ * @return X coordinate of left edge of the repositioned toolbar window.
  */
 int PositionMainToolbar(Window *w)
 {
 	DEBUG(misc, 5, "Repositioning Main Toolbar...");
-
-	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
-		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
-	}
-
-	switch (_settings_client.gui.toolbar_pos) {
-		case 1:  w->left = (_screen.width - w->width) / 2; break;
-		case 2:  w->left = _screen.width - w->width; break;
-		default: w->left = 0;
-	}
-	SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part
-	return w->left;
+	return PositionWindow(w, WC_MAIN_TOOLBAR, _settings_client.gui.toolbar_pos);
+}
+
+/**
+ * (Re)position statusbar window at the screen.
+ * @param w Window structure of the statusbar window, may also be \c NULL.
+ * @return X coordinate of left edge of the repositioned statusbar.
+ */
+int PositionStatusbar(Window *w)
+{
+	DEBUG(misc, 5, "Repositioning statusbar...");
+	return PositionWindow(w, WC_STATUS_BAR, _settings_client.gui.statusbar_pos);
 }
 
 
@@ -2718,9 +2741,10 @@
 				break;
 
 			case WC_STATUS_BAR:
-				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
+				ResizeWindow(w, min(neww, *_preferred_statusbar_size) - w->width, 0);
+
 				top = newh - w->height;
-				left = (neww - w->width) >> 1;
+				left = PositionStatusbar(w);
 				break;
 
 			case WC_SEND_NETWORK_MSG:
--- a/src/window_func.h
+++ b/src/window_func.h
@@ -21,6 +21,7 @@
 
 void ResizeWindow(Window *w, int x, int y);
 int PositionMainToolbar(Window *w);
+int PositionStatusbar(Window *w);
 
 int GetMainViewTop();
 int GetMainViewBottom();