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

Method SmallMapCenterOnCurrentPos

src/smallmap_gui.cpp:1478–1489  ·  view source on GitHub ↗

* Center the small map on the current center of the viewport. */

Source from the content-addressed store, hash-verified

1476 * Center the small map on the current center of the viewport.
1477 */
1478 void SmallMapCenterOnCurrentPos()
1479 {
1480 const Viewport &vp = *GetMainWindow()->viewport;
1481 Point viewport_center = InverseRemapCoords2(vp.virtual_left + vp.virtual_width / 2, vp.virtual_top + vp.virtual_height / 2);
1482
1483 int sub;
1484 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1485 Point sxy = this->ComputeScroll(viewport_center.x / (int)TILE_SIZE, viewport_center.y / (int)TILE_SIZE,
1486 std::max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
1487 this->SetNewScroll(sxy.x, sxy.y, sub);
1488 this->SetDirty();
1489 }
1490
1491 /**
1492 * Get the center of the given station as point on the screen in the smallmap window.

Callers 3

SmallMapWindowMethod · 0.95
OnClickMethod · 0.95
ScrollMainWindowToFunction · 0.80

Calls 6

ComputeScrollMethod · 0.95
SetNewScrollMethod · 0.95
GetMainWindowFunction · 0.85
InverseRemapCoords2Function · 0.85
SetDirtyMethod · 0.45

Tested by

no test coverage detected