bool FCascadeEdPreviewViewportClient::InputKey(FViewport* Viewport, int32 ControllerId, FKey Key, EInputEvent Event, float AmountDepressed, bool Gamepad)
{
	//Update cursor 
	UpdateAndApplyCursorVisibility();

	bool bHandled = false;
	const int32 HitX = Viewport->GetMouseX();
	const int32 HitY = Viewport->GetMouseY();

	if(Key == EKeys::LeftMouseButton)
	{
		if (Event == IE_Pressed)
		{
			Viewport->InvalidateHitProxy();
			HHitProxy* HitResult = Viewport->GetHitProxy(HitX,HitY);
			if (HitResult && HitResult->IsA(HWidgetUtilProxy::StaticGetType()))
			{
				HWidgetUtilProxy* WidgetProxy = (HWidgetUtilProxy*)HitResult;
				if (WidgetProxy->Info1 == VectorFieldHitproxyInfo)
				{
					bManipulatingVectorField = true;
				}
				WidgetAxis = WidgetProxy->Axis;

				// Calculate the scree-space directions for this drag.
				FSceneViewFamilyContext ViewFamily( FSceneViewFamily::ConstructionValues( Viewport, GetScene(), EngineShowFlags ));
				FSceneView* View = CalcSceneView(&ViewFamily);
				WidgetProxy->CalcVectors(View, FViewportClick(View, this, Key, Event, HitX, HitY), LocalManipulateDir, WorldManipulateDir, DragX, DragY);
				bHandled = true;
			}
		}
		else if (Event == IE_Released)
		{
			if (bManipulatingVectorField)
			{
				WidgetAxis = EAxisList::None;
				bManipulatingVectorField = false;

				bHandled = true;
			}
		}
	}
	else if (Key == EKeys::SpaceBar && Event == IE_Pressed)
	{
		if (CascadePtr.Pin()->GetSelectedModule() && CascadePtr.Pin()->GetSelectedModule()->IsA(UParticleModuleVectorFieldLocal::StaticClass()))
		{
			bHandled = true;

			WidgetMM = (EWidgetMovementMode)((WidgetMM+1) % WMM_MAX);
		}
	}

	if( !bHandled )
	{
		bHandled = FEditorViewportClient::InputKey(Viewport,ControllerId,Key,Event,AmountDepressed,Gamepad);
	}


	return bHandled;
}
Пример #2
0
void FVertexSnappingImpl::GetPossibleSnapActors( const FBox& AllowedBox, FIntPoint MouseLocation, FLevelEditorViewportClient* ViewportClient, const FSceneView* View, EAxisList::Type CurrentAxis, TSet< TWeakObjectPtr<AActor> >& ActorsToIgnore, TArray<FSnapActor>& OutActorsInBox )
{
	if( CurrentAxis == EAxisList::Screen && !ViewportClient->IsOrtho() )
	{
		HHitProxy* HitProxy = ViewportClient->Viewport->GetHitProxy( MouseLocation.X, MouseLocation.Y );
		if( HitProxy && HitProxy->IsA(HActor::StaticGetType()) )
		{
			AActor* HitProxyActor = static_cast<HActor*>(HitProxy)->Actor ;
			if( HitProxyActor && !ActorsToIgnore.Contains(HitProxyActor)  )
			{
				ActorsToIgnore.Add( HitProxyActor );
				OutActorsInBox.Add( FSnapActor( HitProxyActor, HitProxyActor->GetComponentsBoundingBox(true) ) );
			}
		}
	}
				
	if( OutActorsInBox.Num() == 0 )
	{
		GetActorsInsideBox( AllowedBox, ViewportClient->GetWorld(), OutActorsInBox, ActorsToIgnore, View );
	}
}
/**
 * @return		true if the key was handled by this editor mode tool.
 */
