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

Function InputScrollViewport

src/openrct2-ui/input/MouseInput.cpp:1624–1689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1622 }
1623
1624 void InputScrollViewport(const ScreenCoordsXY& scrollScreenCoords)
1625 {
1626 WindowBase* mainWindow = WindowGetMain();
1627 if (mainWindow == nullptr)
1628 return;
1629
1630 Viewport* viewport = mainWindow->viewport;
1631 if (viewport == nullptr)
1632 return;
1633
1634 const int32_t speed = Config::Get().general.edgeScrollingSpeed;
1635
1636 int32_t multiplier = viewport->zoom.ApplyTo(speed);
1637 int32_t dx = scrollScreenCoords.x * multiplier;
1638 int32_t dy = scrollScreenCoords.y * multiplier;
1639
1640 if (scrollScreenCoords.x != 0)
1641 {
1642 // Speed up scrolling horizontally when at the edge of the map
1643 // so that the speed is consistent with vertical edge scrolling.
1644 int32_t x = mainWindow->savedViewPos.x + viewport->ViewWidth() / 2 + dx;
1645 int32_t y = mainWindow->savedViewPos.y + viewport->ViewHeight() / 2;
1646 int32_t y_dy = mainWindow->savedViewPos.y + viewport->ViewHeight() / 2 + dy;
1647
1648 auto mapCoord = ViewportPosToMapPos({ x, y }, 0, viewport->rotation);
1649 auto mapCoord_dy = ViewportPosToMapPos({ x, y_dy }, 0, viewport->rotation);
1650
1651 // Check if we're crossing the boundary
1652 // Clamp to the map minimum value
1653 int32_t at_map_edge = 0;
1654 int32_t at_map_edge_dy = 0;
1655 if (mapCoord.x < kMapMinimumXY || mapCoord.y < kMapMinimumXY)
1656 {
1657 at_map_edge = 1;
1658 }
1659 if (mapCoord_dy.x < kMapMinimumXY || mapCoord_dy.y < kMapMinimumXY)
1660 {
1661 at_map_edge_dy = 1;
1662 }
1663
1664 // Clamp to the map maximum value (scenario specific)
1665 auto mapSizeMinus2 = GetMapSizeMinus2();
1666 if (mapCoord.x > mapSizeMinus2.x || mapCoord.y > mapSizeMinus2.y)
1667 {
1668 at_map_edge = 1;
1669 }
1670 if (mapCoord_dy.x > mapSizeMinus2.x || mapCoord_dy.y > mapSizeMinus2.y)
1671 {
1672 at_map_edge_dy = 1;
1673 }
1674
1675 // If we crossed the boundary, multiply the distance by 2
1676 if (at_map_edge && at_map_edge_dy)
1677 {
1678 dx *= 2;
1679 }
1680
1681 mainWindow->savedViewPos.x += dx;

Callers 2

GameHandleEdgeScrollFunction · 0.85
handleViewScrollingMethod · 0.85

Calls 7

WindowGetMainFunction · 0.85
ViewportPosToMapPosFunction · 0.85
GetMapSizeMinus2Function · 0.85
ApplyToMethod · 0.80
ViewWidthMethod · 0.80
ViewHeightMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected