private IEnumerator <object> HandleDragTask(VelocityMeter velocityMeter, float mouseProjectedPosition, DragGesture dragGesture) { if (!CanScroll || !ScrollWhenContentFits && MaxScrollPosition == 0 || ScrollBySlider) { yield break; } // Do not block scrollview on refresh gesture IsBeingRefreshed = false; IsDragging = true; float realScrollPosition = ScrollPosition; wheelScrollState = WheelScrollState.Stop; while (dragGesture.IsChanging()) { var newMouseProjectedPosition = ProjectToScrollAxisWithFrameRotation(Input.MousePosition); realScrollPosition += mouseProjectedPosition - newMouseProjectedPosition; // Round scrolling position to prevent blurring ScrollPosition = ClampScrollPositionWithinBounceZone(realScrollPosition).Round(); mouseProjectedPosition = newMouseProjectedPosition; velocityMeter.AddSample(realScrollPosition); yield return(null); } StartScrolling(InertialScrollingTask(velocityMeter.CalcVelocity())); IsDragging = false; }
private IEnumerator <object> SpinByDragTask(DragGesture dragGesture) { RaiseBeginSpin(); try { isDragging = true; var startValue = Value; var startMousePosition = Application.DesktopMousePosition; float accumulator = 0.0f; while (dragGesture.IsChanging()) { var mousePosition = Application.DesktopMousePosition; var disp = CommonWindow.Current.Display; var wrapped = false; if (Application.DesktopMousePosition.X > disp.Position.X + disp.Size.X - 5) { accumulator += disp.Position.X + disp.Size.X - 5 - startMousePosition.X; startMousePosition.X = mousePosition.X = disp.Position.X + 5; wrapped = true; } if (Application.DesktopMousePosition.X < disp.Position.X + 5) { accumulator -= startMousePosition.X - disp.Position.X - 5; startMousePosition.X = mousePosition.X = disp.Position.X + disp.Size.X - 5; wrapped = true; } if (wrapped) { Application.DesktopMousePosition = new Vector2(mousePosition.X, Application.DesktopMousePosition.Y); } var delta = (mousePosition.X - startMousePosition.X + accumulator).Round() * Step; if (Input.IsKeyPressed(Key.Shift)) { delta *= 10f; } else if (Input.IsKeyPressed(Key.Control)) { delta *= 0.1f; } if (!IsReadOnly) { Value = startValue + delta; } yield return(null); } } finally { isDragging = false; RaiseEndSpin(); } }
void Advance() { if (Thumb == null) { return; } var draggingJustBegun = false; if (GloballyEnabled && RangeMax > RangeMin) { if (dragGestureThumb.WasRecognized()) { activeDragGesture = dragGestureThumb; TryStartDrag(); draggingJustBegun = true; } else { if (clickGesture.WasBegan()) { TryStartDrag(); SetValueFromCurrentMousePosition(false); } if (clickGesture.WasRecognizedOrCanceled() && !dragGestureSlider.WasRecognized()) { TryEndDrag(); } if (dragGestureSlider.WasRecognized()) { activeDragGesture = dragGestureSlider; TryStartDrag(); dragInitialDelta = 0; dragInitialOffset = (Value - RangeMin) / (RangeMax - RangeMin); draggingJustBegun = false; } } } if (activeDragGesture?.WasEnded() ?? false) { TryEndDrag(); } if (Enabled && (activeDragGesture?.IsChanging() ?? false)) { SetValueFromCurrentMousePosition(draggingJustBegun); } InterpolateGraphicsBetweenMinAndMaxMarkers(); RefreshThumbPosition(); }
private IEnumerator <object> SpinByDragTask(DragGesture dragGesture) { RaiseBeginSpin(); try { var prevMousePos = Application.DesktopMousePosition; while (dragGesture.IsChanging()) { var disp = CommonWindow.Current.Display; var wrapped = false; if (Application.DesktopMousePosition.X > disp.Position.X + disp.Size.X - 5) { prevMousePos.X = disp.Position.X + 5; wrapped = true; } if (Application.DesktopMousePosition.X < disp.Position.X + 5) { prevMousePos.X = disp.Position.X + disp.Size.X - 5; wrapped = true; } if (wrapped) { Application.DesktopMousePosition = new Vector2(prevMousePos.X, Application.DesktopMousePosition.Y); } var delta = (Application.DesktopMousePosition.X - prevMousePos.X).Round() * Step; if (Input.IsKeyPressed(Key.Shift)) { delta *= 10f; } else if (Input.IsKeyPressed(Key.Control)) { delta *= 0.1f; } if (!IsReadOnly) { Value += delta; } prevMousePos = Application.DesktopMousePosition; yield return(null); } } finally { RaiseEndSpin(); } }