(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added

This commit is contained in:
bjarni 2007-01-24 02:36:55 +00:00
parent a1a6e1eb85
commit e2f72cbf1f
5 changed files with 68 additions and 31 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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 */