Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-4305: After panning, sometimes zooming doesn't zoom into the mouse position #13095

Merged
merged 7 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping code that stops propagation if nothing has changed.

{
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 = GetTranslateTransform(child);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetChildTranslateTransform() ?
I saw you used this method at line 103

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, could be used here. I may do a pass and use the child version of these methods.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not allow zoom if middle button is down. This caused zoom to jump.

{
//double zoom = e.Delta > 0 ? .1 : -.1;
double zoom = e.Delta > 0 ? 1 : -1;
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)
Copy link
Contributor

@pinzart90 pinzart90 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a tolerance ? I guess it does not matter that much...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of it but the values I have seen here have been 0,1,2 etc and 0 has been 0 in those cases. So I think this is good enough.

{
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the second bug. Zoom jumped if only X or Y changed during pan.

{
Model.X = p.X;
Model.Y = p.Y;
Expand Down