MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnInitialPosition

Method OnInitialPosition

src/misc_gui.cpp:621–639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619 }
620
621 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
622 {
623 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
624 * Add a fixed distance 2 so the tooltip floats free from both bars.
625 */
626 int scr_top = GetMainViewTop() + 2;
627 int scr_bot = GetMainViewBottom() - 2;
628
629 Point pt;
630
631 /* Correctly position the tooltip position, watch out for window and cursor size
632 * Clamp value to below main toolbar and above statusbar. If tooltip would
633 * go below window, flip it so it is shown above the cursor */
634 pt.y = SoftClamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
635 if (pt.y + sm_height > scr_bot) pt.y = std::min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
636 pt.x = sm_width >= _screen.width ? 0 : SoftClamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
637
638 return pt;
639 }
640
641 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
642 {

Callers

nothing calls this directly

Calls 3

GetMainViewTopFunction · 0.85
GetMainViewBottomFunction · 0.85
SoftClampFunction · 0.85

Tested by

no test coverage detected