(svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods cpp_gui
authorbjarni
Tue, 13 Feb 2007 09:54:37 +0000
branchcpp_gui
changeset 6238 1ff56ccccbb5
parent 6237 bce32e54c993
child 6239 925a1bba771f
(svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
src/build_vehicle_gui.cpp
src/depot_gui.cpp
src/main_gui.cpp
src/vehicle_gui.cpp
src/window.cpp
src/window.h
--- a/src/build_vehicle_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/build_vehicle_gui.cpp	Tue Feb 13 09:54:37 2007 +0000
@@ -967,17 +967,17 @@
 	switch (type) {
 		case VEH_Train:
 			WP(w,buildvehicle_d).filter.railtype = (tile == 0) ? RAILTYPE_END : GetRailType(tile);
-			ResizeWindow(w, 0, 16);
+			w->ResizeWindow(0, 16);
 			break;
 		case VEH_Road:
-			ResizeWindow(w, 20, 16);
+			w->ResizeWindow(20, 16);
 		case VEH_Ship:
-			ResizeWindow(w, 27, 0);
+			w->ResizeWindow(27, 0);
 			break;
 		case VEH_Aircraft:
 			AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
 			bv->filter.acc_planes = acc_planes;
-			ResizeWindow(w, 12, 0);
+			w->ResizeWindow(12, 0);
 			break;
 	}
 	SetupWindowStrings(w, type);
--- a/src/depot_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/depot_gui.cpp	Tue Feb 13 09:54:37 2007 +0000
@@ -711,13 +711,12 @@
 	w->resize.step_height = _block_sizes[type][1];
 
 	/* Enlarge the window to fit with the selected number of blocks of the selected size */
-	ResizeWindow(w,
-				 _block_sizes[type][0] * w->hscroll.cap,
-				 _block_sizes[type][1] * w->vscroll.cap);
+	w->ResizeWindow(_block_sizes[type][0] * w->hscroll.cap,
+	                _block_sizes[type][1] * w->vscroll.cap);
 
 	if (type == VEH_Train) {
 		/* The train depot has a horizontal scroller so we should make room for it */
-		ResizeWindow(w, 0, 12);
+		w->ResizeWindow(0, 12);
 		/* substract the newly added space from the matrix since it was meant for the scrollbar */
 		w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12;
 	}
--- a/src/main_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/main_gui.cpp	Tue Feb 13 09:54:37 2007 +0000
@@ -463,7 +463,7 @@
 		}
 
 	case WE_POPUPMENU_SELECT: {
-		int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+		int index = w->GetMenuItemIndex(e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 		int action_id;
 
 
@@ -485,7 +485,7 @@
 		}
 
 	case WE_POPUPMENU_OVER: {
-		int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+		int index = w->GetMenuItemIndex(e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 
 		if (index == -1 || index == WP(w,menu_d).sel_index) return;
 
@@ -598,7 +598,7 @@
 		}
 
 	case WE_POPUPMENU_SELECT: {
-		int index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+		int index = w->GetMenuItemIndex(e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 		int action_id = WP(w,menu_d).action_id;
 
 		// We have a new entry at the top of the list of menu 9 when networking
@@ -626,7 +626,7 @@
 	case WE_POPUPMENU_OVER: {
 		int index;
 		UpdatePlayerMenuHeight(w);
-		index = GetMenuItemIndex(w, e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
+		index = w->GetMenuItemIndex(e->we.popupmenu.pt.x, e->we.popupmenu.pt.y);
 
 		// We have a new entry at the top of the list of menu 9 when networking
 		//  so keep that in count
--- a/src/vehicle_gui.cpp	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/vehicle_gui.cpp	Tue Feb 13 09:54:37 2007 +0000
@@ -1250,11 +1250,11 @@
 		default: NOT_REACHED();
 		case VEH_Train:
 			w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num);
-			if (w != NULL) ResizeWindow(w, 65, 38);
+			if (w != NULL) w->ResizeWindow(65, 38);
 			break;
 		case VEH_Road:
 			w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num);
-			if (w != NULL) ResizeWindow(w, 0, 38);
+			if (w != NULL) w->ResizeWindow(0, 38);
 			break;
 		case VEH_Ship:
 			w = AllocateWindowDescFront(&_player_vehicle_list_ship_desc, num);
--- a/src/window.cpp	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/window.cpp	Tue Feb 13 09:54:37 2007 +0000
@@ -560,7 +560,7 @@
 	_drag_delta.y += y;
 
 	/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
-	ResizeWindow(this, x, y);
+	this->ResizeWindow(x, y);
 
 	e.event = WE_RESIZE;
 	e.we.sizing.size.x = x + width;
@@ -1365,10 +1365,9 @@
 /** Update all the widgets of a window based on their resize flags
  * Both the areas of the old window and the new sized window are set dirty
  * ensuring proper redrawal.
- * @param w Window to resize
  * @param x delta x-size of changed window (positive if larger, etc.(
  * @param y delta y-size of changed window */
-void ResizeWindow(Window *w, int x, int y)
+void Window::ResizeWindow(int x, int y)
 {
 	Widget *wi;
 	bool resize_height = false;
@@ -1376,8 +1375,8 @@
 
 	if (x == 0 && y == 0) return;
 
-	w->SetDirty();
-	for (wi = w->widget; wi->type != WWT_LAST; wi++) {
+	this->SetDirty();
+	for (wi = widget; wi->type != WWT_LAST; wi++) {
 		/* Isolate the resizing flags */
 		byte rsizeflag = GB(wi->display_flags, 0, 4);
 
@@ -1406,10 +1405,10 @@
 	}
 
 	/* We resized at least 1 widget, so let's resize the window totally */
-	if (resize_width)  w->width  += x;
-	if (resize_height) w->height += y;
+	if (resize_width)  width  += x;
+	if (resize_height) height += y;
 
-	w->SetDirty();
+	SetDirty();
 }
 
 static bool HandleScrollbarScrolling(void)
@@ -1845,13 +1844,13 @@
 }
 
 
-int GetMenuItemIndex(const Window *w, int x, int y)
+int Window::GetMenuItemIndex(int x, int y) const
 {
-	if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
+	if ((x -= left) >= 0 && x < width && (y -= top + 1) >= 0) {
 		y /= 10;
 
-		if (y < WP(w, const menu_d).item_count &&
-				!HASBIT(WP(w, const menu_d).disabled_items, y)) {
+		if (y < WP(this, const menu_d).item_count &&
+				!HASBIT(WP(this, const menu_d).disabled_items, y)) {
 			return y;
 		}
 	}
--- a/src/window.h	Tue Feb 13 01:04:32 2007 +0000
+++ b/src/window.h	Tue Feb 13 09:54:37 2007 +0000
@@ -387,6 +387,9 @@
 	static Window* FindById(WindowClass cls, WindowNumber num);
 	static void SetDirtyById(WindowClass cls, WindowNumber num);
 
+	int GetMenuItemIndex(int x, int y) const;
+	void ResizeWindow(int x, int y);
+
 	void AssignWidgetToWindow(const Widget *widget);
 
 	void InvalidateWidget(byte widget_index) const;
@@ -741,7 +744,6 @@
 Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number);
 
 void DrawWindowViewport(const Window *w);
-void ResizeWindow(Window *w, int x, int y);
 
 /**
  * Sets the enabled/disabled status of a widget.
@@ -893,7 +895,6 @@
 void InitWindowSystem(void);
 void UnInitWindowSystem(void);
 void ResetWindowSystem(void);
-int GetMenuItemIndex(const Window *w, int x, int y);
 void InputLoop(void);
 void InvalidateThisWindowData(Window *w);
 void InvalidateWindowData(WindowClass cls, WindowNumber number);