From 9f18d8378174c68c3f4d5d43bde59392d0fc8a15 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 11 Jul 2022 09:44:39 -0400 Subject: [PATCH 1/5] WIP check-in --- src/DynamoCoreWpf/Controls/ZoomBorder.cs | 53 ++++++++++++++----- .../ViewModels/Core/WorkspaceViewModel.cs | 2 - 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/DynamoCoreWpf/Controls/ZoomBorder.cs b/src/DynamoCoreWpf/Controls/ZoomBorder.cs index cb9a82bd186..c45ea0e5964 100644 --- a/src/DynamoCoreWpf/Controls/ZoomBorder.cs +++ b/src/DynamoCoreWpf/Controls/ZoomBorder.cs @@ -100,29 +100,38 @@ public Point GetTranslateTransformOrigin() public void SetTranslateTransformOrigin(Point2D p) { - var tt = GetTranslateTransform(child); - tt.X = p.X; - tt.Y = p.Y; - - var st = GetScaleTransform(child); - NotifyViewSettingsChanged(tt.X, tt.Y, st.ScaleX); + var tt = GetChildTranslateTransform(); + if (tt.X != p.X || tt.Y != p.Y) + { + tt.X = p.X; + tt.Y = p.Y; + + var st = GetChildScaleTransform(); + if (child.IsMouseCaptured) + { + 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); + NotifyViewSettingsChanged(tt.X, tt.Y, zoom); + } } #region Child Events private void child_MouseWheel(object sender, MouseWheelEventArgs e) { - if (child != null) + PrintMousePosition(e); + if (child != null && !child.IsMouseCaptured) { //double zoom = e.Delta > 0 ? .1 : -.1; double zoom = e.Delta > 0 ? 1 : -1; @@ -173,6 +182,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, @@ -200,6 +215,18 @@ private void NotifyViewSettingsChanged(double x, double y, double zoom) if (handler != null) { handler(new ViewSettingsChangedEventArgs(x, y, zoom)); + var ws = DataContext as WorkspaceViewModel; + ws?.DynamoViewModel.Model.Logger.Log($"X={x}, Y={y}, zoom={zoom}"); + } + } + + private void PrintMousePosition(MouseEventArgs e) + { + if (child != null) + { + var p = e.GetPosition(child); + var ws = DataContext as WorkspaceViewModel; + // ws?.DynamoViewModel.Model.Logger.Log($"X={p.X}, Y={p.Y}"); } } diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 6c85fb1281c..32ea9287117 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -850,8 +850,6 @@ void ModelPropertyChanged(object sender, PropertyChangedEventArgs e) case "Y": break; case "Zoom": - this.OnZoomChanged(this, new ZoomEventArgs(this.Zoom)); - RaisePropertyChanged("Zoom"); break; case "IsCurrentSpace": RaisePropertyChanged("IsCurrentSpace"); From 54ad9dbf7a5ae828840650b6069673c78a891fcd Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 1 Aug 2022 11:03:57 -0400 Subject: [PATCH 2/5] Set offset fix --- src/DynamoCoreWpf/Controls/ZoomBorder.cs | 2 +- src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/Controls/ZoomBorder.cs b/src/DynamoCoreWpf/Controls/ZoomBorder.cs index c45ea0e5964..7ded3192f87 100644 --- a/src/DynamoCoreWpf/Controls/ZoomBorder.cs +++ b/src/DynamoCoreWpf/Controls/ZoomBorder.cs @@ -216,7 +216,7 @@ private void NotifyViewSettingsChanged(double x, double y, double zoom) { handler(new ViewSettingsChangedEventArgs(x, y, zoom)); var ws = DataContext as WorkspaceViewModel; - ws?.DynamoViewModel.Model.Logger.Log($"X={x}, Y={y}, zoom={zoom}"); +// ws?.DynamoViewModel.Model.Logger.Log($"X={x}, Y={y}, zoom={zoom}"); } } diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 8cc62e7d0b7..972fd167b95 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -1308,7 +1308,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; From 176647fda595d328679dde5febb1c8c3ef475e10 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 1 Aug 2022 11:12:00 -0400 Subject: [PATCH 3/5] Cleanup code --- src/DynamoCoreWpf/Controls/ZoomBorder.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/DynamoCoreWpf/Controls/ZoomBorder.cs b/src/DynamoCoreWpf/Controls/ZoomBorder.cs index 7ded3192f87..59a4d962f74 100644 --- a/src/DynamoCoreWpf/Controls/ZoomBorder.cs +++ b/src/DynamoCoreWpf/Controls/ZoomBorder.cs @@ -107,10 +107,7 @@ public void SetTranslateTransformOrigin(Point2D p) tt.Y = p.Y; var st = GetChildScaleTransform(); - if (child.IsMouseCaptured) - { - NotifyViewSettingsChanged(tt.X, tt.Y, st.ScaleX); - } + NotifyViewSettingsChanged(tt.X, tt.Y, st.ScaleX); } } @@ -130,7 +127,6 @@ public void SetZoom(double zoom) private void child_MouseWheel(object sender, MouseWheelEventArgs e) { - PrintMousePosition(e); if (child != null && !child.IsMouseCaptured) { //double zoom = e.Delta > 0 ? .1 : -.1; @@ -215,21 +211,8 @@ private void NotifyViewSettingsChanged(double x, double y, double zoom) if (handler != null) { handler(new ViewSettingsChangedEventArgs(x, y, zoom)); - var ws = DataContext as WorkspaceViewModel; -// ws?.DynamoViewModel.Model.Logger.Log($"X={x}, Y={y}, zoom={zoom}"); } } - - private void PrintMousePosition(MouseEventArgs e) - { - if (child != null) - { - var p = e.GetPosition(child); - var ws = DataContext as WorkspaceViewModel; - // ws?.DynamoViewModel.Model.Logger.Log($"X={p.X}, Y={p.Y}"); - } - } - #endregion } } From 862c4516459914baa9f600b542ab344b734310b0 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 1 Aug 2022 13:07:30 -0400 Subject: [PATCH 4/5] Revert one change. --- src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 972fd167b95..06f7d801fbd 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -850,6 +850,8 @@ void ModelPropertyChanged(object sender, PropertyChangedEventArgs e) case "Y": break; case "Zoom": + this.OnZoomChanged(this, new ZoomEventArgs(this.Zoom)); + RaisePropertyChanged("Zoom"); break; case "IsCurrentSpace": RaisePropertyChanged("IsCurrentSpace"); From 264c0af478a5049406a7d3696261fe41002da32f Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 2 Aug 2022 10:47:10 -0400 Subject: [PATCH 5/5] Use child methods --- src/DynamoCoreWpf/Controls/ZoomBorder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/Controls/ZoomBorder.cs b/src/DynamoCoreWpf/Controls/ZoomBorder.cs index 59a4d962f74..2955880b1f6 100644 --- a/src/DynamoCoreWpf/Controls/ZoomBorder.cs +++ b/src/DynamoCoreWpf/Controls/ZoomBorder.cs @@ -118,7 +118,7 @@ public void SetZoom(double zoom) { st.ScaleX = zoom; st.ScaleY = zoom; - var tt = GetTranslateTransform(child); + var tt = GetChildTranslateTransform(); NotifyViewSettingsChanged(tt.X, tt.Y, zoom); } } @@ -150,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();