Skip to content

Commit

Permalink
[Add] Options to turn two finger scale, rotate and translate on and off
Browse files Browse the repository at this point in the history
  • Loading branch information
WXRIW committed Nov 14, 2023
1 parent 40a4b99 commit 6eb75e9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions Ink Canvas/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
<GroupBox Header="手势">
<ui:SimpleStackPanel Spacing="12">
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerZoom" Header="允许双指缩放" FontFamily="Microsoft YaHei UI" IsOn="True" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerZoom_Toggled"/>
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerTranslate" Header="允许双指移动" FontFamily="Microsoft YaHei UI" IsOn="True" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerTranslate_Toggled"/>
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerRotation" Header="允许双指旋转" FontFamily="Microsoft YaHei UI" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerRotation_Toggled"/>
<TextBlock Text="允许选中墨迹后对墨迹进行双指或多指缩放操作(此设置不受“允许双指旋转”设置的影响)" TextWrapping="Wrap" Foreground="#666666"/>
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerRotationOnSelection" Header="允许双指旋转选中的墨迹" FontFamily="Microsoft YaHei UI" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerRotation_Toggled"/>
Expand Down
45 changes: 30 additions & 15 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Ink Canvas/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 6eb75e9

Please sign in to comment.