public Drag(AppRect dragBounds, Direction direction, DragLength dragLength) { this.dragBounds = dragBounds; dragDirection = direction; this.dragLength = dragLength; SetDragForBounds(dragDirection, dragLength); }
private void OnMouseMove(MouseEventArgs e) { if (IsDragging == false || SkipEventHandling(e)) { return; } try { ScreenPoint = MouseInternal.ScreenPosition; if (_thresholdExceeded) { OnDragMove(); } else { if (DragLength.IsGreaterThanOrClose(Threshold) == false) { return; } _thresholdExceeded = true; OnDragStarted(); } } finally { PostEventHandling(e); } }
void SetDragForBounds(Direction direction, DragLength dragLength) { // percentage of bounds to scroll centered in element float scrollPercentage; switch (dragLength) { case DragLength.Long: scrollPercentage = 0.8f; break; case DragLength.Medium: scrollPercentage = 0.5f; break; default: scrollPercentage = 0.2f; break; } if (direction == Direction.LeftToRight) { yStart = dragBounds.CenterY; yEnd = dragBounds.CenterY; float xDisplacement = (dragBounds.CenterX + (dragBounds.Width / 2)) - dragBounds.X; float insetForScroll = (xDisplacement - (xDisplacement * scrollPercentage)) / 2; xStart = dragBounds.X + insetForScroll; xEnd = (dragBounds.CenterX + (dragBounds.Width / 2)) - insetForScroll; } else if (direction == Direction.RightToLeft) { yStart = dragBounds.CenterY; yEnd = dragBounds.CenterY; float xDisplacement = (dragBounds.CenterX + (dragBounds.Width / 2)) - dragBounds.X; float insetForScroll = (xDisplacement - (xDisplacement * scrollPercentage)) / 2; xStart = (dragBounds.CenterX + (dragBounds.Width / 2)) - insetForScroll; xEnd = dragBounds.X + insetForScroll; } else if (direction == Direction.TopToBottom) { xStart = dragBounds.CenterX; xEnd = dragBounds.CenterX; float yDisplacement = (dragBounds.CenterY + (dragBounds.Height / 2)) - dragBounds.Y; float insetForScroll = (yDisplacement - (yDisplacement * scrollPercentage)) / 2; yStart = dragBounds.Y + insetForScroll; yEnd = (dragBounds.CenterY + (dragBounds.Height / 2)) - insetForScroll; } else if (direction == Direction.BottomToTop) { xStart = dragBounds.CenterX; xEnd = dragBounds.CenterX; float yDisplacement = (dragBounds.CenterY + (dragBounds.Height / 2)) - dragBounds.Y; float insetForScroll = (yDisplacement - (yDisplacement * scrollPercentage)) / 2; yStart = (dragBounds.CenterY + (dragBounds.Height / 2)) - insetForScroll; yEnd = dragBounds.Y + insetForScroll; } }