diff options
author | frosch <frosch@openttd.org> | 2008-08-02 11:26:25 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2008-08-02 11:26:25 +0000 |
commit | 196268b7ff622f9cf24e6b7b138b4150b3ca7124 (patch) | |
tree | b97cb40953be7e1c6358fb063d63f445d3847aad /src | |
parent | 755b149902a302c0291e1fc458e2a60dc05af25d (diff) | |
download | openttd-196268b7ff622f9cf24e6b7b138b4150b3ca7124.tar.xz |
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
Diffstat (limited to 'src')
-rw-r--r-- | src/misc_gui.cpp | 22 | ||||
-rw-r--r-- | src/viewport.cpp | 19 | ||||
-rw-r--r-- | src/window_gui.h | 6 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 2c75465e4..ded54b9d0 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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 str, uint paramcount, const uint64 params[ 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); } diff --git a/src/viewport.cpp b/src/viewport.cpp index 91420c30e..d6ab2eef9 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -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, TileIndex to) _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(TileHighlightData *thd, int x, int y, int meth 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; diff --git a/src/window_gui.h b/src/window_gui.h index 87b7b381c..7d0a1403c 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -524,11 +524,7 @@ Wcls *AllocateWindowDescFront(const WindowDesc *desc, int window_number) 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); |