(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
is only a single tile. Seems this was a bit annoying to some ;)
This commit is contained in:
		
							
								
								
									
										10
									
								
								misc_gui.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								misc_gui.c
									
									
									
									
									
								
							@@ -665,18 +665,18 @@ static void TooltipsWndProc(Window *w, WindowEvent *e)
 | 
				
			|||||||
* @param str String to be displayed
 | 
					* @param str String to be displayed
 | 
				
			||||||
* @param params (optional) up to 5 pieces of additional information that may be
 | 
					* @param params (optional) up to 5 pieces of additional information that may be
 | 
				
			||||||
* added to a tooltip; currently only supports parameters of {NUM} (integer) */
 | 
					* added to a tooltip; currently only supports parameters of {NUM} (integer) */
 | 
				
			||||||
void GuiShowTooltipsWithArgs(StringID str, uint paramcount, uint32 params[])
 | 
					void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char buffer[512];
 | 
						char buffer[512];
 | 
				
			||||||
	BoundingRect br;
 | 
						BoundingRect br;
 | 
				
			||||||
 | 
						Window *w;
 | 
				
			||||||
	uint i;
 | 
						uint i;
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Window *w = FindWindowById(WC_TOOLTIPS, 0);
 | 
						DeleteWindowById(WC_TOOLTIPS, 0);
 | 
				
			||||||
	if (w != NULL) DeleteWindow(w);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* We only show measurement tooltips with shift pressed down */
 | 
						/* We only show measurement tooltips with patch setting on */
 | 
				
			||||||
	if (paramcount != 0 && !_patches.measure_tooltip) return;
 | 
						if (str == STR_NULL || (paramcount != 0 && !_patches.measure_tooltip)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i != paramcount; i++) SetDParam(i, params[i]);
 | 
						for (i = 0; i != paramcount; i++) SetDParam(i, params[i]);
 | 
				
			||||||
	GetString(buffer, str);
 | 
						GetString(buffer, str);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										56
									
								
								viewport.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								viewport.c
									
									
									
									
									
								
							@@ -2110,6 +2110,8 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
 | 
				
			|||||||
	return (int)(h1 - h0) * 50;
 | 
						return (int)(h1 - h0) * 50;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// while dragging
 | 
					// while dragging
 | 
				
			||||||
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
 | 
					static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -2215,9 +2217,11 @@ static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int meth
 | 
				
			|||||||
		TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y);
 | 
							TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y);
 | 
				
			||||||
		TileIndex t1 = TileVirtXY(x, y);
 | 
							TileIndex t1 = TileVirtXY(x, y);
 | 
				
			||||||
		uint distance = DistanceManhattan(t0, t1) + 1;
 | 
							uint distance = DistanceManhattan(t0, t1) + 1;
 | 
				
			||||||
		int heightdiff = CalcHeightdiff(b, distance, t0, t1);
 | 
							byte index = 0;
 | 
				
			||||||
		uint params[2];
 | 
							uint params[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (distance != 1) {
 | 
				
			||||||
 | 
								int heightdiff = CalcHeightdiff(b, distance, t0, t1);
 | 
				
			||||||
			/* If we are showing a tooltip for horizontal or vertical drags,
 | 
								/* If we are showing a tooltip for horizontal or vertical drags,
 | 
				
			||||||
			 * 2 tiles have a length of 1. To bias towards the ceiling we add
 | 
								 * 2 tiles have a length of 1. To bias towards the ceiling we add
 | 
				
			||||||
			 * one before division. It feels more natural to count 3 lengths as 2 */
 | 
								 * one before division. It feels more natural to count 3 lengths as 2 */
 | 
				
			||||||
@@ -2225,13 +2229,11 @@ static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int meth
 | 
				
			|||||||
				distance = (distance + 1) / 2;
 | 
									distance = (distance + 1) / 2;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		params[0] = distance;
 | 
								params[index++] = distance;
 | 
				
			||||||
		if (heightdiff == 0) {
 | 
								if (heightdiff != 0) params[index++] = heightdiff;
 | 
				
			||||||
			GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, params);
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			params[1] = heightdiff;
 | 
					 | 
				
			||||||
			GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH_HEIGHTDIFF, 2, params);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	thd->selend.x = x;
 | 
						thd->selend.x = x;
 | 
				
			||||||
@@ -2294,21 +2296,22 @@ calc_heightdiff_single_direction:;
 | 
				
			|||||||
				TileIndex t0 = TileVirtXY(sx, sy);
 | 
									TileIndex t0 = TileVirtXY(sx, sy);
 | 
				
			||||||
				TileIndex t1 = TileVirtXY(x, y);
 | 
									TileIndex t1 = TileVirtXY(x, y);
 | 
				
			||||||
				uint distance = DistanceManhattan(t0, t1) + 1;
 | 
									uint distance = DistanceManhattan(t0, t1) + 1;
 | 
				
			||||||
 | 
									byte index = 0;
 | 
				
			||||||
 | 
									uint params[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (distance != 1) {
 | 
				
			||||||
					/* With current code passing a HT_LINE style to calculate the height
 | 
										/* With current code passing a HT_LINE style to calculate the height
 | 
				
			||||||
					 * difference is enough. However if/when a point-tool is created
 | 
										 * difference is enough. However if/when a point-tool is created
 | 
				
			||||||
					 * with this method, function should be called with new_style (below)
 | 
										 * with this method, function should be called with new_style (below)
 | 
				
			||||||
					 * instead of HT_LINE | style case HT_POINT is handled specially
 | 
										 * instead of HT_LINE | style case HT_POINT is handled specially
 | 
				
			||||||
					 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
 | 
										 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
 | 
				
			||||||
					int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
 | 
										int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
 | 
				
			||||||
				uint params[2];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				params[0] = distance;
 | 
										params[index++] = distance;
 | 
				
			||||||
				if (heightdiff == 0) {
 | 
										if (heightdiff != 0) params[index++] = heightdiff;
 | 
				
			||||||
					GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, params);
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					params[1] = heightdiff;
 | 
					 | 
				
			||||||
					GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH_HEIGHTDIFF, 2, params);
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									GuiShowTooltipsWithArgs(measure_strings_length[index], index, params);
 | 
				
			||||||
			} break;
 | 
								} break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
 | 
							case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */
 | 
				
			||||||
@@ -2316,13 +2319,17 @@ calc_heightdiff_single_direction:;
 | 
				
			|||||||
			x = sx + clamp(x - sx, -limit, limit);
 | 
								x = sx + clamp(x - sx, -limit, limit);
 | 
				
			||||||
			y = sy + clamp(y - sy, -limit, limit);
 | 
								y = sy + clamp(y - sy, -limit, limit);
 | 
				
			||||||
			/* Fallthrough */
 | 
								/* Fallthrough */
 | 
				
			||||||
		case VPM_X_AND_Y: { /* drag an X by Y area */
 | 
							case VPM_X_AND_Y: /* drag an X by Y area */
 | 
				
			||||||
			if (_patches.measure_tooltip) {
 | 
								if (_patches.measure_tooltip) {
 | 
				
			||||||
 | 
									static const StringID measure_strings_area[] = {
 | 
				
			||||||
 | 
										STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
 | 
				
			||||||
 | 
									};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				TileIndex t0 = TileVirtXY(sx, sy);
 | 
									TileIndex t0 = TileVirtXY(sx, sy);
 | 
				
			||||||
				TileIndex t1 = TileVirtXY(x, y);
 | 
									TileIndex t1 = TileVirtXY(x, y);
 | 
				
			||||||
				uint dx = abs(TileX(t0) - TileX(t1)) + 1;
 | 
									uint dx = abs(TileX(t0) - TileX(t1)) + 1;
 | 
				
			||||||
				uint dy = abs(TileY(t0) - TileY(t1)) + 1;
 | 
									uint dy = abs(TileY(t0) - TileY(t1)) + 1;
 | 
				
			||||||
				int heightdiff;
 | 
									byte index = 0;
 | 
				
			||||||
				uint params[3];
 | 
									uint params[3];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				/* If dragging an area (eg dynamite tool) and it is actually a single
 | 
									/* If dragging an area (eg dynamite tool) and it is actually a single
 | 
				
			||||||
@@ -2336,18 +2343,17 @@ calc_heightdiff_single_direction:;
 | 
				
			|||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				heightdiff = CalcHeightdiff(style, 0, t0, t1);
 | 
									if (dx != 1 || dy != 1) {
 | 
				
			||||||
 | 
										int heightdiff = CalcHeightdiff(style, 0, t0, t1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				params[0] = dx;
 | 
										params[index++] = dx;
 | 
				
			||||||
				params[1] = dy;
 | 
										params[index++] = dy;
 | 
				
			||||||
				if (heightdiff == 0) {
 | 
										if (heightdiff != 0) params[index++] = heightdiff;
 | 
				
			||||||
					GuiShowTooltipsWithArgs(STR_MEASURE_AREA, 2, params);
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					params[2] = heightdiff;
 | 
					 | 
				
			||||||
					GuiShowTooltipsWithArgs(STR_MEASURE_AREA_HEIGHTDIFF, 3, params);
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									GuiShowTooltipsWithArgs(measure_strings_area[index], index, params);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		default: NOT_REACHED();
 | 
							default: NOT_REACHED();
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								window.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								window.h
									
									
									
									
									
								
							@@ -807,7 +807,7 @@ void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets,
 | 
				
			|||||||
void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...);
 | 
					void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* misc_gui.c*/
 | 
					/* misc_gui.c*/
 | 
				
			||||||
void GuiShowTooltipsWithArgs(StringID str, uint paramcount, uint params[]);
 | 
					void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint params[]);
 | 
				
			||||||
static inline void GuiShowTooltips(StringID str)
 | 
					static inline void GuiShowTooltips(StringID str)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	GuiShowTooltipsWithArgs(str, 0, NULL);
 | 
						GuiShowTooltipsWithArgs(str, 0, NULL);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user