From 37c58f606b35e7a84c2ab415d78c17d74718381d Mon Sep 17 00:00:00 2001 From: belugas Date: Tue, 17 Jun 2008 03:13:09 +0000 Subject: (svn r13542) -Codechange: Less a few more magic numbers and a code a bit more adaptable, still --- src/toolbar_gui.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 10cf8b1ff..029493029 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -682,16 +682,17 @@ static void ResizeToolbar(Window *w) /* There are 27 buttons plus some spacings if the space allows it */ uint button_width; uint spacing; - if (w->width >= 27 * 22) { + if (w->width >= (int)w->widget_count * 22) { button_width = 22; - spacing = w->width - (27 * button_width); + spacing = w->width - (w->widget_count * button_width); } else { - button_width = w->width / 27; + button_width = w->width / w->widget_count; spacing = 0; } - uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; - for (uint i = 0, x = 0, j = 0; i < 27; i++) { + uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; + uint i = 0; + for (uint x = 0, j = 0; i < w->widget_count; i++) { if (extra_spacing_at[j] == i) { j++; uint add = spacing / (lengthof(extra_spacing_at) - j); @@ -701,11 +702,11 @@ static void ResizeToolbar(Window *w) w->widget[i].type = WWT_IMGBTN; w->widget[i].left = x; - x += (spacing != 0) ? button_width : (w->width - x) / (27 - i); + x += (spacing != 0) ? button_width : (w->width - x) / (w->widget_count - i); w->widget[i].right = x - 1; } - w->widget[27].type = WWT_EMPTY; + w->widget[i].type = WWT_EMPTY; // i now points to the last item _toolbar_mode = TB_NORMAL; } @@ -746,7 +747,7 @@ static void SplitToolbar(Window *w) assert(max_icons >= 14 && max_icons <= 19); /* first hide all icons */ - for (uint i = 0; i < 27; i++) { + for (uint i = 0; i < w->widget_count; i++) { w->widget[i].type = WWT_EMPTY; } -- cgit v1.2.3-70-g09d2