bool FModeTool_InterpEdit::InputKey(FLevelEditorViewportClient* ViewportClient, FViewport* Viewport, FKey Key, EInputEvent Event)
{
	check( GEditorModeTools().IsModeActive(FBuiltinEditorModes::EM_InterpEdit) );

	FEdModeInterpEdit* mode = (FEdModeInterpEdit*)GEditorModeTools().GetActiveMode(FBuiltinEditorModes::EM_InterpEdit);
	if( !mode->InterpEd )
	{
		// Abort cleanly on InerpEd not yet being assigned.  This can occasionally be the case when receiving
		// modifier key release events when changing into interp edit mode.
		return false;
	}

	bool bCtrlDown = Viewport->KeyState(EKeys::LeftControl) || Viewport->KeyState(EKeys::RightControl);
	bool bAltDown = Viewport->KeyState(EKeys::LeftAlt) || Viewport->KeyState(EKeys::RightAlt);
	bool bShiftDown = Viewport->KeyState(EKeys::LeftShift) || Viewport->KeyState(EKeys::RightShift);

	if( Key == EKeys::LeftMouseButton )
	{

		if( Event == IE_Pressed)
		{
			int32 HitX = ViewportClient->Viewport->GetMouseX();
			int32 HitY = ViewportClient->Viewport->GetMouseY();
			HHitProxy*	HitResult = ViewportClient->Viewport->GetHitProxy(HitX, HitY);

			if(HitResult)
			{
				if( HitResult->IsA(HInterpTrackKeypointProxy::StaticGetType()) )
				{
					HInterpTrackKeypointProxy* KeyProxy = (HInterpTrackKeypointProxy*)HitResult;
					UInterpGroup* Group = KeyProxy->Group;
					UInterpTrack* Track = KeyProxy->Track;
					int32 KeyIndex = KeyProxy->KeyIndex;

					// Using the CTRL modifier invokes multi-select keyframe selection.
					if( bCtrlDown )
					{
						// If key is already selected, deselect the key.
						if( mode->InterpEd->KeyIsInSelection(Group, Track, KeyIndex) )
						{
							mode->InterpEd->RemoveKeyFromSelection(Group, Track, KeyIndex);
							mode->InterpEd->InvalidateTrackWindowViewports();
						}
						// Otherwise, select the key while preserving previous selection.
						else
						{
							// This will invalidate the display - so we must not access the KeyProxy after this!
							mode->InterpEd->SelectTrack( Group, Track, false);
							mode->InterpEd->AddKeyToSelection(Group, Track, KeyIndex, !bShiftDown);
						}
					}
					else
					{
						mode->InterpEd->SelectTrack( Group, Track );
						// NOTE: Clear previously-selected tracks because ctrl is not down. 
						mode->InterpEd->ClearKeySelection();
						mode->InterpEd->AddKeyToSelection(Group, Track, KeyIndex, !bShiftDown);
					}
				}
				else if( HitResult->IsA(HInterpTrackKeyHandleProxy::StaticGetType()) )
				{
					// If we clicked on a 3D track handle, remember which key.
					HInterpTrackKeyHandleProxy* KeyProxy = (HInterpTrackKeyHandleProxy*)HitResult;
					DragGroup = KeyProxy->Group;
					DragTrackIndex = KeyProxy->TrackIndex;
					DragKeyIndex = KeyProxy->KeyIndex;
					bDragArriving = KeyProxy->bArriving;

					bMovingHandle = true;

					mode->InterpEd->BeginDrag3DHandle(DragGroup, DragTrackIndex);
				}
			}
		}
		else if( Event == IE_Released)
		{
			if(bMovingHandle)
			{
				mode->InterpEd->EndDrag3DHandle();
				bMovingHandle = false;
			}
		}
	}

	// Handle keys
	if( Event == IE_Pressed )
	{
		if( Key == EKeys::Delete )
		{
			// Swallow 'Delete' key to avoid deleting stuff when trying to interpolate it!
			return true;
		}
		else if( mode->InterpEd->ProcessKeyPress( Key, bCtrlDown, bAltDown ) )
		{
			return true;
		}
	}

	return FModeTool::InputKey(ViewportClient, Viewport, Key, Event);
}
Пример #4
0
/**
 * Begin tracking at the specified location for the specified viewport.
 */
