From 4dd0d007b1cf1f595fba5d690a096e69c7bbca20 Mon Sep 17 00:00:00 2001 From: bjarni Date: Wed, 24 Jan 2007 02:36:55 +0000 Subject: (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added --- src/widget.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/widget.cpp') 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(); + } +} -- cgit v1.2.3-54-g00ecf