FReply SPaperEditorViewport::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { TotalMouseDelta = 0; if (MouseEvent.GetEffectingButton() == EKeys::RightMouseButton) { // RIGHT BUTTON is for dragging and Context Menu. FReply ReplyState = FReply::Handled(); ReplyState.CaptureMouse( SharedThis(this) ); ReplyState.UseHighPrecisionMouseMovement( SharedThis(this) ); SoftwareCursorPosition = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ); // clear any interpolation when you manually pan //DeferredMovementTargetObject = nullptr; return ReplyState; } else if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton) { // START MARQUEE SELECTION. const FVector2D GraphMousePos = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ); Marquee.Start( GraphMousePos, FMarqueeOperation::OperationTypeFromMouseEvent(MouseEvent) ); // Trigger a selection update now so that single-clicks without a drag still select something OnSelectionChanged.ExecuteIfBound(Marquee, true); PaperViewportClient->Invalidate(); return FReply::Handled().CaptureMouse( SharedThis(this) ); } else { return FReply::Unhandled(); } }
FReply FSequencerEditTool_Movement::OnMouseMove(SWidget& OwnerWidget, const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { if (DelayedDrag.IsSet()) { const FVirtualTrackArea VirtualTrackArea = SequencerWidget.Pin()->GetVirtualTrackArea(); FReply Reply = FReply::Handled(); if (DelayedDrag->IsDragging()) { // If we're already dragging, just update the drag op if it exists if (DragOperation.IsValid()) { DragOperation->OnDrag(MouseEvent, MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()), VirtualTrackArea); } } // Otherwise we can attempt a new drag else if (DelayedDrag->AttemptDragStart(MouseEvent)) { DragOperation = CreateDrag(); if (DragOperation.IsValid()) { DragOperation->OnBeginDrag(MouseEvent, DelayedDrag->GetInitialPosition(), VirtualTrackArea); // Steal the capture, as we're now the authoritative widget in charge of a mouse-drag operation Reply.CaptureMouse(OwnerWidget.AsShared()); } } return Reply; } return FReply::Unhandled(); }
FReply FWebBrowserViewport::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { // Capture mouse on left button down so that you can drag out of the viewport FReply Reply = WebBrowserWindow->OnMouseButtonDown(MyGeometry, MouseEvent); if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton && ViewportWidget.IsValid()) { return Reply.CaptureMouse(ViewportWidget.Pin().ToSharedRef()); } return Reply; }
FReply STableViewBase::OnMouseMove( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { if( MouseEvent.IsMouseButtonDown( EKeys::RightMouseButton ) ) { const float ScrollByAmount = MouseEvent.GetCursorDelta().Y / MyGeometry.Scale; // If scrolling with the right mouse button, we need to remember how much we scrolled. // If we did not scroll at all, we will bring up the context menu when the mouse is released. AmountScrolledWhileRightMouseDown += FMath::Abs( ScrollByAmount ); // Has the mouse moved far enough with the right mouse button held down to start capturing // the mouse and dragging the view? if( IsRightClickScrolling() ) { // Make sure the active timer is registered to update the inertial scroll if (!bIsScrollingActiveTimerRegistered) { bIsScrollingActiveTimerRegistered = true; RegisterActiveTimer(0.f, FWidgetActiveTimerDelegate::CreateSP(this, &STableViewBase::UpdateInertialScroll)); } TickScrollDelta -= ScrollByAmount; const float AmountScrolled = this->ScrollBy( MyGeometry, -ScrollByAmount, AllowOverscroll ); FReply Reply = FReply::Handled(); // The mouse moved enough that we're now dragging the view. Capture the mouse // so the user does not have to stay within the bounds of the list while dragging. if(this->HasMouseCapture() == false) { Reply.CaptureMouse( AsShared() ).UseHighPrecisionMouseMovement( AsShared() ); SoftwareCursorPosition = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ); bShowSoftwareCursor = true; } // Check if the mouse has moved. if( AmountScrolled != 0 ) { SoftwareCursorPosition.Y += ScrollByAmount; } return Reply; } } return FReply::Unhandled(); }
FReply FScrollyZoomy::OnMouseMove( const TSharedRef<SWidget> MyWidget, IScrollableZoomable& ScrollableZoomable, const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { if (MouseEvent.IsMouseButtonDown(EKeys::RightMouseButton)) { // If scrolling with the right mouse button, we need to remember how much we scrolled. // If we did not scroll at all, we will bring up the context menu when the mouse is released. AmountScrolledWhileRightMouseDown += FMath::Abs( MouseEvent.GetCursorDelta().X ) + FMath::Abs( MouseEvent.GetCursorDelta().Y ); // Has the mouse moved far enough with the right mouse button held down to start capturing // the mouse and dragging the view? if (IsRightClickScrolling()) { this->HorizontalIntertia.AddScrollSample( MouseEvent.GetCursorDelta().X, FPlatformTime::Seconds() ); this->VerticalIntertia.AddScrollSample( MouseEvent.GetCursorDelta().Y, FPlatformTime::Seconds() ); const bool DidScroll = ScrollableZoomable.ScrollBy( MouseEvent.GetCursorDelta() ); FReply Reply = FReply::Handled(); // Capture the mouse if we need to if (MyWidget->HasMouseCapture() == false) { Reply.CaptureMouse( MyWidget ).UseHighPrecisionMouseMovement( MyWidget ); SoftwareCursorPosition = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ); bShowSoftwareCursor = true; } // Check if the mouse has moved. if (DidScroll) { SoftwareCursorPosition += MouseEvent.GetCursorDelta(); } return Reply; } } return FReply::Unhandled(); }
FReply FTextEditHelper::OnMouseButtonDown( const FGeometry& MyGeometry, const FPointerEvent& InMouseEvent, const TSharedRef< ITextEditorWidget >& TextEditor ) { FReply Reply = FReply::Unhandled(); // If the mouse is already captured, then don't allow a new action to be taken if( !TextEditor->GetWidget()->HasMouseCapture() ) { if( InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton || InMouseEvent.GetEffectingButton() == EKeys::RightMouseButton ) { // Am I getting focus right now? const bool bIsGettingFocus = !TextEditor->GetWidget()->HasKeyboardFocus(); if( bIsGettingFocus ) { // We might be receiving keyboard focus due to this event. Because the keyboard focus received callback // won't fire until after this function exits, we need to make sure our widget's state is in order early // Assume we'll be given keyboard focus, so load text for editing TextEditor->LoadText(); // Reset 'mouse has moved' state. We'll use this in OnMouseMove to determine whether we // should reset the selection range to the caret's position. TextEditor->SetWasFocusedByLastMouseDown( true ); } if( InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton ) { if( InMouseEvent.IsShiftDown() ) { TextEditor->MoveCursor( FMoveCursor::ViaScreenPointer( MyGeometry.AbsoluteToLocal( InMouseEvent.GetScreenSpacePosition( ) ), MyGeometry.Scale, ECursorAction::SelectText ) ); } else { // Deselect any text that was selected TextEditor->ClearSelection(); TextEditor->MoveCursor( FMoveCursor::ViaScreenPointer( MyGeometry.AbsoluteToLocal( InMouseEvent.GetScreenSpacePosition( ) ), MyGeometry.Scale, ECursorAction::MoveCursor ) ); } // Start drag selection TextEditor->BeginDragSelection(); } else if( InMouseEvent.GetEffectingButton() == EKeys::RightMouseButton ) { // If the user right clicked on a character that wasn't already selected, we'll clear // the selection if ( TextEditor->AnyTextSelected( ) && !TextEditor->IsTextSelectedAt( MyGeometry, InMouseEvent.GetScreenSpacePosition() ) ) { // Deselect any text that was selected TextEditor->ClearSelection(); } } // Right clicking to summon context menu, but we'll do that on mouse-up. Reply = FReply::Handled(); Reply.CaptureMouse( TextEditor->GetWidget() ); Reply.SetUserFocus(TextEditor->GetWidget(), EFocusCause::Mouse); } } return Reply; }