[update] 跟随ica更新旧版手势橡皮

This commit is contained in:
Dubi906w 2024-08-15 20:03:07 +08:00
parent 22efc05e86
commit 54a5c5de72
5 changed files with 1246 additions and 1150 deletions

File diff suppressed because one or more lines are too long

View File

@ -1864,12 +1864,6 @@ namespace Ink_Canvas {
SaveSettingsToFile(); SaveSettingsToFile();
} }
private void ToggleSwitchEraserBindTouchMultiplier_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Advanced.EraserBindTouchMultiplier = ToggleSwitchEraserBindTouchMultiplier.IsOn;
SaveSettingsToFile();
}
private void NibModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { private void NibModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
if (!isLoaded) return; if (!isLoaded) return;
Settings.Advanced.NibModeBoundsWidth = (int)e.NewValue; Settings.Advanced.NibModeBoundsWidth = (int)e.NewValue;
@ -1894,6 +1888,34 @@ namespace Ink_Canvas {
SaveSettingsToFile(); SaveSettingsToFile();
} }
private void NibModeBoundsWidthThresholdValueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!isLoaded) return;
Settings.Advanced.NibModeBoundsWidthThresholdValue = (double)e.NewValue;
SaveSettingsToFile();
}
private void FingerModeBoundsWidthThresholdValueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!isLoaded) return;
Settings.Advanced.FingerModeBoundsWidthThresholdValue = (double)e.NewValue;
SaveSettingsToFile();
}
private void NibModeBoundsWidthEraserSizeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!isLoaded) return;
Settings.Advanced.NibModeBoundsWidthEraserSize = (double)e.NewValue;
SaveSettingsToFile();
}
private void FingerModeBoundsWidthEraserSizeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!isLoaded) return;
Settings.Advanced.FingerModeBoundsWidthEraserSize = (double)e.NewValue;
SaveSettingsToFile();
}
private void ToggleSwitchIsQuadIR_Toggled(object sender, RoutedEventArgs e) { private void ToggleSwitchIsQuadIR_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return; if (!isLoaded) return;
Settings.Advanced.IsQuadIR = ToggleSwitchIsQuadIR.IsOn; Settings.Advanced.IsQuadIR = ToggleSwitchIsQuadIR.IsOn;

View File

@ -680,9 +680,12 @@ namespace Ink_Canvas {
TouchMultiplierSlider.Value = Settings.Advanced.TouchMultiplier; TouchMultiplierSlider.Value = Settings.Advanced.TouchMultiplier;
FingerModeBoundsWidthSlider.Value = Settings.Advanced.FingerModeBoundsWidth; FingerModeBoundsWidthSlider.Value = Settings.Advanced.FingerModeBoundsWidth;
NibModeBoundsWidthSlider.Value = Settings.Advanced.NibModeBoundsWidth; NibModeBoundsWidthSlider.Value = Settings.Advanced.NibModeBoundsWidth;
ToggleSwitchIsLogEnabled.IsOn = Settings.Advanced.IsLogEnabled; FingerModeBoundsWidthThresholdValueSlider.Value = Settings.Advanced.FingerModeBoundsWidthThresholdValue;
NibModeBoundsWidthThresholdValueSlider.Value = Settings.Advanced.NibModeBoundsWidthThresholdValue;
FingerModeBoundsWidthEraserSizeSlider.Value = Settings.Advanced.FingerModeBoundsWidthEraserSize;
NibModeBoundsWidthEraserSizeSlider.Value = Settings.Advanced.NibModeBoundsWidthEraserSize;
ToggleSwitchEraserBindTouchMultiplier.IsOn = Settings.Advanced.EraserBindTouchMultiplier; ToggleSwitchIsLogEnabled.IsOn = Settings.Advanced.IsLogEnabled;
ToggleSwitchIsSpecialScreen.IsOn = Settings.Advanced.IsSpecialScreen; ToggleSwitchIsSpecialScreen.IsOn = Settings.Advanced.IsSpecialScreen;

View File

@ -27,8 +27,7 @@ namespace Ink_Canvas {
inkCanvas.EditingMode = InkCanvasEditingMode.Ink; inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.Children.Clear(); inkCanvas.Children.Clear();
isInMultiTouchMode = false; isInMultiTouchMode = false;
} } else {
else {
inkCanvas.StylusDown += MainWindow_StylusDown; inkCanvas.StylusDown += MainWindow_StylusDown;
inkCanvas.StylusMove += MainWindow_StylusMove; inkCanvas.StylusMove += MainWindow_StylusMove;
inkCanvas.StylusUp += MainWindow_StylusUp; inkCanvas.StylusUp += MainWindow_StylusUp;
@ -41,7 +40,6 @@ namespace Ink_Canvas {
} }
private void MainWindow_TouchDown(object sender, TouchEventArgs e) { private void MainWindow_TouchDown(object sender, TouchEventArgs e) {
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice) { if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice) {
System.Windows.Forms.Cursor.Hide(); System.Windows.Forms.Cursor.Hide();
isCursorHidden = true; isCursorHidden = true;
@ -58,49 +56,43 @@ namespace Ink_Canvas {
// 不禁用手势橡皮 // 不禁用手势橡皮
if (!Settings.Gesture.DisableGestureEraser) { if (!Settings.Gesture.DisableGestureEraser) {
double boundWidth = e.GetTouchPoint(null).Bounds.Width, eraserMultiplier = 1.0; double boundWidth = e.GetTouchPoint(null).Bounds.Width;
if (!Settings.Advanced.EraserBindTouchMultiplier && Settings.Advanced.IsSpecialScreen) if ((Settings.Advanced.TouchMultiplier != 0 ||
eraserMultiplier = 1 / Settings.Advanced.TouchMultiplier; !Settings.Advanced.IsSpecialScreen) //启用特殊屏幕且触摸倍数为 0 时禁用橡皮
&& (boundWidth > BoundsWidth)) {
if ((Settings.Advanced.TouchMultiplier != 0 || !Settings.Advanced.IsSpecialScreen) //启用特殊屏幕且触摸倍数为 0 时禁用橡皮
&& boundWidth > BoundsWidth * 2.5) {
if (drawingShapeMode == 0 && forceEraser) return; if (drawingShapeMode == 0 && forceEraser) return;
double k = 1; double EraserThresholdValue = Settings.Startup.IsEnableNibMode
switch (Settings.Canvas.EraserSize) { ? Settings.Advanced.NibModeBoundsWidthThresholdValue
case 0: : Settings.Advanced.FingerModeBoundsWidthThresholdValue;
k = 0.5; if (boundWidth > BoundsWidth * EraserThresholdValue) {
break; boundWidth *= (Settings.Startup.IsEnableNibMode
case 1: ? Settings.Advanced.NibModeBoundsWidthEraserSize
k = 0.8; : Settings.Advanced.FingerModeBoundsWidthEraserSize);
break; if (Settings.Advanced.IsSpecialScreen) boundWidth *= Settings.Advanced.TouchMultiplier;
case 3: inkCanvas.EraserShape = new EllipseStylusShape(boundWidth, boundWidth);
k = 1.25; TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
break; inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
case 4: } else {
k = 1.8; inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
break; inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
} }
} else {
inkCanvas.EraserShape = new EllipseStylusShape(boundWidth * k * eraserMultiplier * 0.25, inkCanvas.EraserShape =
boundWidth * k * eraserMultiplier * 0.25); forcePointEraser ? new EllipseStylusShape(50, 50) : new EllipseStylusShape(5, 5);
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
}
else {
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None; TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None;
inkCanvas.EditingMode = InkCanvasEditingMode.None; inkCanvas.EditingMode = InkCanvasEditingMode.None;
} }
} }
} }
private void MainWindow_StylusDown(object sender, StylusDownEventArgs e) { private void MainWindow_StylusDown(object sender, StylusDownEventArgs e) {
if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) { if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) {
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice && e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) { if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice &&
e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) {
System.Windows.Forms.Cursor.Hide(); System.Windows.Forms.Cursor.Hide();
isCursorHidden = true; isCursorHidden = true;
} }
ViewboxFloatingBar.IsHitTestVisible = false; ViewboxFloatingBar.IsHitTestVisible = false;
BlackboardUIGridForInkReplay.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false;
@ -118,8 +110,10 @@ namespace Ink_Canvas {
inkCanvas.Strokes.Add(GetStrokeVisual(e.StylusDevice.Id).Stroke); inkCanvas.Strokes.Add(GetStrokeVisual(e.StylusDevice.Id).Stroke);
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁 await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id)); inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke)); inkCanvas_StrokeCollected(inkCanvas,
} catch (Exception ex) { new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
}
catch (Exception ex) {
Label.Content = ex.ToString(); Label.Content = ex.ToString();
} }
@ -142,9 +136,8 @@ namespace Ink_Canvas {
} }
private void MainWindow_StylusMove(object sender, StylusEventArgs e) { private void MainWindow_StylusMove(object sender, StylusEventArgs e) {
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice &&
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice && e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) e.StylusDevice.TabletDevice.Type == TabletDeviceType.Touch) {
{
System.Windows.Forms.Cursor.Hide(); System.Windows.Forms.Cursor.Hide();
isCursorHidden = true; isCursorHidden = true;
} }
@ -162,7 +155,8 @@ namespace Ink_Canvas {
foreach (var stylusPoint in stylusPointCollection) foreach (var stylusPoint in stylusPointCollection)
strokeVisual.Add(new StylusPoint(stylusPoint.X, stylusPoint.Y, stylusPoint.PressureFactor)); strokeVisual.Add(new StylusPoint(stylusPoint.X, stylusPoint.Y, stylusPoint.PressureFactor));
strokeVisual.Redraw(); strokeVisual.Redraw();
} catch { } }
catch { }
} }
} }
@ -184,7 +178,9 @@ namespace Ink_Canvas {
} }
private InkCanvasEditingMode GetTouchDownPointsList(int id) { private InkCanvasEditingMode GetTouchDownPointsList(int id) {
return TouchDownPointsList.TryGetValue(id, out var inkCanvasEditingMode) ? inkCanvasEditingMode : inkCanvas.EditingMode; return TouchDownPointsList.TryGetValue(id, out var inkCanvasEditingMode)
? inkCanvasEditingMode
: inkCanvas.EditingMode;
} }
private Dictionary<int, InkCanvasEditingMode> TouchDownPointsList { get; } = private Dictionary<int, InkCanvasEditingMode> TouchDownPointsList { get; } =
@ -198,7 +194,7 @@ namespace Ink_Canvas {
#region Touch Pointer Hide #region Touch Pointer Hide
public bool isCursorHidden = false; public bool isCursorHidden = false;
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) { private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) {
if (e.StylusDevice == null) { if (e.StylusDevice == null) {
if (isCursorHidden) { if (isCursorHidden) {
@ -222,9 +218,7 @@ namespace Ink_Canvas {
private bool forcePointEraser = true; private bool forcePointEraser = true;
private void Main_Grid_TouchDown(object sender, TouchEventArgs e) { private void Main_Grid_TouchDown(object sender, TouchEventArgs e) {
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice) {
if (!isCursorHidden && Settings.Gesture.HideCursorWhenUsingTouchDevice)
{
System.Windows.Forms.Cursor.Hide(); System.Windows.Forms.Cursor.Hide();
isCursorHidden = true; isCursorHidden = true;
} }
@ -243,39 +237,27 @@ namespace Ink_Canvas {
inkCanvas.Opacity = 1; inkCanvas.Opacity = 1;
if (!Settings.Gesture.DisableGestureEraser) { if (!Settings.Gesture.DisableGestureEraser) {
double boundsWidth = GetTouchBoundWidth(e), eraserMultiplier = 1.0; double boundsWidth = GetTouchBoundWidth(e);
if (!Settings.Advanced.EraserBindTouchMultiplier && Settings.Advanced.IsSpecialScreen) if ((Settings.Advanced.TouchMultiplier != 0 ||
eraserMultiplier = 1 / Settings.Advanced.TouchMultiplier; !Settings.Advanced.IsSpecialScreen) //启用特殊屏幕且触摸倍数为 0 时禁用橡皮
if (boundsWidth > BoundsWidth) { && (boundsWidth > BoundsWidth)) {
isLastTouchEraser = true; isLastTouchEraser = true;
if (drawingShapeMode == 0 && forceEraser) return; if (drawingShapeMode == 0 && forceEraser) return;
if (boundsWidth > BoundsWidth * 2.5) { double EraserThresholdValue = Settings.Startup.IsEnableNibMode
double k = 1; ? Settings.Advanced.NibModeBoundsWidthThresholdValue
switch (Settings.Canvas.EraserSize) { : Settings.Advanced.FingerModeBoundsWidthThresholdValue;
case 0: if (boundsWidth > BoundsWidth * EraserThresholdValue) {
k = 0.5; boundsWidth *= (Settings.Startup.IsEnableNibMode
break; ? Settings.Advanced.NibModeBoundsWidthEraserSize
case 1: : Settings.Advanced.FingerModeBoundsWidthEraserSize);
k = 0.8; if (Settings.Advanced.IsSpecialScreen) boundsWidth *= Settings.Advanced.TouchMultiplier;
break; inkCanvas.EraserShape = new EllipseStylusShape(boundsWidth, boundsWidth);
case 3:
k = 1.25;
break;
case 4:
k = 1.8;
break;
}
inkCanvas.EraserShape = new EllipseStylusShape(boundsWidth * k * eraserMultiplier,
boundsWidth * k * eraserMultiplier);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint; inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
} } else {
else {
inkCanvas.EraserShape = new EllipseStylusShape(5, 5); inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
} }
} } else {
else {
isLastTouchEraser = false; isLastTouchEraser = false;
inkCanvas.EraserShape = inkCanvas.EraserShape =
forcePointEraser ? new EllipseStylusShape(50, 50) : new EllipseStylusShape(5, 5); forcePointEraser ? new EllipseStylusShape(50, 50) : new EllipseStylusShape(5, 5);
@ -285,13 +267,10 @@ namespace Ink_Canvas {
} }
} }
private double GetTouchBoundWidth(TouchEventArgs e) { public double GetTouchBoundWidth(TouchEventArgs e) {
var args = e.GetTouchPoint(null).Bounds; var args = e.GetTouchPoint(null).Bounds;
double value; if (!Settings.Advanced.IsQuadIR) return args.Width;
if (!Settings.Advanced.IsQuadIR) value = args.Width; else return Math.Sqrt(args.Width * args.Height); //四边红外
else value = Math.Sqrt(args.Width * args.Height); //四边红外
if (Settings.Advanced.IsSpecialScreen) value *= Settings.Advanced.TouchMultiplier;
return value;
} }
//记录触摸设备ID //记录触摸设备ID
@ -303,7 +282,6 @@ namespace Ink_Canvas {
private bool isSingleFingerDragMode = false; private bool isSingleFingerDragMode = false;
private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) { private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) {
inkCanvas.CaptureTouch(e.TouchDevice); inkCanvas.CaptureTouch(e.TouchDevice);
ViewboxFloatingBar.IsHitTestVisible = false; ViewboxFloatingBar.IsHitTestVisible = false;
BlackboardUIGridForInkReplay.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false;
@ -317,6 +295,7 @@ namespace Ink_Canvas {
//记录第一根手指点击时的 StrokeCollection //记录第一根手指点击时的 StrokeCollection
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone(); lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
} }
//设备两个及两个以上,将画笔功能关闭 //设备两个及两个以上,将画笔功能关闭
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture) { if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture) {
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return; if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
@ -328,7 +307,6 @@ namespace Ink_Canvas {
} }
private void inkCanvas_PreviewTouchUp(object sender, TouchEventArgs e) { private void inkCanvas_PreviewTouchUp(object sender, TouchEventArgs e) {
inkCanvas.ReleaseAllTouchCaptures(); inkCanvas.ReleaseAllTouchCaptures();
ViewboxFloatingBar.IsHitTestVisible = true; ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true;
@ -431,8 +409,7 @@ namespace Ink_Canvas {
} }
catch { } catch { }
} }
} } else {
else {
if (Settings.Gesture.IsEnableTwoFingerZoom) { if (Settings.Gesture.IsEnableTwoFingerZoom) {
foreach (var stroke in inkCanvas.Strokes) { foreach (var stroke in inkCanvas.Strokes) {
stroke.Transform(m, false); stroke.Transform(m, false);
@ -444,8 +421,7 @@ namespace Ink_Canvas {
} }
; ;
} } else {
else {
foreach (var stroke in inkCanvas.Strokes) stroke.Transform(m, false); foreach (var stroke in inkCanvas.Strokes) stroke.Transform(m, false);
; ;
} }

View File

@ -454,6 +454,18 @@ namespace Ink_Canvas
[JsonProperty("eraserBindTouchMultiplier")] [JsonProperty("eraserBindTouchMultiplier")]
public bool EraserBindTouchMultiplier { get; set; } = false; public bool EraserBindTouchMultiplier { get; set; } = false;
[JsonProperty("nibModeBoundsWidthThresholdValue")]
public double NibModeBoundsWidthThresholdValue { get; set; } = 2.5;
[JsonProperty("fingerModeBoundsWidthThresholdValue")]
public double FingerModeBoundsWidthThresholdValue { get; set; } = 2.5;
[JsonProperty("nibModeBoundsWidthEraserSize")]
public double NibModeBoundsWidthEraserSize { get; set; } = 0.8;
[JsonProperty("fingerModeBoundsWidthEraserSize")]
public double FingerModeBoundsWidthEraserSize { get; set; } = 0.8;
[JsonProperty("isLogEnabled")] [JsonProperty("isLogEnabled")]
public bool IsLogEnabled { get; set; } = true; public bool IsLogEnabled { get; set; } = true;