Skip to content

Commit 21d8a84

Browse files
authored
Merge branch 'WXRIW:master' into master
2 parents 228b687 + c054e85 commit 21d8a84

File tree

5 files changed

+92
-28
lines changed

5 files changed

+92
-28
lines changed

Ink Canvas/App.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
xmlns:ui="http://schemas.modernwpf.com/2019">
77
<Application.Resources>
88
<ResourceDictionary>
9+
<Style TargetType="ScrollViewer">
10+
11+
<EventSetter Event="PreviewMouseWheel" Handler="ScrollViewer_PreviewMouseWheel"/>
12+
13+
</Style>
914
<ResourceDictionary.MergedDictionaries>
1015
<ui:ThemeResources RequestedTheme="Light"/>
1116
<ui:XamlControlsResources />

Ink Canvas/App.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,27 @@ void App_Startup(object sender, StartupEventArgs e)
5858
};
5959
}
6060
}
61+
62+
private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
63+
{
64+
try
65+
{
66+
if (System.Windows.Forms.SystemInformation.MouseWheelScrollLines == -1)
67+
e.Handled = false;
68+
else
69+
try
70+
{
71+
System.Windows.Controls.ScrollViewer SenderScrollViewer = (System.Windows.Controls.ScrollViewer)sender;
72+
SenderScrollViewer.ScrollToVerticalOffset(SenderScrollViewer.VerticalOffset - e.Delta * 10 * System.Windows.Forms.SystemInformation.MouseWheelScrollLines / (double)120);
73+
e.Handled = true;
74+
}
75+
catch
76+
{
77+
}
78+
}
79+
catch
80+
{
81+
}
82+
}
6183
}
6284
}

Ink Canvas/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@
441441
<GroupBox Header="手势">
442442
<ui:SimpleStackPanel Spacing="12">
443443
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerZoom" Header="允许双指缩放" FontFamily="Microsoft YaHei UI" IsOn="True" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerZoom_Toggled"/>
444+
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerTranslate" Header="允许双指移动" FontFamily="Microsoft YaHei UI" IsOn="True" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerTranslate_Toggled"/>
444445
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerRotation" Header="允许双指旋转" FontFamily="Microsoft YaHei UI" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerRotation_Toggled"/>
445446
<TextBlock Text="允许选中墨迹后对墨迹进行双指或多指缩放操作(此设置不受“允许双指旋转”设置的影响)" TextWrapping="Wrap" Foreground="#666666"/>
446447
<ui:ToggleSwitch Name="ToggleSwitchEnableTwoFingerRotationOnSelection" Header="允许双指旋转选中的墨迹" FontFamily="Microsoft YaHei UI" OnContent="" OffContent="" Toggled="ToggleSwitchEnableTwoFingerRotation_Toggled"/>

