(svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods cpp_gui
authorbjarni
Tue, 13 Feb 2007 01:04:32 +0000
branchcpp_gui
changeset 6237 bce32e54c993
parent 6236 ec056d324811
child 6238 1ff56ccccbb5
(svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
src/depot_gui.cpp
src/genworld_gui.cpp
src/main_gui.cpp
src/misc_gui.cpp
src/news_gui.cpp
src/order_gui.cpp
src/player_gui.cpp
src/rail_gui.cpp
src/road_gui.cpp
src/station_gui.cpp
src/viewport.cpp
src/widget.cpp
src/window.cpp
src/window.h
--- a/src/depot_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/depot_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -803,7 +803,7 @@
 					break;
 
 				case DEPOT_WIDGET_CLONE: // Clone button
-					InvalidateWidget(w, DEPOT_WIDGET_CLONE);
+					w->InvalidateWidget(DEPOT_WIDGET_CLONE);
 					ToggleWidgetLoweredState(w, DEPOT_WIDGET_CLONE);
 
 					if (IsWindowWidgetLowered(w, DEPOT_WIDGET_CLONE)) {
@@ -865,7 +865,7 @@
 
 		case WE_ABORT_PLACE_OBJ: {
 			RaiseWindowWidget(w, DEPOT_WIDGET_CLONE);
-			InvalidateWidget(w, DEPOT_WIDGET_CLONE);
+			w->InvalidateWidget(DEPOT_WIDGET_CLONE);
 		} break;
 
 			/* check if a vehicle in a depot was clicked.. */
--- a/src/genworld_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/genworld_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -476,11 +476,11 @@
 
 			switch (WP(w, def_d).data_3) {
 			case GLAND_START_DATE_TEXT:
-				InvalidateWidget(w, GLAND_START_DATE_TEXT);
+				w->InvalidateWidget(GLAND_START_DATE_TEXT);
 				_patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR);
 				break;
 			case GLAND_SNOW_LEVEL_TEXT:
-				InvalidateWidget(w, GLAND_SNOW_LEVEL_TEXT);
+				w->InvalidateWidget(GLAND_SNOW_LEVEL_TEXT);
 				_patches_newgame.snow_line_height = clamp(value, 2, 13);
 				break;
 			}
@@ -672,11 +672,11 @@
 
 			switch (WP(w, def_d).data_3) {
 			case CSCEN_START_DATE_TEXT:
-				InvalidateWidget(w, CSCEN_START_DATE_TEXT);
+				w->InvalidateWidget(CSCEN_START_DATE_TEXT);
 				_patches_newgame.starting_year = clamp(value, MIN_YEAR, MAX_YEAR);
 				break;
 			case CSCEN_FLAT_LAND_HEIGHT_TEXT:
-				InvalidateWidget(w, CSCEN_FLAT_LAND_HEIGHT_TEXT);
+				w->InvalidateWidget(CSCEN_FLAT_LAND_HEIGHT_TEXT);
 				_patches_newgame.se_flat_world_height = clamp(value, 0, 15);
 				break;
 			}
--- a/src/main_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/main_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -695,7 +695,7 @@
 
 	assert(disabled_mask == 0 || item_count <= 8);
 	LowerWindowWidget(w, parent_button);
-	InvalidateWidget(w, parent_button);
+	w->InvalidateWidget(parent_button);
 
 	DeleteWindowById(WC_TOOLBAR_MENU, 0);
 
@@ -730,7 +730,7 @@
 	x += w->left;
 
 	LowerWindowWidget(w, main_button);
-	InvalidateWidget(w, main_button);
+	w->InvalidateWidget(main_button);
 
 	DeleteWindowById(WC_TOOLBAR_MENU, 0);
 	w = Window::Allocate(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
@@ -1341,7 +1341,7 @@
 		for (i = 0; i < w->widget_count; i++) {
 			if (IsWindowWidgetLowered(w, i)) {
 				RaiseWindowWidget(w, i);
-				InvalidateWidget(w, i);
+				w->InvalidateWidget(i);
 			}
 			if (i == 3) i = 11;
 		}
@@ -1690,7 +1690,7 @@
 		break;
 	case WE_TIMEOUT:
 		RaiseWindowWidget(w, 3);
-		InvalidateWidget(w, 3);
+		w->InvalidateWidget(3);
 		break;
 	}
 }
@@ -1871,12 +1871,12 @@
 	case WE_MOUSELOOP:
 		if (IsWindowWidgetLowered(w, 0) != !!_pause) {
 			ToggleWidgetLoweredState(w, 0);
-			InvalidateWidget(w, 0);
+			w->InvalidateWidget(0);
 		}
 
 		if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) {
 			ToggleWidgetLoweredState(w, 1);
-			InvalidateWidget(w, 1);
+			w->InvalidateWidget(1);
 		}
 		break;
 
