Skip to content

Commit

Permalink
DYN-4305: After panning, sometimes zooming doesn't zoom into the mous…
Browse files Browse the repository at this point in the history
…e position (#13095)

* WIP check-in

* Set offset fix

* Cleanup code

* Revert one change.

* Use child methods
  • Loading branch information
sm6srw authored Aug 2, 2022
1 parent a450f7a commit 99215f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/DynamoCoreWpf/Controls/ZoomBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,34 @@ public Point GetTranslateTransformOrigin()

public void SetTranslateTransformOrigin(Point2D p)
{
var tt = GetTranslateTransform(child);
tt.X = p.X;
tt.Y = p.Y;
var tt = GetChildTranslateTransform();
if (tt.X != p.X || tt.Y != p.Y)
{
tt.X = p.X;
tt.Y = p.Y;

var st = GetScaleTransform(child);
NotifyViewSettingsChanged(tt.X, tt.Y, st.ScaleX);
var st = GetChildScaleTransform();
NotifyViewSettingsChanged(tt.X, tt.Y, st.ScaleX);
}
}

public void SetZoom(double zoom)
{
var st = GetScaleTransform(child);
st.ScaleX = zoom;
st.ScaleY = zoom;

var tt = GetTranslateTransform(child);
NotifyViewSettingsChanged(tt.X, tt.Y, zoom);
var st = GetChildScaleTransform();
if (st.ScaleX != zoom || st.ScaleY != zoom)
{
st.ScaleX = zoom;
st.ScaleY = zoom;
var tt = GetChildTranslateTransform();
NotifyViewSettingsChanged(tt.X, tt.Y, zoom);
}
}

#region Child Events

private void child_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (child != null)
if (child != null && !child.IsMouseCaptured)
{
//double zoom = e.Delta > 0 ? .1 : -.1;
double zoom = e.Delta > 0 ? 1 : -1;
Expand All @@ -145,7 +150,7 @@ private void child_MouseDown(object sender, MouseButtonEventArgs e)
(e.ChangedButton == MouseButton.Middle
|| e.ChangedButton == MouseButton.Left && IsInPanMode()))
{
var tt = GetTranslateTransform(child);
var tt = GetChildTranslateTransform();
start = e.GetPosition(this);
origin = new Point(tt.X, tt.Y);
child.CaptureMouse();
Expand Down Expand Up @@ -173,6 +178,12 @@ private void child_MouseMove(object sender, MouseEventArgs e)

// Change ZoomBorder's child translation
Vector v = start - e.GetPosition(this);

if (v.Length == 0.0)
{
return;
}

SetTranslateTransformOrigin(new Point2D
{
X = origin.X - v.X,
Expand Down Expand Up @@ -202,7 +213,6 @@ private void NotifyViewSettingsChanged(double x, double y, double zoom)
handler(new ViewSettingsChangedEventArgs(x, y, zoom));
}
}

#endregion
}
}
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ private void SetCurrentOffset(object parameter)

//set the current offset without triggering
//any property change notices.
if (Model.X != p.X && Model.Y != p.Y)
if (Model.X != p.X || Model.Y != p.Y)
{
Model.X = p.X;
Model.Y = p.Y;
Expand Down

0 comments on commit 99215f1

Please sign in to comment.