Ink Canvas/MainWindow.xaml.cs

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,9 +1926,9 @@ private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e)
19261926
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
19271927
}
19281928
//设备两个及两个以上,将画笔功能关闭
1929-
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerZoom)
1929+
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture)
19301930
{
1931-
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerZoom) return;
1931+
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
19321932
if (inkCanvas.EditingMode != InkCanvasEditingMode.None && inkCanvas.EditingMode != InkCanvasEditingMode.Select)
19331933
{
19341934
lastInkCanvasEditingMode = inkCanvas.EditingMode;
@@ -1984,7 +1984,7 @@ private void Main_Grid_ManipulationCompleted(object sender, ManipulationComplete
19841984

19851985
private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
19861986
{
1987-
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerZoom) return;
1987+
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
19881988
if ((dec.Count >= 2 && (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode || StackPanelPPTControls.Visibility != Visibility.Visible || StackPanelPPTButtons.Visibility == Visibility.Collapsed)) || isSingleFingerDragMode)
19891989
{
19901990
ManipulationDelta md = e.DeltaManipulation;
@@ -2000,12 +2000,12 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr
20002000
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
20012001

20022002
// Update matrix to reflect translation/rotation
2003-
m.Translate(trans.X, trans.Y); // 移动
2003+
if (Settings.Gesture.IsEnableTwoFingerTranslate)
2004+
m.Translate(trans.X, trans.Y); // 移动
20042005
if (Settings.Gesture.IsEnableTwoFingerRotation)
2005-
{
20062006
m.RotateAt(rotate, center.X, center.Y); // 旋转
2007-
}
2008-
m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放
2007+
if (Settings.Gesture.IsEnableTwoFingerZoom)
2008+
m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放
20092009

20102010
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
20112011
if (strokes.Count != 0)
@@ -2025,12 +2025,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr
20252025
}
20262026
}
20272027

2028-
try
2028+
if (Settings.Gesture.IsEnableTwoFingerZoom)
20292029
{
2030-
stroke.DrawingAttributes.Width *= md.Scale.X;
2031-
stroke.DrawingAttributes.Height *= md.Scale.Y;
2030+
try
2031+
{
2032+
stroke.DrawingAttributes.Width *= md.Scale.X;
2033+
stroke.DrawingAttributes.Height *= md.Scale.Y;
2034+
}
2035+
catch { }
20322036
}
2033-
catch { }
20342037
}
20352038
}
20362039
else
@@ -2039,12 +2042,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr
20392042
{
20402043
stroke.Transform(m, false);
20412044

2042-
try
2045+
if (Settings.Gesture.IsEnableTwoFingerZoom)
20432046
{
2044-
stroke.DrawingAttributes.Width *= md.Scale.X;
2045-
stroke.DrawingAttributes.Height *= md.Scale.Y;
2047+
try
2048+
{
2049+
stroke.DrawingAttributes.Width *= md.Scale.X;
2050+
stroke.DrawingAttributes.Height *= md.Scale.Y;
2051+
}
2052+
catch { }
20462053
}
2047-
catch { }
20482054
}
20492055
foreach (Circle circle in circles)
20502056
{
@@ -2282,6 +2288,8 @@ private void PptApplication_SlideShowBegin(SlideShowWindow Wn)
22822288
LogHelper.WriteLogToFile("PowerPoint Application Slide Show Begin", LogHelper.LogType.Event);
22832289
Application.Current.Dispatcher.Invoke(() =>
22842290
{
2291+
// 退出画板模式
2292+
BtnSwitch_Click(null, null);
22852293
//调整颜色
22862294
double screenRatio = SystemParameters.PrimaryScreenWidth / SystemParameters.PrimaryScreenHeight;
22872295
if (Math.Abs(screenRatio - 16.0 / 9) <= -0.01)
@@ -2902,7 +2910,7 @@ private void ToggleSwitchShowCursor_Toggled(object sender, RoutedEventArgs e)
29022910
#endregion
29032911

29042912
#region Canvas
2905-
2913+
29062914
private void ComboBoxPenStyle_SelectionChanged(object sender, SelectionChangedEventArgs e)
29072915
{
29082916
if (!isLoaded) return;
@@ -3107,6 +3115,15 @@ private void ToggleSwitchEnableTwoFingerZoom_Toggled(object sender, RoutedEventA
31073115
SaveSettingsToFile();
31083116
}
31093117

3118+
private void ToggleSwitchEnableTwoFingerTranslate_Toggled(object sender, RoutedEventArgs e)
3119+
{
3120+
if (!isLoaded) return;
3121+
3122+
Settings.Gesture.IsEnableTwoFingerTranslate = ToggleSwitchEnableTwoFingerTranslate.IsOn;
3123+
3124+
SaveSettingsToFile();
3125+
}
3126+
31103127
private void ToggleSwitchEnableTwoFingerRotation_Toggled(object sender, RoutedEventArgs e)
31113128
{
31123129
if (!isLoaded) return;
@@ -4796,16 +4813,31 @@ private void MouseTouchMove(Point endP)
47964813
{
47974814
//第二笔:画双曲线
47984815
double k = drawMultiStepShapeSpecialParameter3;
4799-
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) - (endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
4800-
b = a * k;
4801-
pointList = new List<Point>();
4802-
for (double i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
4803-
{
4804-
double rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
4805-
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
4806-
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
4807-
pointList3.Add(new Point(iniP.X - i, iniP.Y - rY));
4808-
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
4816+
bool isHyperbolaFocalPointOnXAxis = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X)) < k;
4817+
if (isHyperbolaFocalPointOnXAxis) { // 焦点在 x 轴上
4818+
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) - (endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
4819+
b = a * k;
4820+
pointList = new List<Point>();
4821+
for (double i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
4822+
{
4823+
double rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
4824+
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
4825+
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
4826+
pointList3.Add(new Point(iniP.X - i, iniP.Y - rY));
4827+
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
4828+
}
4829+
} else { // 焦点在 y 轴上
4830+
a = Math.Sqrt(Math.Abs((endP.Y - iniP.Y) * (endP.Y - iniP.Y) - (endP.X - iniP.X) * (endP.X - iniP.X) * (k * k)));
4831+
b = a / k;
4832+
pointList = new List<Point>();
4833+
for (double i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5)
4834+
{
4835+
double rX = Math.Sqrt(Math.Abs(i * i / k / k - b * b));
4836+
pointList.Add(new Point(iniP.X - rX, iniP.Y + i));
4837+
pointList2.Add(new Point(iniP.X + rX, iniP.Y + i));
4838+
pointList3.Add(new Point(iniP.X - rX, iniP.Y - i));
4839+
pointList4.Add(new Point(iniP.X + rX, iniP.Y - i));
4840+
}
48094841
}
48104842
try
48114843
{
@@ -4825,12 +4857,12 @@ private void MouseTouchMove(Point endP)
48254857
{
48264858
//画焦点
48274859
c = Math.Sqrt(a * a + b * b);
4828-
stylusPoint = new StylusPoint(iniP.X + c, iniP.Y, (float)1.0);
4860+
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X + c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y + c, (float)1.0);
48294861
point = new StylusPointCollection();
48304862
point.Add(stylusPoint);
48314863
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
48324864
strokes.Add(stroke.Clone());
4833-
stylusPoint = new StylusPoint(iniP.X - c, iniP.Y, (float)1.0);
4865+
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X - c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
48344866
point = new StylusPointCollection();
48354867
point.Add(stylusPoint);
48364868
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };

Ink Canvas/Settings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ public enum OptionalOperation
5353

5454
public class Gesture
5555
{
56+
[JsonIgnore]
57+
public bool IsEnableTwoFingerGesture => IsEnableTwoFingerZoom || IsEnableTwoFingerTranslate || IsEnableTwoFingerRotation;
5658
[JsonProperty("isEnableTwoFingerZoom")]
5759
public bool IsEnableTwoFingerZoom { get; set; } = true;
60+
[JsonProperty("isEnableTwoFingerTranslate")]
61+
public bool IsEnableTwoFingerTranslate { get; set; } = true;
5862
[JsonProperty("isEnableTwoFingerRotation")]
5963
public bool IsEnableTwoFingerRotation { get; set; } = false;
6064
[JsonProperty("isEnableTwoFingerRotationOnSelection")]

0 commit comments

Comments
 (0)