@@ -1885,7 +1885,7 @@
 		for (i = 2; i < w->widget_count; i++) {
 			if (IsWindowWidgetLowered(w, i)) {
 				RaiseWindowWidget(w, i);
-				InvalidateWidget(w, i);
+				w->InvalidateWidget(i);
 			}
 		}
 		break;
@@ -2201,14 +2201,14 @@
 
 		if (WP(w, def_d).data_1 > -1280) { /* Scrolling text */
 			WP(w, def_d).data_1 -= 2;
-			InvalidateWidget(w, 1);
+			w->InvalidateWidget(1);
 		}
 
 		if (WP(w, def_d).data_2 > 0) { /* Red blot to show there are new unread newsmessages */
 			WP(w, def_d).data_2 -= 2;
 		} else if (WP(w, def_d).data_2 < 0) {
 			WP(w, def_d).data_2 = 0;
-			InvalidateWidget(w, 1);
+			w->InvalidateWidget(1);
 		}
 
 		break;
--- a/src/misc_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/misc_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -971,24 +971,24 @@
 	case WKC_RETURN: case WKC_NUM_ENTER: return 1;
 	case (WKC_CTRL | 'V'):
 		if (InsertTextBufferClipboard(&string->text))
-			InvalidateWidget(w, wid);
+			w->InvalidateWidget(wid);
 		break;
 	case (WKC_CTRL | 'U'):
 		DeleteTextBufferAll(&string->text);
-		InvalidateWidget(w, wid);
+		w->InvalidateWidget(wid);
 		break;
 	case WKC_BACKSPACE: case WKC_DELETE:
 		if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode))
-			InvalidateWidget(w, wid);
+			w->InvalidateWidget(wid);
 		break;
 	case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
 		if (MoveTextBufferPos(&string->text, e->we.keypress.keycode))
-			InvalidateWidget(w, wid);
+			w->InvalidateWidget(wid);
 		break;
 	default:
 		if (IsValidChar(e->we.keypress.key, string->afilter)) {
 			if (InsertTextBufferChar(&string->text, e->we.keypress.key)) {
-				InvalidateWidget(w, wid);
+				w->InvalidateWidget(wid);
 			}
 		} else { // key wasn't caught. Continue only if standard entry specified
 			e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL);
@@ -1012,7 +1012,7 @@
 
 void HandleEditBox(Window *w, querystr_d *string, int wid)
 {
-	if (HandleCaret(&string->text)) InvalidateWidget(w, wid);
+	if (HandleCaret(&string->text)) w->InvalidateWidget(wid);
 }
 
 void DrawEditBox(Window *w, querystr_d *string, int wid)
@@ -1514,7 +1514,7 @@
 					// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox
 					ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
 					UpdateTextBufferSize(&WP(w, querystr_d).text);
-					InvalidateWidget(w, 10);
+					w->InvalidateWidget(10);
 				}
 			} else {
 				// Changed directory, need repaint.
--- a/src/news_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/news_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -785,7 +785,7 @@
 		case 25: /* Change ticker sound on/off */
 			_news_ticker_sound ^= 1;
 			ToggleWidgetLoweredState(w, e->we.click.widget);
-			InvalidateWidget(w, e->we.click.widget);
+			w->InvalidateWidget(e->we.click.widget);
 			break;
 		default: { /* Clicked on the [<] .. [>] widgets */
 			int wid = e->we.click.widget;
--- a/src/order_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/order_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -356,7 +356,7 @@
 
 static void OrderClick_Goto(Window *w, const Vehicle *v)
 {
-	InvalidateWidget(w, ORDER_WIDGET_GOTO);
+	w->InvalidateWidget(ORDER_WIDGET_GOTO);
 	ToggleWidgetLoweredState(w, ORDER_WIDGET_GOTO);
 	if (IsWindowWidgetLowered(w, ORDER_WIDGET_GOTO)) {
 		_place_clicked_vehicle = NULL;
@@ -549,7 +549,7 @@
 
 	case WE_ABORT_PLACE_OBJ: {
 		RaiseWindowWidget(w, ORDER_WIDGET_GOTO);
-		InvalidateWidget( w, ORDER_WIDGET_GOTO);
+		w->InvalidateWidget( ORDER_WIDGET_GOTO);
 	} break;
 
 	// check if a vehicle in a depot was clicked..
@@ -580,7 +580,7 @@
 		for (i = 0; i < w->widget_count; i++) {
 			if (IsWindowWidgetLowered(w, i) && i != ORDER_WIDGET_GOTO) {
 				RaiseWindowWidget(w, i);
-				InvalidateWidget(w, i);
+				w->InvalidateWidget(i);
 			}
 		}
 	} break;
--- a/src/player_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/player_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -786,7 +786,7 @@
 						SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
 						SetTileSelectSize(2, 2);
 						LowerWindowWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
-						InvalidateWidget(w, PCW_WIDGET_BUILD_VIEW_HQ);
+						w->InvalidateWidget(PCW_WIDGET_BUILD_VIEW_HQ);
 					} else {
 						ScrollMainWindowToTile(tile);
 					}
@@ -797,7 +797,7 @@
 					SetObjectToPlaceWnd(SPR_CURSOR_HQ, PAL_NONE, 1, w);
 					SetTileSelectSize(2, 2);
 					LowerWindowWidget(w, PCW_WIDGET_RELOCATE_HQ);
-					InvalidateWidget(w, PCW_WIDGET_RELOCATE_HQ);
+					w->InvalidateWidget(PCW_WIDGET_RELOCATE_HQ);
 					break;
 
 				case PCW_WIDGET_BUY_SHARE:
--- a/src/rail_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/rail_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -526,7 +526,7 @@
 	case WE_ABORT_PLACE_OBJ:
 		w->RaiseButtons();
 		DisableWindowWidget(w, RTW_REMOVE);
-		InvalidateWidget(w, RTW_REMOVE);
+		w->InvalidateWidget(RTW_REMOVE);
 
 		w = Window::FindById(WC_BUILD_STATION, 0);
 		if (w != NULL) WP(w,def_d).close = true;
--- a/src/road_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/road_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -230,7 +230,7 @@
 	case WE_ABORT_PLACE_OBJ:
 		w->RaiseButtons();
 		DisableWindowWidget(w, RTW_REMOVE);
-		InvalidateWidget(w, RTW_REMOVE);
+		w->InvalidateWidget(RTW_REMOVE);
 
 		w = Window::FindById(WC_BUS_STATION, 0);
 		if (w != NULL) WP(w,def_d).close = true;
--- a/src/station_gui.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/station_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -743,10 +743,10 @@
 
 			/* toggle height/widget set */
 			if (IsWindowOfPrototype(w, _station_view_expanded_widgets)) {
-				AssignWidgetToWindow(w, _station_view_widgets);
+				w->AssignWidgetToWindow(_station_view_widgets);
 				w->height = 110;
 			} else {
-				AssignWidgetToWindow(w, _station_view_expanded_widgets);
+				w->AssignWidgetToWindow(_station_view_expanded_widgets);
 				w->height = 210;
 			}
 
--- a/src/viewport.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/viewport.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -405,10 +405,10 @@
 void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
 {
 	SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == 0);
-	InvalidateWidget(w, widget_zoom_in);
+	w->InvalidateWidget(widget_zoom_in);
 
 	SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == 2);
-	InvalidateWidget(w, widget_zoom_out);
+	w->InvalidateWidget(widget_zoom_out);
 }
 
 void DrawGroundSpriteAt(SpriteID image, SpriteID pal, int32 x, int32 y, byte z)
--- a/src/widget.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/widget.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -591,7 +591,7 @@
 			Window *w2 = Window::FindById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
 			if (w2 != NULL) {
 				RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
-				InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
+				w2->InvalidateWidget( WP(w,dropdown_d).parent_button);
 			}
 		} break;
 	}
@@ -614,7 +614,7 @@
 
 	LowerWindowWidget(w, button);
 
-	InvalidateWidget(w, button);
+	w->InvalidateWidget(button);
 
 	for (i = 0; strings[i] != INVALID_STRING_ID; i++) {}
 	if (i == 0) return;
--- a/src/window.cpp	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/window.cpp	Tue Feb 13 01:04:32 2007 +0000
@@ -134,7 +134,7 @@
 	width = w;
 	height = h;
 	wndproc = proc;
-	AssignWidgetToWindow(this, widget);
+	this->AssignWidgetToWindow(widget);
 	resize.width = width;
 	resize.height = height;
 	resize.step_width = 1;
