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

Function ViewportRotateSingleInternal

src/openrct2/interface/Viewport.cpp:751–791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749 }
750
751 static void ViewportRotateSingleInternal(WindowBase& w, int32_t direction)
752 {
753 auto* viewport = w.viewport;
754 if (viewport == nullptr)
755 return;
756
757 auto windowPos = ScreenCoordsXY{ (viewport->width >> 1), (viewport->height >> 1) } + viewport->pos;
758
759 // has something to do with checking if middle of the viewport is obstructed
760 Viewport* other;
761 auto mapXYCoords = ScreenGetMapXY(windowPos, &other);
762 CoordsXYZ coords{};
763
764 // other != viewport probably triggers on viewports in ride or guest window?
765 // mapXYCoords is nullopt if middle of viewport is obstructed by another window?
766 if (!mapXYCoords.has_value() || other != viewport)
767 {
768 auto viewPos = ScreenCoordsXY{ (viewport->ViewWidth() >> 1), (viewport->ViewHeight() >> 1) } + viewport->viewPos;
769
770 coords = ViewportAdjustForMapHeight(viewPos, viewport->rotation);
771 }
772 else
773 {
774 coords.x = mapXYCoords->x;
775 coords.y = mapXYCoords->y;
776 coords.z = TileElementHeight(coords);
777 }
778
779 viewport->rotation = (viewport->rotation + direction) & 3;
780
781 auto centreLoc = centre2dCoordinates(coords, viewport);
782
783 if (centreLoc.has_value())
784 {
785 w.savedViewPos = centreLoc.value();
786 viewport->viewPos = *centreLoc;
787 }
788
789 w.invalidate();
790 w.onViewportRotate();
791 }
792
793 void ViewportRotateSingle(WindowBase* window, int32_t direction)
794 {

Callers 2

ViewportRotateSingleFunction · 0.85
ViewportRotateAllFunction · 0.85

Calls 9

ScreenGetMapXYFunction · 0.85
TileElementHeightFunction · 0.85
centre2dCoordinatesFunction · 0.85
ViewWidthMethod · 0.80
ViewHeightMethod · 0.80
valueMethod · 0.80
invalidateMethod · 0.45
onViewportRotateMethod · 0.45

Tested by

no test coverage detected