MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / viewportZoomSet

Method viewportZoomSet

src/OpenLoco/src/Ui/Window.cpp:645–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

643 }
644
645 void Window::viewportZoomSet(int8_t zoomLevel, bool toCursor)
646 {
647 Viewport* v = this->viewports[0];
648 ViewportConfig* vc = &this->viewportConfigurations[0];
649
650 zoomLevel = std::clamp<int8_t>(zoomLevel, 0, 3);
651 if (v->zoom == zoomLevel)
652 {
653 return;
654 }
655
656 const auto previousZoomLevel = v->zoom;
657
658 // Zoom in
659 while (v->zoom > zoomLevel)
660 {
661 v->zoom--;
662 vc->savedViewX += v->viewWidth / 4;
663 vc->savedViewY += v->viewHeight / 4;
664 v->viewWidth /= 2;
665 v->viewHeight /= 2;
666 }
667
668 // Zoom out
669 while (v->zoom < zoomLevel)
670 {
671 v->zoom++;
672 vc->savedViewX -= v->viewWidth / 2;
673 vc->savedViewY -= v->viewHeight / 2;
674 v->viewWidth *= 2;
675 v->viewHeight *= 2;
676 }
677
678 if (toCursor && Config::get().zoomToCursor)
679 {
680 const auto mouseCoords = Ui::getCursorPosScaled() - Point(v->x, v->y);
681 const int32_t diffX = mouseCoords.x - ((v->viewWidth >> zoomLevel) / 2);
682 const int32_t diffY = mouseCoords.y - ((v->viewHeight >> zoomLevel) / 2);
683 if (previousZoomLevel > zoomLevel)
684 {
685 vc->savedViewX += diffX << zoomLevel;
686 vc->savedViewY += diffY << zoomLevel;
687 }
688 else
689 {
690 vc->savedViewX -= diffX << previousZoomLevel;
691 vc->savedViewY -= diffY << previousZoomLevel;
692 }
693 }
694
695 v->viewX = vc->savedViewX;
696 v->viewY = vc->savedViewY;
697
698 this->invalidate();
699 }
700
701 // 0x0045EFDB
702 void Window::viewportZoomIn(bool toCursor)

Callers 2

viewportZoomInMethod · 0.95
viewportZoomOutMethod · 0.95

Calls 3

invalidateMethod · 0.95
getCursorPosScaledFunction · 0.85
getFunction · 0.70

Tested by

no test coverage detected