MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ScreenGetMapXY

Function ScreenGetMapXY

src/openrct2/interface/Viewport.cpp:1811–1844  ·  view source on GitHub ↗

* * rct2: 0x00688972 * In: * screen_x: eax * screen_y: ebx * Out: * x: ax * y: bx * tile_element: edx ? * viewport: edi */

Source from the content-addressed store, hash-verified

1809 * viewport: edi
1810 */
1811 std::optional<CoordsXY> ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewport** viewport)
1812 {
1813 auto* windowMgr = Ui::GetWindowManager();
1814
1815 // This will get the tile location but we will need the more accuracy
1816 WindowBase* window = windowMgr->FindFromPoint(screenCoords);
1817 if (window == nullptr || window->viewport == nullptr)
1818 {
1819 return std::nullopt;
1820 }
1821 auto myViewport = window->viewport;
1822 auto info = GetMapCoordinatesFromPosWindow(window, screenCoords, EnumsToFlags(ViewportInteractionItem::terrain));
1823 if (info.interactionType == ViewportInteractionItem::none)
1824 {
1825 return std::nullopt;
1826 }
1827
1828 auto start_vp_pos = myViewport->ScreenToViewportCoord(screenCoords);
1829 CoordsXY cursorMapPos = info.Loc.ToTileCentre();
1830
1831 // Iterates the cursor location to work out exactly where on the tile it is
1832 for (int32_t i = 0; i < 5; i++)
1833 {
1834 int32_t z = TileElementHeight(cursorMapPos);
1835 cursorMapPos = ViewportPosToMapPos(start_vp_pos, z, myViewport->rotation);
1836 cursorMapPos.x = std::clamp(cursorMapPos.x, info.Loc.x, info.Loc.x + 31);
1837 cursorMapPos.y = std::clamp(cursorMapPos.y, info.Loc.y, info.Loc.y + 31);
1838 }
1839
1840 if (viewport != nullptr)
1841 *viewport = myViewport;
1842
1843 return cursorMapPos;
1844 }
1845
1846 /**
1847 *

Callers 7

ScreenPosToMapPosFunction · 0.85
ScreenGetMapXYQuadrantFunction · 0.85
ScreenGetMapXYSideFunction · 0.85
CreateMethod · 0.85
ToolUpdateLandPaintMethod · 0.85

Calls 8

GetWindowManagerFunction · 0.85
EnumsToFlagsFunction · 0.85
TileElementHeightFunction · 0.85
ViewportPosToMapPosFunction · 0.85
ScreenToViewportCoordMethod · 0.80
FindFromPointMethod · 0.45
ToTileCentreMethod · 0.45

Tested by

no test coverage detected