void FMouseDeltaTracker::StartTracking(FEditorViewportClient* InViewportClient, const int32 InX, const int32 InY, const FInputEventState& InInputState, bool bNudge, bool bResetDragToolState)
{
	DetermineCurrentAxis(InViewportClient);

	// Initialize widget axis (in case it hasn't been set by the hovered hit proxy)

	if (InViewportClient->Widget && InViewportClient->GetCurrentWidgetAxis() == EAxisList::None)
	{
		check(InViewportClient->Viewport);
		HHitProxy* HitProxy = InViewportClient->Viewport->GetHitProxy(InX, InY);
		if (HitProxy && HitProxy->IsA(HWidgetAxis::StaticGetType()))
		{
			EAxisList::Type ProxyAxis = ((HWidgetAxis*)HitProxy)->Axis;
			InViewportClient->SetCurrentWidgetAxis(ProxyAxis);
		}
	}

	const bool AltDown = InViewportClient->IsAltPressed();
	const bool ShiftDown = InViewportClient->IsShiftPressed();
	const bool ControlDown = InViewportClient->IsCtrlPressed();
	const bool LeftMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::LeftMouseButton);
	const bool RightMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::RightMouseButton);
	const bool MiddleMouseButtonDown = InViewportClient->Viewport->KeyState(EKeys::MiddleMouseButton);

	bool bIsDragging = ((ControlDown || ShiftDown) && (LeftMouseButtonDown || RightMouseButtonDown || MiddleMouseButtonDown)) ||
		(InViewportClient->GetCurrentWidgetAxis() != EAxisList::None) || bNudge;

	// Update bWidgetAxisControlledByDrag since we now know that we have begun dragging an object with the mouse.
	if ( bIsDragging )
	{
		InViewportClient->bWidgetAxisControlledByDrag = true;
	}

	InViewportClient->TrackingStarted( InInputState, bIsDragging, bNudge );

	if (InViewportClient->Widget)
	{
		InViewportClient->Widget->SetDragStartPosition(FVector2D(InX, InY));
		InViewportClient->Widget->SetDragging(bIsDragging);
		if (InViewportClient->GetWidgetMode() == FWidget::WM_Rotate)
		{
			InViewportClient->Invalidate();
		}
	}

	// Clear bool that tracks whether AddDelta has been called
	bHasReceivedAddDelta = false;

	if( bResetDragToolState )
	{
		bHasAttemptedDragTool = false;
	}


	ensure( !DragTool.IsValid() );

	StartSnapped = Start = StartScreen = FVector( InX, InY, 0 );
	RawDelta = FVector::ZeroVector;
	TrackingWidgetMode = InViewportClient->GetWidgetMode();

	// No drag tool is active, so handle snapping.
	switch( TrackingWidgetMode )
	{
		case FWidget::WM_Translate:
			FSnappingUtils::SnapPointToGrid( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		case FWidget::WM_Scale:
			FSnappingUtils::SnapScale( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		case FWidget::WM_Rotate:
		{
			FRotator Rotation( StartSnapped.X, StartSnapped.Y, StartSnapped.Z );
			FSnappingUtils::SnapRotatorToGrid( Rotation );
			StartSnapped = FVector( Rotation.Pitch, Rotation.Yaw, Rotation.Roll );
		}
		break;
		case FWidget::WM_TranslateRotateZ:
		case FWidget::WM_2D:
			FSnappingUtils::SnapPointToGrid( StartSnapped, FVector(GEditor->GetGridSize(),GEditor->GetGridSize(),GEditor->GetGridSize()) );
			break;

		default:
			break;
	}

	// Clear any snapping helpers on new movement
	const bool bClearImmediatley = true;
	FSnappingUtils::ClearSnappingHelpers( bClearImmediatley );

	End = EndScreen = Start;
	EndSnapped = StartSnapped;

	bExternalMovement = false;	//no external movement has occurred yet.
	InViewportClient->Widget->ResetDeltaRotation();

}