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

Method GetIndexFromPoint

src/openrct2-ui/windows/Dropdown.cpp:299–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297 }
298
299 int32_t GetIndexFromPoint(const ScreenCoordsXY& loc)
300 {
301 int32_t top = loc.y - windowPos.y - 2;
302 if (top < 0)
303 return -1;
304
305 int32_t left = loc.x - windowPos.x;
306 if (left >= width)
307 return -1;
308 left -= 2;
309 if (left < 0)
310 return -1;
311
312 int32_t columnNum = left / ItemWidth;
313 if (columnNum >= NumColumns)
314 return -1;
315
316 int32_t rowNum = top / ItemHeight;
317 if (rowNum >= NumRows)
318 return -1;
319
320 int32_t dropdownIndex;
321 if (ListVertically)
322 dropdownIndex = columnNum * NumRows + rowNum;
323 else
324 dropdownIndex = rowNum * NumColumns + columnNum;
325
326 if (dropdownIndex >= gDropdown.numItems)
327 return -1;
328
329 return dropdownIndex;
330 }
331
332 private:
333 void UpdateSizeAndPosition(const ScreenCoordsXY& screenPos, const int32_t extraY)

Callers 1

DropdownIndexFromPointFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected