changeset 13438:588cc335bf57 draft

(svn r17947) -Codechange: make the statusbar, chat input and news window know of eachothers size so they don't get overlapped and don't get invisible (bottoms) of windows when a larger font is used
author rubidium <rubidium@openttd.org>
date Mon, 02 Nov 2009 10:15:48 +0000
parents 1ab8e5dfef6c
children 0e90ffa69389
files src/network/network_chat_gui.cpp src/news_gui.cpp src/statusbar_gui.cpp src/window.cpp
diffstat 4 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -118,7 +118,7 @@
 
 	_chatmsg_list       = ReallocT(_chatmsg_list, _settings_client.gui.network_chat_box_height);
 	_chatmsg_box.x      = 10;
-	_chatmsg_box.y      = 30;
+	_chatmsg_box.y      = 3 * FONT_HEIGHT_NORMAL;
 	_chatmsg_box.width  = _settings_client.gui.network_chat_box_width;
 	_chatmsg_box.height = _settings_client.gui.network_chat_box_height * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING) + 2;
 	_chatmessage_backup = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * BlitterFactoryBase::GetCurrentBlitter()->GetBytesPerPixel());
@@ -449,6 +449,12 @@
 		this->DrawEditBox(NWCW_TEXTBOX);
 	}
 
+	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 - FindWindowById(WC_STATUS_BAR, 0)->height };
+		return pt;
+	}
+
 	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
 	{
 		if (widget != NWCW_DESTINATION) return;
@@ -537,7 +543,7 @@
 };
 
 static const WindowDesc _chat_window_desc(
-	WDP_CENTER, -26, 320, 14, 640, 14, // x, y, width, height
+	WDP_CENTER, 0, 320, 14, 640, 14, // x, y, width, height
 	WC_SEND_NETWORK_MSG, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET,
 	NULL, _nested_chat_window_widgets, lengthof(_nested_chat_window_widgets)
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -280,6 +280,7 @@
 /** Window class displaying a news item. */
 struct NewsWindow : Window {
 	uint16 chat_height;   ///< Height of the chat window.
+	uint16 status_height; ///< Height of the status bar window
 	NewsItem *ni;         ///< News item to display.
 	static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
 
@@ -288,6 +289,7 @@
 		NewsWindow::duration = 555;
 		const Window *w = FindWindowById(WC_SEND_NETWORK_MSG, 0);
 		this->chat_height = (w != NULL) ? w->height : 0;
+		this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
 
 		this->flags4 |= WF_DISABLE_VP_SCROLL;
 
@@ -490,7 +492,7 @@
 	virtual void OnTick()
 	{
 		/* Scroll up newsmessages from the bottom in steps of 4 pixels */
-		int y = max(this->top - 4, _screen.height - this->height - 12 - this->chat_height);
+		int y = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
 		if (y == this->top) return;
 
 		if (this->viewport != NULL) this->viewport->top += y - this->top;
--- a/src/statusbar_gui.cpp
+++ b/src/statusbar_gui.cpp
@@ -98,11 +98,22 @@
 		this->InitNested(desc);
 	}
 
+	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 };
+		return pt;
+	}
+
 	virtual void OnPaint()
 	{
 		this->DrawWidgets();
 	}
 
+	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
+	{
+		size->height = FONT_HEIGHT_NORMAL + padding.height;
+	}
+
 	virtual void DrawWidget(const Rect &r, int widget) const
 	{
 		switch (widget) {
@@ -202,7 +213,7 @@
 	EndContainer(),
 };
 
-static WindowDesc _main_status_desc(
+static const WindowDesc _main_status_desc(
 	WDP_CENTER, 0, 320, 12, 640, 12,
 	WC_STATUS_BAR, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_NO_FOCUS,
@@ -220,6 +231,5 @@
 
 void ShowStatusBar()
 {
-	_main_status_desc.top = _screen.height - 12;
 	new StatusBarWindow(&_main_status_desc);
 }
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2720,7 +2720,7 @@
 
 			case WC_SEND_NETWORK_MSG:
 				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
-				top = (newh - 26); // 26 = height of status bar + height of chat bar
+				top = newh - w->height - FindWindowById(WC_STATUS_BAR, 0)->height;
 				left = (neww - w->width) >> 1;
 				break;