@@ -313,7 +313,7 @@
 	for (i = 0; i < widget_count; i++) {
 		if (IsWindowWidgetLowered(this, i)) {
 			RaiseWindowWidget(this, i);
-			InvalidateWidget(this, i);
+			this->InvalidateWidget(i);
 		}
 	}
 }
@@ -322,7 +322,7 @@
 {
 	LowerWindowWidget(this, widget);
 	this->flags4 |= 5 << WF_TIMEOUT_SHL;
-	InvalidateWidget(this, widget);
+	this->InvalidateWidget(widget);
 }
 
 /** On clicking on a window, make it the frontmost window of all. However
@@ -637,13 +637,13 @@
 
 		if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
 			w->StartSizing();
-			InvalidateWidget(w, e.we.click.widget);
+			w->InvalidateWidget(e.we.click.widget);
 			return;
 		}
 
 		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
 			w->flags4 ^= WF_STICKY;
-			InvalidateWidget(w, e.we.click.widget);
+			w->InvalidateWidget(e.we.click.widget);
 			return;
 		}
 	}
@@ -928,22 +928,22 @@
 }
 
 /* Copies 'widget' to 'w->widget' to allow for resizable windows */
-void AssignWidgetToWindow(Window *w, const Widget *widget)
+void Window::AssignWidgetToWindow(const Widget *widget_array)
 {
-	w->original_widget = widget;
+	original_widget = widget_array;
 
-	if (widget != NULL) {
+	if (widget_array != NULL) {
 		uint index = 1;
 		const Widget *wi;
 
-		for (wi = widget; wi->type != WWT_LAST; wi++) index++;
+		for (wi = widget_array; wi->type != WWT_LAST; wi++) index++;
 
-		w->widget = ReallocT(w->widget, index);
-		memcpy(w->widget, widget, sizeof(*w->widget) * index);
-		w->widget_count = index - 1;
+		widget = ReallocT(widget, index);
+		memcpy(widget, widget_array, sizeof(*widget) * index);
+		widget_count = index - 1;
 	} else {
-		w->widget = NULL;
-		w->widget_count = 0;
+		widget = NULL;
+		widget_count = 0;
 	}
 }
 
@@ -1867,14 +1867,14 @@
 	}
 }
 
-void InvalidateWidget(const Window *w, byte widget_index)
+void Window::InvalidateWidget(byte widget_index) const
 {
-	const Widget *wi = &w->widget[widget_index];
+	const Widget *wi = &widget[widget_index];
 
 	/* Don't redraw the window if the widget is invisible or of no-type */
-	if (wi->type == WWT_EMPTY || IsWindowWidgetHidden(w, widget_index)) return;
+	if (wi->type == WWT_EMPTY || IsWindowWidgetHidden(this, widget_index)) return;
 
-	SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
+	SetDirtyBlocks(left + wi->left, top + wi->top, left + wi->right + 1, top + wi->bottom + 1);
 }
 
 void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
@@ -1882,7 +1882,7 @@
 	Window *w;
 	FOR_ALL_WINDOWS(w) {
 		if (w->window_class == cls && w->window_number == number) {
-			InvalidateWidget(w, widget_index);
+			w->InvalidateWidget(widget_index);
 		}
 	}
 }
--- a/src/window.h	Mon Feb 12 23:12:02 2007 +0000
+++ b/src/window.h	Tue Feb 13 01:04:32 2007 +0000
@@ -387,6 +387,10 @@
 	static Window* FindById(WindowClass cls, WindowNumber num);
 	static void SetDirtyById(WindowClass cls, WindowNumber num);
 
+	void AssignWidgetToWindow(const Widget *widget);
+
+	void InvalidateWidget(byte widget_index) const;
+
 	//int32 AddRef()
 	//{
 	//	const char *name = NULL;
@@ -724,7 +728,6 @@
 Window *FindWindowFromPt(int x, int y);
 
 bool IsWindowOfPrototype(const Window *w, const Widget *widget);
-void AssignWidgetToWindow(Window *w, const Widget *widget);
 //Window *AllocateWindow(
 //							int x,
 //							int y,
@@ -892,7 +895,6 @@
 void ResetWindowSystem(void);
 int GetMenuItemIndex(const Window *w, int x, int y);
 void InputLoop(void);
-void InvalidateWidget(const Window *w, byte widget_index);
 void InvalidateThisWindowData(Window *w);
 void InvalidateWindowData(WindowClass cls, WindowNumber number);
 //void RaiseWindowButtons(Window *w);