From 6eb75e9775f2ceefa365726bdf81b9d35964b7db Mon Sep 17 00:00:00 2001 From: XY Wang Date: Tue, 14 Nov 2023 18:48:04 +0800 Subject: [PATCH] [Add] Options to turn two finger scale, rotate and translate on and off --- Ink Canvas/MainWindow.xaml | 1 + Ink Canvas/MainWindow.xaml.cs | 45 +++++++++++++++++++++++------------ Ink Canvas/Settings.cs | 4 ++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 704a1109..5729d3f7 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -441,6 +441,7 @@ + diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 49a07ab7..4085e7b6 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -1878,9 +1878,9 @@ private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone(); } //设备两个及两个以上,将画笔功能关闭 - if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerZoom) + if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture) { - if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerZoom) return; + if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return; if (inkCanvas.EditingMode != InkCanvasEditingMode.None && inkCanvas.EditingMode != InkCanvasEditingMode.Select) { lastInkCanvasEditingMode = inkCanvas.EditingMode; @@ -1936,7 +1936,7 @@ private void Main_Grid_ManipulationCompleted(object sender, ManipulationComplete private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) { - if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerZoom) return; + if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return; if ((dec.Count >= 2 && (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode || StackPanelPPTControls.Visibility != Visibility.Visible || StackPanelPPTButtons.Visibility == Visibility.Collapsed)) || isSingleFingerDragMode) { ManipulationDelta md = e.DeltaManipulation; @@ -1952,12 +1952,12 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点 // Update matrix to reflect translation/rotation - m.Translate(trans.X, trans.Y); // 移动 + if (Settings.Gesture.IsEnableTwoFingerTranslate) + m.Translate(trans.X, trans.Y); // 移动 if (Settings.Gesture.IsEnableTwoFingerRotation) - { m.RotateAt(rotate, center.X, center.Y); // 旋转 - } - m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放 + if (Settings.Gesture.IsEnableTwoFingerZoom) + m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放 StrokeCollection strokes = inkCanvas.GetSelectedStrokes(); if (strokes.Count != 0) @@ -1977,12 +1977,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr } } - try + if (Settings.Gesture.IsEnableTwoFingerZoom) { - stroke.DrawingAttributes.Width *= md.Scale.X; - stroke.DrawingAttributes.Height *= md.Scale.Y; + try + { + stroke.DrawingAttributes.Width *= md.Scale.X; + stroke.DrawingAttributes.Height *= md.Scale.Y; + } + catch { } } - catch { } } } else @@ -1991,12 +1994,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr { stroke.Transform(m, false); - try + if (Settings.Gesture.IsEnableTwoFingerZoom) { - stroke.DrawingAttributes.Width *= md.Scale.X; - stroke.DrawingAttributes.Height *= md.Scale.Y; + try + { + stroke.DrawingAttributes.Width *= md.Scale.X; + stroke.DrawingAttributes.Height *= md.Scale.Y; + } + catch { } } - catch { } } foreach (Circle circle in circles) { @@ -3059,6 +3065,15 @@ private void ToggleSwitchEnableTwoFingerZoom_Toggled(object sender, RoutedEventA SaveSettingsToFile(); } + private void ToggleSwitchEnableTwoFingerTranslate_Toggled(object sender, RoutedEventArgs e) + { + if (!isLoaded) return; + + Settings.Gesture.IsEnableTwoFingerTranslate = ToggleSwitchEnableTwoFingerTranslate.IsOn; + + SaveSettingsToFile(); + } + private void ToggleSwitchEnableTwoFingerRotation_Toggled(object sender, RoutedEventArgs e) { if (!isLoaded) return; diff --git a/Ink Canvas/Settings.cs b/Ink Canvas/Settings.cs index 15f1ca7b..20a8e358 100644 --- a/Ink Canvas/Settings.cs +++ b/Ink Canvas/Settings.cs @@ -53,8 +53,12 @@ public enum OptionalOperation public class Gesture { + [JsonIgnore] + public bool IsEnableTwoFingerGesture => IsEnableTwoFingerZoom || IsEnableTwoFingerTranslate || IsEnableTwoFingerRotation; [JsonProperty("isEnableTwoFingerZoom")] public bool IsEnableTwoFingerZoom { get; set; } = true; + [JsonProperty("isEnableTwoFingerTranslate")] + public bool IsEnableTwoFingerTranslate { get; set; } = true; [JsonProperty("isEnableTwoFingerRotation")] public bool IsEnableTwoFingerRotation { get; set; } = false; [JsonProperty("isEnableTwoFingerRotationOnSelection")]