(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
authorfrosch
Sat, 02 Aug 2008 11:26:25 +0000
changeset 9781 31e0e461d7bf
parent 9780 bb23abff1107
child 9782 f89be25a12ae
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
src/misc_gui.cpp
src/viewport.cpp
src/window_gui.h
--- a/src/misc_gui.cpp	Sat Aug 02 10:17:45 2008 +0000
+++ b/src/misc_gui.cpp	Sat Aug 02 11:26:25 2008 +0000
@@ -622,15 +622,17 @@
 	StringID string_id;
 	byte paramcount;
 	uint64 params[5];
+	bool use_left_mouse_button;
 
 	TooltipsWindow(int x, int y, int width, int height, const Widget *widget,
-								 StringID str, uint paramcount, const uint64 params[]) :
+								 StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) :
 			Window(x, y, width, height, WC_TOOLTIPS, widget)
 	{
 		this->string_id = str;
 		assert(sizeof(this->params[0]) == sizeof(params[0]));
 		memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
 		this->paramcount = paramcount;
+		this->use_left_mouse_button = use_left_mouse_button;
 
 		this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip
 		this->widget[0].right = width;
@@ -654,25 +656,21 @@
 	{
 		/* We can show tooltips while dragging tools. These are shown as long as
 		 * we are dragging the tool. Normal tooltips work with rmb */
-		if (this->paramcount == 0 ) {
-			if (!_right_button_down) delete this;
-		} else {
-			if (!_left_button_down) delete this;
-		}
+		if (this->use_left_mouse_button ? !_left_button_down : !_right_button_down) delete this;
 	}
 };
 
 /** Shows a tooltip
  * @param str String to be displayed
  * @param paramcount number of params to deal with
- * @param params (optional) up to 5 pieces of additional information that may be
- * added to a tooltip; currently only supports parameters of {NUM} (integer) */
-void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[])
+ * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
+ * @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released
+ */
+void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button)
 {
 	DeleteWindowById(WC_TOOLTIPS, 0);
 
-	/* We only show measurement tooltips with patch setting on */
-	if (str == STR_NULL || (paramcount != 0 && !_settings_client.gui.measure_tooltip)) return;
+	if (str == STR_NULL) return;
 
 	for (uint i = 0; i != paramcount; i++) SetDParam(i, params[i]);
 	char buffer[512];
@@ -694,7 +692,7 @@
 	if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5;
 	int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width);
 
-	new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params);
+	new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params, use_left_mouse_button);
 }
 
 
--- a/src/viewport.cpp	Sat Aug 02 10:17:45 2008 +0000
+++ b/src/viewport.cpp	Sat Aug 02 11:26:25 2008 +0000
@@ -2201,6 +2201,17 @@
 	}
 }
 
+/** Displays the measurement tooltips when selecting multiple tiles
+ * @param str String to be displayed
+ * @param paramcount number of params to deal with
+ * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
+ */
+static inline void ShowMeasurementTooltips(StringID str, uint paramcount, const uint64 params[])
+{
+	if (!_settings_client.gui.measure_tooltip) return;
+	GuiShowTooltips(str, paramcount, params, true);
+}
+
 /** highlighting tiles while only going over them with the mouse */
 void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
 {
@@ -2254,7 +2265,7 @@
 	_thd.next_drawstyle = HT_RECT;
 
 	/* show measurement only if there is any length to speak of */
-	if (distance > 1) GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, &distance);
+	if (distance > 1) ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1, &distance);
 }
 
 static void VpStartPreSizing()
@@ -2535,7 +2546,7 @@
 			if (heightdiff != 0) params[index++] = heightdiff;
 		}
 
-		GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
+		ShowMeasurementTooltips(measure_strings_length[index], index, params);
 	}
 
 	thd->selend.x = x;
@@ -2614,7 +2625,7 @@
 					if (heightdiff != 0) params[index++] = heightdiff;
 				}
 
-				GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
+				ShowMeasurementTooltips(measure_strings_length[index], index, params);
 			} break;
 
 		case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
@@ -2654,7 +2665,7 @@
 					if (heightdiff != 0) params[index++] = heightdiff;
 				}
 
-				GuiShowTooltipsWithArgs(measure_strings_area[index], index, params);
+				ShowMeasurementTooltips(measure_strings_area[index], index, params);
 			}
 		break;
 
--- a/src/window_gui.h	Sat Aug 02 10:17:45 2008 +0000
+++ b/src/window_gui.h	Sat Aug 02 11:26:25 2008 +0000
@@ -524,11 +524,7 @@
 void RelocateAllWindows(int neww, int newh);
 
 /* misc_gui.cpp */
-void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]);
-static inline void GuiShowTooltips(StringID str)
-{
-	GuiShowTooltipsWithArgs(str, 0, NULL);
-}
+void GuiShowTooltips(StringID str, uint paramcount = 0, const uint64 params[] = NULL, bool use_left_mouse_button = false);
 
 /* widget.cpp */
 int GetWidgetFromPos(const Window *w, int x, int y);