Mercurial > hg > openttd
comparison src/misc_gui.cpp @ 9781:5ab8b1b156bb draft
(svn r13922) -Codechange: Move measurement-tooltip related stuff out of the general tooltip window.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 02 Aug 2008 11:26:25 +0000 |
parents | 617fc1c2d1db |
children | f5b8e5291165 |
comparison
equal
deleted
inserted
replaced
9780:02a03f9931ed | 9781:5ab8b1b156bb |
---|---|
620 struct TooltipsWindow : public Window | 620 struct TooltipsWindow : public Window |
621 { | 621 { |
622 StringID string_id; | 622 StringID string_id; |
623 byte paramcount; | 623 byte paramcount; |
624 uint64 params[5]; | 624 uint64 params[5]; |
625 bool use_left_mouse_button; | |
625 | 626 |
626 TooltipsWindow(int x, int y, int width, int height, const Widget *widget, | 627 TooltipsWindow(int x, int y, int width, int height, const Widget *widget, |
627 StringID str, uint paramcount, const uint64 params[]) : | 628 StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) : |
628 Window(x, y, width, height, WC_TOOLTIPS, widget) | 629 Window(x, y, width, height, WC_TOOLTIPS, widget) |
629 { | 630 { |
630 this->string_id = str; | 631 this->string_id = str; |
631 assert(sizeof(this->params[0]) == sizeof(params[0])); | 632 assert(sizeof(this->params[0]) == sizeof(params[0])); |
632 memcpy(this->params, params, sizeof(this->params[0]) * paramcount); | 633 memcpy(this->params, params, sizeof(this->params[0]) * paramcount); |
633 this->paramcount = paramcount; | 634 this->paramcount = paramcount; |
635 this->use_left_mouse_button = use_left_mouse_button; | |
634 | 636 |
635 this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip | 637 this->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip |
636 this->widget[0].right = width; | 638 this->widget[0].right = width; |
637 this->widget[0].bottom = height; | 639 this->widget[0].bottom = height; |
638 | 640 |
652 | 654 |
653 virtual void OnMouseLoop() | 655 virtual void OnMouseLoop() |
654 { | 656 { |
655 /* We can show tooltips while dragging tools. These are shown as long as | 657 /* We can show tooltips while dragging tools. These are shown as long as |
656 * we are dragging the tool. Normal tooltips work with rmb */ | 658 * we are dragging the tool. Normal tooltips work with rmb */ |
657 if (this->paramcount == 0 ) { | 659 if (this->use_left_mouse_button ? !_left_button_down : !_right_button_down) delete this; |
658 if (!_right_button_down) delete this; | |
659 } else { | |
660 if (!_left_button_down) delete this; | |
661 } | |
662 } | 660 } |
663 }; | 661 }; |
664 | 662 |
665 /** Shows a tooltip | 663 /** Shows a tooltip |
666 * @param str String to be displayed | 664 * @param str String to be displayed |
667 * @param paramcount number of params to deal with | 665 * @param paramcount number of params to deal with |
668 * @param params (optional) up to 5 pieces of additional information that may be | 666 * @param params (optional) up to 5 pieces of additional information that may be added to a tooltip |
669 * added to a tooltip; currently only supports parameters of {NUM} (integer) */ | 667 * @param use_left_mouse_button close the tooltip when the left (true) or right (false) mousebutton is released |
670 void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]) | 668 */ |
669 void GuiShowTooltips(StringID str, uint paramcount, const uint64 params[], bool use_left_mouse_button) | |
671 { | 670 { |
672 DeleteWindowById(WC_TOOLTIPS, 0); | 671 DeleteWindowById(WC_TOOLTIPS, 0); |
673 | 672 |
674 /* We only show measurement tooltips with patch setting on */ | 673 if (str == STR_NULL) return; |
675 if (str == STR_NULL || (paramcount != 0 && !_settings_client.gui.measure_tooltip)) return; | |
676 | 674 |
677 for (uint i = 0; i != paramcount; i++) SetDParam(i, params[i]); | 675 for (uint i = 0; i != paramcount; i++) SetDParam(i, params[i]); |
678 char buffer[512]; | 676 char buffer[512]; |
679 GetString(buffer, str, lastof(buffer)); | 677 GetString(buffer, str, lastof(buffer)); |
680 | 678 |
692 * go below window, flip it so it is shown above the cursor */ | 690 * go below window, flip it so it is shown above the cursor */ |
693 int y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12); | 691 int y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12); |
694 if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5; | 692 if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5; |
695 int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width); | 693 int x = Clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width); |
696 | 694 |
697 new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params); | 695 new TooltipsWindow(x, y, br.width, br.height, _tooltips_widgets, str, paramcount, params, use_left_mouse_button); |
698 } | 696 } |
699 | 697 |
700 | 698 |
701 static int DrawStationCoverageText(const AcceptedCargo cargo, | 699 static int DrawStationCoverageText(const AcceptedCargo cargo, |
702 int str_x, int str_y, StationCoverageType sct, bool supplies) | 700 int str_x, int str_y, StationCoverageType sct, bool supplies) |