summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-01-24 02:36:55 +0000
committerbjarni <bjarni@openttd.org>2007-01-24 02:36:55 +0000
commite2f72cbf1ff97f1b0eab68614ac730fe8cd47b73 (patch)
tree6db06687d695ee0417f9694efa9466b841ab1481
parenta1a6e1eb85017bcddef24825103fb86240535d2e (diff)
downloadopenttd-e2f72cbf1ff97f1b0eab68614ac730fe8cd47b73.tar.xz
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
-rw-r--r--src/build_vehicle_gui.cpp12
-rw-r--r--src/depot_gui.cpp8
-rw-r--r--src/train_gui.cpp15
-rw-r--r--src/widget.cpp47
-rw-r--r--src/window.h17
5 files changed, 68 insertions, 31 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index b352d06ff..1129c2b54 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -56,14 +56,6 @@ static const Widget _build_vehicle_widgets[] = {
{ WIDGETS_END},
};
-static void ResizeButtons(Window *w)
-{
- /* Make the buttons in the bottom equal in size */
- w->widget[BUILD_VEHICLE_WIDGET_RENAME].right = w->widget[BUILD_VEHICLE_WIDGET_RESIZE].left - 1;
- w->widget[BUILD_VEHICLE_WIDGET_RENAME].left = w->widget[BUILD_VEHICLE_WIDGET_RENAME].right / 2;
- w->widget[BUILD_VEHICLE_WIDGET_BUILD].right = w->widget[BUILD_VEHICLE_WIDGET_RENAME].left - 1;
-}
-
/* Setup widget strings to fit the different types of vehicles */
static void SetupWindowStrings(Window *w, byte type)
{
@@ -922,7 +914,7 @@ static void NewVehicleWndProc(Window *w, WindowEvent *e)
break;
case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) ResizeButtons(w);
+ if (e->we.sizing.diff.x != 0) ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RESIZE);
if (e->we.sizing.diff.y == 0) break;
w->vscroll.cap += e->we.sizing.diff.y / GetVehicleListHeight(bv->vehicle_type);
@@ -984,7 +976,7 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
break;
}
SetupWindowStrings(w, type);
- ResizeButtons(w);
+ ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RESIZE);
w->resize.width = w->width;
w->resize.height = w->height;
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 71ab1e799..4b5166da3 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -497,13 +497,7 @@ static void ClonePlaceObj(const Window *w)
static void ResizeDepotButtons(Window *w)
{
- /* We got the widget moved around. Now we will make some widgets to fill the gap between some widgets in equal sizes */
-
- /* Make the buttons in the bottom equal in size */
- w->widget[DEPOT_WIDGET_BUILD].right = w->widget[DEPOT_WIDGET_LOCATION].right / 3;
- w->widget[DEPOT_WIDGET_LOCATION].left = w->widget[DEPOT_WIDGET_BUILD].right * 2;
- w->widget[DEPOT_WIDGET_CLONE].left = w->widget[DEPOT_WIDGET_BUILD].right + 1;
- w->widget[DEPOT_WIDGET_CLONE].right = w->widget[DEPOT_WIDGET_LOCATION].left - 1;
+ ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_VEHICLE_LIST);
if (WP(w, depot_d).type == VEH_Train) {
/* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size.
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 060c1fea5..b952b3534 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -506,19 +506,6 @@ static void DrawTrainDetailsWindow(Window *w)
}
}
-static void TrainDetailButtonResize(Window *w)
-{
- /* Make the buttons in the bottom equal in size */
- w->widget[12].right = w->widget[13].left - 1; // right point of the buttons (4/4)
- w->widget[10].right = w->widget[12].right / 2; // the middle of the buttons (2/4)
- w->widget[ 9].right = w->widget[10].right / 2; // 1/4 of the buttons
- w->widget[11].right = w->widget[10].right + w->widget[ 9].right; // (2+1)/4 = 3/4 of the buttons
- /* Now the right side of the buttons are set. We will now set the left sides next to them */
- w->widget[10].left = w->widget[ 9].right + 1;
- w->widget[11].left = w->widget[10].right + 1;
- w->widget[12].left = w->widget[11].right + 1;
-}
-
static void TrainDetailsWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -573,7 +560,7 @@ do_change_service_int:
break;
case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) TrainDetailButtonResize(w);
+ if (e->we.sizing.diff.x != 0) ResizeButtons(w, 9, 13);
if (e->we.sizing.diff.y == 0) break;
w->vscroll.cap += e->we.sizing.diff.y / 14;
diff --git a/src/widget.cpp b/src/widget.cpp
index 2c6dba2fa..2c21cd74c 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -698,3 +698,50 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
WP(w2,dropdown_d).click_delay = 0;
WP(w2,dropdown_d).drag_mode = true;
}
+
+/* Make the buttons in the bottom equal in size */
+void ResizeButtons(Window *w, byte a, byte b, byte c, byte d, byte right)
+{
+ w->widget[d].right = w->widget[right].left - 1; // now we set the right of the widgets
+
+ /* Now we will find the middle, then the middle of each of the two blocks on each side of the middle.
+ * This way, if we got leftover pixels from the division, they will be somewhat evenly distributed */
+ w->widget[b].right = w->widget[d].right / 2;
+ w->widget[a].right = w->widget[b].right / 2;
+ w->widget[c].right = (w->widget[b].right + w->widget[d].right)/2;
+ /* Now the right side of the buttons are set. We will now set the left sides next to them */
+ w->widget[b].left = w->widget[a].right + 1;
+ w->widget[c].left = w->widget[b].right + 1;
+ w->widget[d].left = w->widget[c].right + 1;
+}
+
+void ResizeButtons(Window *w, byte a, byte b, byte c, byte right)
+{
+ w->widget[c].right = w->widget[right].left - 1; // now we set the right of the widgets
+
+ w->widget[a].right = w->widget[c].right / 3;
+ w->widget[b].right = w->widget[a].right * 2;
+
+ /* Now the right side of the buttons are set. We will now set the left sides next to them */
+ w->widget[b].left = w->widget[a].right + 1;
+ w->widget[c].left = w->widget[b].right + 1;
+}
+
+void ResizeButtons(Window *w, byte a, byte b, byte right)
+{
+ w->widget[b].right = w->widget[right].left - 1; // now we set the right of the widgets
+
+ w->widget[a].right = w->widget[b].right / 2;
+
+ w->widget[b].left = w->widget[a].right + 1;
+}
+
+void ResizeButtons(Window *w, byte left, byte right)
+{
+ switch (right - left) {
+ case 2: ResizeButtons(w, left, left + 1, left + 2); break;
+ case 3: ResizeButtons(w, left, left + 1, left + 2, left + 3); break;
+ case 4: ResizeButtons(w, left, left + 1, left + 2, left + 3, left + 4); break;
+ default: NOT_REACHED();
+ }
+}
diff --git a/src/window.h b/src/window.h
index be3edae9d..5e5fcf6ba 100644
--- a/src/window.h
+++ b/src/window.h
@@ -767,4 +767,21 @@ enum SpecialMouseMode {
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y);
+/** Evenly distribute some widgets when resizing horizontally (often a button row)
+ * @param w widow to modify
+ * @param a,b,c,d the widgets to resize (left to right, order matters)
+ * @param right the widget right of the buttons, that needs resizing
+ */
+void ResizeButtons(Window *w, byte a, byte b, byte right);
+void ResizeButtons(Window *w, byte a, byte b, byte c, byte right);
+void ResizeButtons(Window *w, byte a, byte b, byte c, byte d, byte right);
+
+/** Evenly distribute some widgets when resizing horizontally (often a button row)
+ * When only two arguments are given, the widgets are presumed to be on a line and only the ends are given
+ * @param w widow to modify
+ * @param left The leftmost widget to resize
+ * @param right The widget just right of the widgets to resize
+ */
+void ResizeButtons(Window *w, byte left, byte right);
+
#endif /* WINDOW_H */