(svn r13550) -Fix(r13540, r13542): widget_count did not had the same value as 27. So, it has to be lowered by one, so it can be used as a widget "pointer"
authorbelugas
Tue, 17 Jun 2008 16:33:55 +0000
changeset 10996 c0f85c0d7284
parent 10990 787c5664f30b
child 10997 968df7476121
(svn r13550) -Fix(r13540, r13542): widget_count did not had the same value as 27. So, it has to be lowered by one, so it can be used as a widget "pointer"
src/toolbar_gui.cpp
--- a/src/toolbar_gui.cpp	Tue Jun 17 07:05:17 2008 +0000
+++ b/src/toolbar_gui.cpp	Tue Jun 17 16:33:55 2008 +0000
@@ -715,17 +715,19 @@
 	/* There are 27 buttons plus some spacings if the space allows it */
 	uint button_width;
 	uint spacing;
-	if (w->width >= (int)w->widget_count * 22) {
+	uint widgetcount = w->widget_count - 1;
+
+	if (w->width >= (int)widgetcount * 22) {
 		button_width = 22;
-		spacing = w->width - (w->widget_count * button_width);
+		spacing = w->width - (widgetcount * button_width);
 	} else {
-		button_width = w->width / w->widget_count;
+		button_width = w->width / widgetcount;
 		spacing = 0;
 	}
 
 	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++) {
+	for (uint x = 0, j = 0; i < widgetcount; i++) {
 		if (extra_spacing_at[j] == i) {
 			j++;
 			uint add = spacing / (lengthof(extra_spacing_at) - j);
@@ -735,7 +737,7 @@
 
 		w->widget[i].type = WWT_IMGBTN;
 		w->widget[i].left = x;
-		x += (spacing != 0) ? button_width : (w->width - x) / (w->widget_count - i);
+		x += (spacing != 0) ? button_width : (w->width - x) / (widgetcount - i);
 		w->widget[i].right = x - 1;
 	}
 
@@ -780,7 +782,7 @@
 	assert(max_icons >= 14 && max_icons <= 19);
 
 	/* first hide all icons */
-	for (uint i = 0; i < w->widget_count; i++) {
+	for (uint i = 0; i < w->widget_count - 1; i++) {
 		w->widget[i].type = WWT_EMPTY;
 	}
 
@@ -940,7 +942,7 @@
 
 	virtual void OnTimeout()
 	{
-		for (uint i = TBN_SETTINGS; i < this->widget_count; i++) {
+		for (uint i = TBN_SETTINGS; i < this->widget_count - 1; i++) {
 			if (this->IsWidgetLowered(i)) {
 				this->RaiseWidget(i);
 				this->InvalidateWidget(i);
@@ -1133,7 +1135,7 @@
 		}
 		uint extra_spacing_at[] = { 3, 4, 7, 8, 10, 16, 0 };
 
-		for (uint i = 0, x = 0, j = 0, b = 0; i < this->widget_count; i++) {
+		for (uint i = 0, x = 0, j = 0, b = 0; i < this->widget_count - 1; i++) {
 			switch (i) {
 				case 4:
 					this->widget[i].left = x;