FReply SVirtualJoystick::OnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& Event) { for (int32 ControlIndex = 0; ControlIndex < Controls.Num(); ControlIndex++) { FControlInfo& Control = Controls[ControlIndex]; // is this control the one captured to this pointer? if (Control.CapturedPointerIndex == Event.GetPointerIndex()) { // release and center the joystick Control.ThumbPosition = FVector2D(0, 0); Control.CapturedPointerIndex = -1; // send one more joystick update for the centering Control.bSendOneMoreEvent = true; // Pass event as unhandled if time is too short if (Control.bNeedUpdatedCenter) { Control.bNeedUpdatedCenter = false; return FReply::Unhandled(); } return FReply::Handled(); } } return FReply::Unhandled(); }
FReply SVirtualJoystick::OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& Event) { // UE_LOG(LogTemp, Log, TEXT("Pointer index: %d"), Event.GetPointerIndex()); FVector2D LocalCoord = MyGeometry.AbsoluteToLocal( Event.GetScreenSpacePosition() ); for (int32 ControlIndex = 0; ControlIndex < Controls.Num(); ControlIndex++) { FControlInfo& Control = Controls[ControlIndex]; // skip controls already in use if (Control.CapturedPointerIndex == -1) { if (PositionIsInside(Control, LocalCoord, Control.InteractionSize)) { // Align Joystick inside of Screen AlignBoxIntoScreen(LocalCoord, Control.VisualSize, MyGeometry.Size); Control.CapturedPointerIndex = Event.GetPointerIndex(); if (ActivationDelay == 0.f) { CurrentOpacity = ActiveOpacity; if (!bPreventReCenter) { Control.VisualCenter = LocalCoord; } if (HandleTouch(ControlIndex, LocalCoord, MyGeometry.Size)) // Never fail! { return FReply::Handled(); } } else { Control.bNeedUpdatedCenter = true; Control.ElapsedTime = 0.f; Control.NextCenter = LocalCoord; return FReply::Unhandled(); } } } } // CapturedPointerIndex[CapturedJoystick] = -1; return FReply::Unhandled(); }
FReply FSceneViewport::OnTouchEnded( const FGeometry& MyGeometry, const FPointerEvent& TouchEvent ) { // Start a new reply state CurrentReplyState = FReply::Handled(); UpdateCachedMousePos(MyGeometry, TouchEvent); UpdateCachedGeometry(MyGeometry); if( ViewportClient ) { // Switch to the viewport clients world before processing input FScopedConditionalWorldSwitcher WorldSwitcher( ViewportClient ); const FVector2D TouchPosition = MyGeometry.AbsoluteToLocal(TouchEvent.GetLastScreenSpacePosition()); if( !ViewportClient->InputTouch( this, TouchEvent.GetUserIndex(), TouchEvent.GetPointerIndex(), ETouchType::Ended, TouchPosition, FDateTime::Now(), TouchEvent.GetTouchpadIndex()) ) { CurrentReplyState = FReply::Unhandled(); } } return CurrentReplyState; }
FReply SVirtualJoystick::OnTouchMoved(const FGeometry& MyGeometry, const FPointerEvent& Event) { FVector2D LocalCoord = MyGeometry.AbsoluteToLocal( Event.GetScreenSpacePosition() ); for (int32 ControlIndex = 0; ControlIndex < Controls.Num(); ControlIndex++) { FControlInfo& Control = Controls[ControlIndex]; // is this control the one captured to this pointer? if (Control.CapturedPointerIndex == Event.GetPointerIndex()) { if (Control.bNeedUpdatedCenter) { return FReply::Unhandled(); } else if (HandleTouch(ControlIndex, LocalCoord, MyGeometry.Size)) { return FReply::Handled(); } } } return FReply::Unhandled(); }
int32 UKismetInputLibrary::PointerEvent_GetPointerIndex(const FPointerEvent& Input) { return Input.GetPointerIndex(); }