void SSlider::OnFocusLost(const FFocusEvent& InFocusEvent) { if (bControllerInputCaptured) { // Commit and reset state CommitValue(ValueAttribute.Get()); ResetControllerState(); } }
FReply SSlider::OnMouseMove( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { if (this->HasMouseCapture() && !IsLocked()) { SetCursor((Orientation == Orient_Horizontal) ? EMouseCursor::ResizeLeftRight : EMouseCursor::ResizeUpDown); CommitValue(PositionToValue(MyGeometry, MouseEvent.GetLastScreenSpacePosition())); // Release capture for controller/keyboard when switching to mouse ResetControllerState(); return FReply::Handled(); } return FReply::Unhandled(); }
FReply SSlider::OnMouseButtonDown( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { if ((MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton) && !IsLocked()) { OnMouseCaptureBegin.ExecuteIfBound(); CommitValue(PositionToValue(MyGeometry, MouseEvent.GetLastScreenSpacePosition())); // Release capture for controller/keyboard when switching to mouse. ResetControllerState(); return FReply::Handled().CaptureMouse(SharedThis(this)); } return FReply::Unhandled(); }
FReply SScrubWidget::OnMouseButtonUp( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { bool bHandleLeftMouseButton = MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton && this->HasMouseCapture(); bool bHandleRightMouseButton = MouseEvent.GetEffectingButton() == EKeys::RightMouseButton && this->HasMouseCapture() && bAllowZoom; if ( bHandleRightMouseButton ) { bPanning = false; FTrackScaleInfo TimeScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); FVector2D CursorPos = MyGeometry.AbsoluteToLocal(MouseEvent.GetLastScreenSpacePosition()); float NewValue = TimeScaleInfo.LocalXToInput(CursorPos.X); if( !bMouseMovedDuringPanning ) { CreateContextMenu(NewValue, MouseEvent); } return FReply::Handled().ReleaseMouseCapture(); } else if ( bHandleLeftMouseButton ) { if(DraggingBar) { DraggingBar = false; } else if( bDragging ) { OnEndSliderMovement.ExecuteIfBound( ValueAttribute.Get() ); } else { FTrackScaleInfo TimeScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); FVector2D CursorPos = MyGeometry.AbsoluteToLocal(MouseEvent.GetLastScreenSpacePosition()); float NewValue = TimeScaleInfo.LocalXToInput(CursorPos.X); CommitValue( NewValue, true, false ); } bDragging = false; return FReply::Handled().ReleaseMouseCapture(); } return FReply::Unhandled(); }
FReply SScrubWidget::OnMouseMove( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { // Bar Dragging if(DraggingBar) { // Update bar if we are dragging FVector2D CursorPos = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ); FTrackScaleInfo ScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); float NewDataPos = FMath::Clamp( ScaleInfo.LocalXToInput(CursorPos.X), ViewInputMin.Get(), ViewInputMax.Get() ); OnBarDrag.ExecuteIfBound(DraggableBarIndex, NewDataPos); } else { // Update what bar we are hovering over FVector2D CursorPos = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()); FTrackScaleInfo ScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); DraggableBarIndex = INDEX_NONE; if ( DraggableBars.IsBound() ) { const TArray<float>& DraggableBarsVal = DraggableBars.Get(); for ( int32 I=0; I < DraggableBarsVal.Num(); I++ ) { if( FMath::Abs( ScaleInfo.InputToLocalX(DraggableBarsVal[I]) - CursorPos.X ) < 10 ) { DraggableBarIndex = I; break; } } } } if ( this->HasMouseCapture() ) { if (MouseEvent.IsMouseButtonDown( EKeys::RightMouseButton ) && bPanning) { FTrackScaleInfo ScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); FVector2D ScreenDelta = MouseEvent.GetCursorDelta(); float InputDeltaX = ScreenDelta.X/ScaleInfo.PixelsPerInput; bMouseMovedDuringPanning |= !ScreenDelta.IsNearlyZero(0.001f); float NewViewInputMin = ViewInputMin.Get() - InputDeltaX; float NewViewInputMax = ViewInputMax.Get() - InputDeltaX; // we'd like to keep the range if outside when panning if ( NewViewInputMin < 0.f ) { NewViewInputMin = 0.f; NewViewInputMax = ScaleInfo.ViewInputRange; } else if ( NewViewInputMax > SequenceLength.Get() ) { NewViewInputMax = SequenceLength.Get(); NewViewInputMin = NewViewInputMax - ScaleInfo.ViewInputRange; } OnSetInputViewRange.ExecuteIfBound(NewViewInputMin, NewViewInputMax); } else if (!bDragging) { DistanceDragged += FMath::Abs(MouseEvent.GetCursorDelta().X); if ( DistanceDragged > FSlateApplication::Get().GetDragTriggerDistance() ) { bDragging = true; } if( bDragging ) { OnBeginSliderMovement.ExecuteIfBound(); } } else if (bDragging) { FTrackScaleInfo TimeScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0.f, 0.f, MyGeometry.Size); FVector2D CursorPos = MyGeometry.AbsoluteToLocal(MouseEvent.GetLastScreenSpacePosition()); float NewValue = TimeScaleInfo.LocalXToInput(CursorPos.X); CommitValue( NewValue, true, false ); } return FReply::Handled(); } return FReply::Unhandled(); }
FReply SSlider::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) { FReply Reply = FReply::Unhandled(); const FKey KeyPressed = InKeyEvent.GetKey(); if (IsInteractable()) { // The controller's bottom face button must be pressed once to begin manipulating the slider's value. // Navigation away from the widget is prevented until the button has been pressed again or focus is lost. // The value can be manipulated by using the game pad's directional arrows ( relative to slider orientation ). if (KeyPressed == EKeys::Enter || KeyPressed == EKeys::SpaceBar || KeyPressed == EKeys::Gamepad_FaceButton_Bottom) { if (bControllerInputCaptured == false) { // Begin capturing controller input and allow user to modify the slider's value. bControllerInputCaptured = true; OnControllerCaptureBegin.ExecuteIfBound(); Reply = FReply::Handled(); } else { ResetControllerState(); Reply = FReply::Handled(); } } if (bControllerInputCaptured) { float NewValue = ValueAttribute.Get(); if (Orientation == EOrientation::Orient_Horizontal) { if (KeyPressed == EKeys::Left || KeyPressed == EKeys::Gamepad_DPad_Left || KeyPressed == EKeys::Gamepad_LeftStick_Left) { NewValue -= StepSize.Get(); } else if (KeyPressed == EKeys::Right || KeyPressed == EKeys::Gamepad_DPad_Right || KeyPressed == EKeys::Gamepad_LeftStick_Right) { NewValue += StepSize.Get(); } } else { if (KeyPressed == EKeys::Down || KeyPressed == EKeys::Gamepad_DPad_Down || KeyPressed == EKeys::Gamepad_LeftStick_Down) { NewValue -= StepSize.Get(); } else if (KeyPressed == EKeys::Up || KeyPressed == EKeys::Gamepad_DPad_Up || KeyPressed == EKeys::Gamepad_LeftStick_Up) { NewValue += StepSize.Get(); } } CommitValue(FMath::Clamp(NewValue, 0.0f, 1.0f)); Reply = FReply::Handled(); } else { Reply = SLeafWidget::OnKeyDown(MyGeometry, InKeyEvent); } } else { Reply = SLeafWidget::OnKeyDown(MyGeometry, InKeyEvent); } return Reply; }