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

Function InputViewportDragContinue

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

Source from the content-addressed store, hash-verified

553 }
554
555 static void InputViewportDragContinue()
556 {
557 WindowBase* w;
558 Viewport* viewport;
559
560 auto newDragCoords = ContextGetCursorPosition();
561
562 auto differentialCoords = newDragCoords - gInputDragLast;
563 if (differentialCoords.x == 0 && differentialCoords.y == 0)
564 return;
565
566 auto* windowMgr = GetWindowManager();
567 w = windowMgr->FindByNumber(_dragWidget.windowClassification, _dragWidget.windowNumber);
568
569 // #3294: Window can be closed during a drag session, so just finish
570 // the session if the window no longer exists
571 if (w == nullptr)
572 {
573 InputViewportDragEnd();
574 return;
575 }
576
577 viewport = w->viewport;
578 if (viewport == nullptr)
579 {
580 ContextShowCursor();
581 _inputState = InputState::reset;
582 }
583 else if (differentialCoords.x != 0 || differentialCoords.y != 0)
584 {
585 if (!w->flags.has(WindowFlag::noScrolling))
586 {
587 // User dragged a scrollable viewport
588
589 // If the drag time is less than 500 the "drag" is usually interpreted as a right click.
590 // As the user moved the mouse, don't interpret it as right click in any case.
591 _ticksSinceDragStart = std::nullopt;
592
593 // applying the zoom only with negative values avoids a "deadzone" effect where small positive value round to
594 // zero.
595 const bool posX = differentialCoords.x > 0;
596 const bool posY = differentialCoords.y > 0;
597 differentialCoords.x = (viewport->zoom + 1).ApplyTo(-std::abs(differentialCoords.x));
598 differentialCoords.y = (viewport->zoom + 1).ApplyTo(-std::abs(differentialCoords.y));
599 differentialCoords.x = posX ? -differentialCoords.x : differentialCoords.x;
600 differentialCoords.y = posY ? -differentialCoords.y : differentialCoords.y;
601
602 if (Config::Get().general.invertViewportDrag)
603 {
604 w->savedViewPos -= differentialCoords;
605 }
606 else
607 {
608 w->savedViewPos += differentialCoords;
609 }
610 }
611 }
612

Callers 1

GameHandleInputMouseFunction · 0.85

Calls 9

ContextGetCursorPositionFunction · 0.85
GetWindowManagerFunction · 0.85
InputViewportDragEndFunction · 0.85
ContextShowCursorFunction · 0.85
ContextGetCursorStateFunction · 0.85
ContextSetCursorPositionFunction · 0.85
ApplyToMethod · 0.80
hasMethod · 0.65
FindByNumberMethod · 0.45

Tested by

no test coverage detected