Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsashah45 committed Oct 23, 2024
1 parent beb4d12 commit 2fb035e
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,11 @@ private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
if (_capturedPointerContext is { } context)
{
var position = e.GetCurrentPoint(this).Position;
var delta = context.Position - position;
var delta = new Point(context.Position.X - position.X, context.Position.Y - position.Y);
delta.X *= -1;

SetScrollValue(context.ScrollOffset + delta);
var newScrollOffset = new Point(context.ScrollOffset.X + delta.X, context.ScrollOffset.Y + delta.Y);
SetScrollValue(newScrollOffset);
}
}

Expand All @@ -306,7 +307,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
#if IS_WINUI
p.PointerDeviceType != PointerDeviceType.Mouse
#else
p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse
p.PointerDevice.PointerDeviceType != PointerDeviceType.Mouse
#endif
) return;

Expand All @@ -315,16 +316,21 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (!IsZoomAllowed) return;

var oldPosition = (p.Position - vp.ActualSize.ToPoint().DivideBy(2)) - ScrollValue.MultiplyBy(1, -1);
var basePosition = oldPosition.DivideBy(ZoomLevel);
var oldPositionX = p.Position.X - (vp.ActualSize.X / 2) - ScrollValue.X * 1;
var oldPositionY = p.Position.Y - (vp.ActualSize.Y / 2) - ScrollValue.Y * (-1);
var oldPosition = new Point(oldPositionX, oldPositionY);

var basePosition = new Point(oldPosition.X / ZoomLevel, oldPosition.Y / ZoomLevel);

var newZoom = ZoomLevel * (1 + p.Properties.MouseWheelDelta * ScaleWheelRatio);
//var newZoom = ZoomLevel + Math.Sign(p.Properties.MouseWheelDelta);
newZoom = Math.Clamp(newZoom, MinZoomLevel, MaxZoomLevel);

var newPosition = basePosition.MultiplyBy(newZoom);
var delta = (newPosition - oldPosition).MultiplyBy(-1, 1);
var offset = ScrollValue + delta;
var newPosition = new Point(basePosition.X * newZoom, basePosition.Y * newZoom);
var deltaX = newPosition.X - oldPosition.X;
var deltaY = newPosition.Y - oldPosition.Y;
var delta = new Point(deltaX * -1, deltaY * 1);
var offset = new Point(ScrollValue.X + delta.X, ScrollValue.Y + delta.Y);

// note: updating ZoomLevel can have side effects on ScrollValue:
// ZoomLevel --UpdateScrollBars-> ScrollBar.Maximum --clamp-> ScrollBar.Value --bound-> H/VScrollValue
Expand All @@ -342,7 +348,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
var delta = e.KeyModifiers.HasFlag(Windows.System.VirtualKeyModifiers.Shift)
? new Point(magnitude, 0)
: new Point(0, -magnitude);
var offset = ScrollValue + delta;
var offset = new Point(ScrollValue.X + delta.X, ScrollValue.Y + delta.Y);

SetScrollValue(offset);
e.Handled = true;
Expand Down

0 comments on commit 2fb035e

Please sign in to comment.