Changeset - r9781:10a19184a5ba
[Not reviewed]
master
0 3 0
frosch - 16 years ago 2008-08-02 11:26:25
frosch@openttd.org
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
3 files changed with 26 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -622,15 +622,17 @@ struct TooltipsWindow : public Window
 
	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 @@ struct TooltipsWindow : public Window
 
	{
 
		/* 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 @@ void GuiShowTooltipsWithArgs(StringID st
 
	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);
 
}
 

	
 

	
src/viewport.cpp
Show inline comments
 
@@ -2201,6 +2201,17 @@ void UpdateTileSelection()
 
	}
 
}
 

	
 
/** 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 @@ void VpSetPresizeRange(TileIndex from, T
 
	_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 @@ static void CalcRaildirsDrawstyle(TileHi
 
			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 @@ calc_heightdiff_single_direction:;
 
					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 @@ calc_heightdiff_single_direction:;
 
					if (heightdiff != 0) params[index++] = heightdiff;
 
				}
 

	
 
				GuiShowTooltipsWithArgs(measure_strings_area[index], index, params);
 
				ShowMeasurementTooltips(measure_strings_area[index], index, params);
 
			}
 
		break;
 

	
src/window_gui.h
Show inline comments
 
@@ -524,11 +524,7 @@ Wcls *AllocateWindowDescFront(const Wind
 
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);
0 comments (0 inline, 0 general)