* * rct2: 0x00688972 * In: * screen_x: eax * screen_y: ebx * Out: * x: ax * y: bx * tile_element: edx ? * viewport: edi */
| 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 | * |
no test coverage detected