(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
authorpeter1138
Sat, 26 Jan 2008 20:55:04 +0000
changeset 8914 6ebaa4b4eb2b
parent 8913 b62e2db9de38
child 8915 db4c2ae09c4b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
src/build_vehicle_gui.cpp
src/widget.cpp
src/window_gui.h
--- a/src/build_vehicle_gui.cpp	Sat Jan 26 03:11:27 2008 +0000
+++ b/src/build_vehicle_gui.cpp	Sat Jan 26 20:55:04 2008 +0000
@@ -958,23 +958,6 @@
 	}
 }
 
-static void ExpandPurchaseInfoWidget(Window *w, int expand_by)
-{
-	Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
-
-	SetWindowDirty(w);
-	wi->bottom += expand_by;
-
-	for (uint i = BUILD_VEHICLE_WIDGET_BUILD; i < BUILD_VEHICLE_WIDGET_END; i++) {
-		wi = &w->widget[i];
-		wi->top += expand_by;
-		wi->bottom += expand_by;
-	}
-
-	w->height += expand_by;
-	SetWindowDirty(w);
-}
-
 static void DrawBuildVehicleWindow(Window *w)
 {
 	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
@@ -996,7 +979,11 @@
 		const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
 		int text_end = DrawVehiclePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, bv->sel_engine);
 
-		if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
+		if (text_end > wi->bottom) {
+			SetWindowDirty(w);
+			ResizeWindowForWidget(w, BUILD_VEHICLE_WIDGET_PANEL, 0, text_end - wi->bottom);
+			SetWindowDirty(w);
+		}
 	}
 
 	DrawSortButtonState(w, BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, bv->descending_sort_order ? SBS_DOWN : SBS_UP);
--- a/src/widget.cpp	Sat Jan 26 03:11:27 2008 +0000
+++ b/src/widget.cpp	Sat Jan 26 20:55:04 2008 +0000
@@ -583,6 +583,24 @@
 	}
 }
 
+void ResizeWindowForWidget(Window *w, int widget, int delta_x, int delta_y)
+{
+	int right  = w->widget[widget].right;
+	int bottom = w->widget[widget].bottom;
+
+	for (uint i = 0; i < w->widget_count; i++) {
+		if (w->widget[i].left >= right) w->widget[i].left += delta_x;
+		if (w->widget[i].right >= right) w->widget[i].right += delta_x;
+		if (w->widget[i].top >= bottom) w->widget[i].top += delta_y;
+		if (w->widget[i].bottom >= bottom) w->widget[i].bottom += delta_y;
+	}
+
+	w->width  += delta_x;
+	w->height += delta_y;
+	w->resize.width  += delta_x;
+	w->resize.height += delta_y;
+}
+
 /** Draw a sort button's up or down arrow symbol.
  * @param w Window of widget
  * @param widget Sort button widget
--- a/src/window_gui.h	Sat Jan 26 03:11:27 2008 +0000
+++ b/src/window_gui.h	Sat Jan 26 20:55:04 2008 +0000
@@ -630,6 +630,10 @@
  */
 void ResizeButtons(Window *w, byte left, byte right);
 
+/** Resize a widget an shuffle other widgets around to fit.
+ */
+void ResizeWindowForWidget(Window *w, int widget, int delta_x, int delta_y);
+
 
 /**
  * Sets the enabled/disabled status of a widget.