(svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
authorrubidium
Fri, 16 May 2008 07:08:04 +0000
changeset 10570 b83e3644d1da
parent 10569 1359ca399ddd
child 10571 55cc869d11e3
(svn r13114) -Codechange: use InvalidateData instead of direct window access to modify the state of the statusbar from outside the statusbar.
projects/openttd_vs80.vcproj
projects/openttd_vs90.vcproj
source.list
src/main_gui.cpp
src/news_gui.cpp
src/saveload.cpp
src/statusbar_gui.cpp
src/statusbar_gui.h
--- a/projects/openttd_vs80.vcproj	Thu May 15 22:47:03 2008 +0000
+++ b/projects/openttd_vs80.vcproj	Fri May 16 07:08:04 2008 +0000
@@ -1440,6 +1440,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\statusbar_gui.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\stdafx.h"
 				>
 			</File>
--- a/projects/openttd_vs90.vcproj	Thu May 15 22:47:03 2008 +0000
+++ b/projects/openttd_vs90.vcproj	Fri May 16 07:08:04 2008 +0000
@@ -1437,6 +1437,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\..\src\statusbar_gui.h"
+				>
+			</File>
+			<File
 				RelativePath=".\..\src\stdafx.h"
 				>
 			</File>
--- a/source.list	Thu May 15 22:47:03 2008 +0000
+++ b/source.list	Fri May 16 07:08:04 2008 +0000
@@ -285,6 +285,7 @@
 station_func.h
 station_gui.h
 station_type.h
+statusbar_gui.h
 stdafx.h
 string_func.h
 string_type.h
--- a/src/main_gui.cpp	Thu May 15 22:47:03 2008 +0000
+++ b/src/main_gui.cpp	Fri May 16 07:08:04 2008 +0000
@@ -29,6 +29,7 @@
 #include "player_gui.h"
 #include "settings_type.h"
 #include "toolbar_gui.h"
+#include "statusbar_gui.h"
 #include "variables.h"
 #include "tilehighlight_func.h"
 
@@ -431,8 +432,6 @@
 	}
 }
 
-extern void ShowStatusBar();
-
 void ShowVitalWindows()
 {
 	AllocateToolbar();
--- a/src/news_gui.cpp	Thu May 15 22:47:03 2008 +0000
+++ b/src/news_gui.cpp	Fri May 16 07:08:04 2008 +0000
@@ -18,6 +18,7 @@
 #include "string_func.h"
 #include "widgets/dropdown_func.h"
 #include "map_func.h"
+#include "statusbar_gui.h"
 
 #include "table/sprites.h"
 #include "table/strings.h"
@@ -472,8 +473,7 @@
 	if (_news_ticker_sound) SndPlayFx(SND_16_MORSE);
 
 	_statusbar_news_item = *ni;
-	Window *w = FindWindowById(WC_STATUS_BAR, 0);
-	if (w != NULL) WP(w, def_d).data_1 = 360;
+	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_TICKER);
 }
 
 
@@ -490,8 +490,7 @@
 
 	/* Ticker message
 	 * Check if the status bar message is still being displayed? */
-	const Window *w = FindWindowById(WC_STATUS_BAR, 0);
-	if (w != NULL && WP(w, const def_d).data_1 > -1280) return false;
+	if (IsNewsTickerShown()) return false;
 
 	/* Newspaper message, decrement duration counter */
 	if (ni->duration != 0) ni->duration--;
@@ -517,15 +516,9 @@
 
 		switch (_news_type_data[type].display) {
 			default: NOT_REACHED();
-			case ND_OFF: { // Off - show nothing only a small reminder in the status bar
-				Window *w = FindWindowById(WC_STATUS_BAR, 0);
-
-				if (w != NULL) {
-					WP(w, def_d).data_2 = 91;
-					w->SetDirty();
-				}
+			case ND_OFF: // Off - show nothing only a small reminder in the status bar
+				InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SHOW_REMINDER);
 				break;
-			}
 
 			case ND_SUMMARY: // Summary - show ticker, but if forced big, cascade to full
 				if (!(ni->flags & NF_FORCE_BIG)) {
--- a/src/saveload.cpp	Thu May 15 22:47:03 2008 +0000
+++ b/src/saveload.cpp	Fri May 16 07:08:04 2008 +0000
@@ -30,6 +30,7 @@
 #include "core/endian_func.hpp"
 #include "vehicle_base.h"
 #include "autoreplace_base.h"
+#include "statusbar_gui.h"
 #include <list>
 
 #include "table/strings.h"
@@ -1493,7 +1494,7 @@
 	_fast_forward = 0;
 	if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
 
-	InvalidateWindowData(WC_STATUS_BAR, 0, true);
+	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_START);
 	_ts.saveinprogress = true;
 }
 
@@ -1504,7 +1505,7 @@
 	_fast_forward = _ts.ff_state;
 	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
 
-	InvalidateWindowData(WC_STATUS_BAR, 0, false);
+	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_SAVELOAD_FINISH);
 	_ts.saveinprogress = false;
 }
 
--- a/src/statusbar_gui.cpp	Thu May 15 22:47:03 2008 +0000
+++ b/src/statusbar_gui.cpp	Fri May 16 07:08:04 2008 +0000
@@ -18,6 +18,7 @@
 #include "window_gui.h"
 #include "variables.h"
 #include "window_func.h"
+#include "statusbar_gui.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -107,7 +108,13 @@
 		} break;
 
 		case WE_INVALIDATE_DATA:
-			WP(w, def_d).data_3 = e->we.invalidate.data;
+			switch (e->we.invalidate.data) {
+				default: NOT_REACHED();
+				case SBI_SAVELOAD_START:  WP(w, def_d).data_3 = true;  break;
+				case SBI_SAVELOAD_FINISH: WP(w, def_d).data_3 = false; break;
+				case SBI_SHOW_TICKER:     WP(w, def_d).data_1 = 360;   break;
+				case SBI_SHOW_REMINDER:   WP(w, def_d).data_2 = 91;    break;
+			}
 			break;
 
 		case WE_CLICK:
@@ -152,6 +159,15 @@
 	StatusBarWndProc
 };
 
+/**
+ * Checks whether the news ticker is currently being used.
+ */
+bool IsNewsTickerShown()
+{
+	const Window *w = FindWindowById(WC_STATUS_BAR, 0);
+	return w != NULL && WP(w, const def_d).data_1 > -1280;
+}
+
 void ShowStatusBar()
 {
 	_main_status_desc.top = _screen.height - 12;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/statusbar_gui.h	Fri May 16 07:08:04 2008 +0000
@@ -0,0 +1,20 @@
+/* $Id$ */
+
+/** @file statusbar_gui.h Functions, definitions and such used only by the GUI. */
+
+#ifndef STATUSBAR_GUI_H
+#define STATUSBAR_GUI_H
+
+enum StatusBarInvalidate
+{
+	SBI_SAVELOAD_START,
+	SBI_SAVELOAD_FINISH,
+	SBI_SHOW_TICKER,
+	SBI_SHOW_REMINDER,
+	SBI_END
+};
+
+bool IsNewsTickerShown();
+void ShowStatusBar();
+
+#endif /* STATUSBAR_GUI_H */