improve:实时笔锋
This commit is contained in:
@@ -2244,9 +2244,14 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
SetFloatingBarHighlightPosition("pen");
|
SetFloatingBarHighlightPosition("pen");
|
||||||
|
|
||||||
// 记录当前是否已经是批注模式且是否为高光显示模式
|
bool isRealtimePenState = inkCanvas.EditingMode == InkCanvasEditingMode.None
|
||||||
|
&& ShouldUseRealtimeVelocityBrushTip()
|
||||||
|
&& string.Equals(GetCurrentSelectedMode(), "pen", StringComparison.OrdinalIgnoreCase);
|
||||||
bool wasInInkMode = inkCanvas.EditingMode == InkCanvasEditingMode.Ink
|
bool wasInInkMode = inkCanvas.EditingMode == InkCanvasEditingMode.Ink
|
||||||
|| (Pen_Icon.Background != null && StackPanelCanvasControls.Visibility == Visibility.Visible);
|
|| isRealtimePenState
|
||||||
|
|| (Pen_Icon.Background != null
|
||||||
|
&& StackPanelCanvasControls.Visibility == Visibility.Visible
|
||||||
|
&& string.Equals(GetCurrentSelectedMode(), "pen", StringComparison.OrdinalIgnoreCase));
|
||||||
bool wasHighlighter = drawingAttributes.IsHighlighter;
|
bool wasHighlighter = drawingAttributes.IsHighlighter;
|
||||||
|
|
||||||
if (drawingShapeMode != 0 && !isLongPressSelected)
|
if (drawingShapeMode != 0 && !isLongPressSelected)
|
||||||
|
|||||||
@@ -571,11 +571,7 @@ namespace Ink_Canvas
|
|||||||
straightStroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
straightStroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
||||||
|
|
||||||
// Replace the original stroke with the straightened one
|
// Replace the original stroke with the straightened one
|
||||||
SetNewBackupOfStroke();
|
ReplaceStrokesSafely(null, straightStroke, e.Stroke);
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(e.Stroke);
|
|
||||||
inkCanvas.Strokes.Add(straightStroke);
|
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
|
|
||||||
straightStrokeForHandwritingKey = straightStroke;
|
straightStrokeForHandwritingKey = straightStroke;
|
||||||
|
|
||||||
@@ -703,11 +699,7 @@ namespace Ink_Canvas
|
|||||||
};
|
};
|
||||||
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
||||||
circles.Add(new Circle(result.Centroid, result.ShapeWidth / 2.0, stroke));
|
circles.Add(new Circle(result.Centroid, result.ShapeWidth / 2.0, stroke));
|
||||||
SetNewBackupOfStroke();
|
ReplaceStrokesSafely(result.StrokesToRemove, stroke, e.Stroke);
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(result.StrokesToRemove);
|
|
||||||
inkCanvas.Strokes.Add(stroke);
|
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
newStrokes = new StrokeCollection();
|
newStrokes = new StrokeCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -794,9 +786,6 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
var topB = endP.Y - iniP.Y;
|
var topB = endP.Y - iniP.Y;
|
||||||
|
|
||||||
SetNewBackupOfStroke();
|
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(result.StrokesToRemove);
|
|
||||||
newStrokes = new StrokeCollection();
|
newStrokes = new StrokeCollection();
|
||||||
|
|
||||||
var _pointList = GenerateEllipseGeometry(iniP, endP, false);
|
var _pointList = GenerateEllipseGeometry(iniP, endP, false);
|
||||||
@@ -812,8 +801,7 @@ namespace Ink_Canvas
|
|||||||
_stroke,
|
_stroke,
|
||||||
_dashedLineStroke
|
_dashedLineStroke
|
||||||
};
|
};
|
||||||
inkCanvas.Strokes.Add(strokes);
|
ReplaceStrokesSafely(result.StrokesToRemove, strokes, e.Stroke);
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -863,11 +851,7 @@ namespace Ink_Canvas
|
|||||||
stroke.Transform(m, false);
|
stroke.Transform(m, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetNewBackupOfStroke();
|
ReplaceStrokesSafely(result.StrokesToRemove, stroke, e.Stroke);
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(result.StrokesToRemove);
|
|
||||||
inkCanvas.Strokes.Add(stroke);
|
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
newStrokes = new StrokeCollection();
|
newStrokes = new StrokeCollection();
|
||||||
}
|
}
|
||||||
@@ -901,11 +885,7 @@ namespace Ink_Canvas
|
|||||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||||
};
|
};
|
||||||
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
||||||
SetNewBackupOfStroke();
|
ReplaceStrokesSafely(result.StrokesToRemove, stroke, e.Stroke);
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(result.StrokesToRemove);
|
|
||||||
inkCanvas.Strokes.Add(stroke);
|
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
newStrokes = new StrokeCollection();
|
newStrokes = new StrokeCollection();
|
||||||
}
|
}
|
||||||
@@ -947,11 +927,7 @@ namespace Ink_Canvas
|
|||||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||||
};
|
};
|
||||||
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
stroke.AddPropertyData(Helpers.ModernInkAnalyzer.ShapeStrokePropertyGuid, true);
|
||||||
SetNewBackupOfStroke();
|
ReplaceStrokesSafely(result.StrokesToRemove, stroke, e.Stroke);
|
||||||
_currentCommitType = CommitReason.ShapeRecognition;
|
|
||||||
inkCanvas.Strokes.Remove(result.StrokesToRemove);
|
|
||||||
inkCanvas.Strokes.Add(stroke);
|
|
||||||
_currentCommitType = CommitReason.UserInput;
|
|
||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
newStrokes = new StrokeCollection();
|
newStrokes = new StrokeCollection();
|
||||||
}
|
}
|
||||||
@@ -2224,6 +2200,49 @@ namespace Ink_Canvas
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReplaceStrokesSafely(StrokeCollection strokesToRemove, Stroke replacementStroke, Stroke fallbackOriginalStroke = null)
|
||||||
|
{
|
||||||
|
if (replacementStroke == null) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SetNewBackupOfStroke();
|
||||||
|
_currentCommitType = CommitReason.ShapeRecognition;
|
||||||
|
|
||||||
|
if (strokesToRemove != null && strokesToRemove.Count > 0)
|
||||||
|
inkCanvas.Strokes.Remove(strokesToRemove);
|
||||||
|
if (fallbackOriginalStroke != null && inkCanvas.Strokes.Contains(fallbackOriginalStroke))
|
||||||
|
inkCanvas.Strokes.Remove(fallbackOriginalStroke);
|
||||||
|
|
||||||
|
if (!inkCanvas.Strokes.Contains(replacementStroke))
|
||||||
|
inkCanvas.Strokes.Add(replacementStroke);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_currentCommitType = CommitReason.UserInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReplaceStrokesSafely(StrokeCollection strokesToRemove, StrokeCollection replacementStrokes, Stroke fallbackOriginalStroke = null)
|
||||||
|
{
|
||||||
|
if (replacementStrokes == null || replacementStrokes.Count == 0) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SetNewBackupOfStroke();
|
||||||
|
_currentCommitType = CommitReason.ShapeRecognition;
|
||||||
|
|
||||||
|
if (strokesToRemove != null && strokesToRemove.Count > 0)
|
||||||
|
inkCanvas.Strokes.Remove(strokesToRemove);
|
||||||
|
if (fallbackOriginalStroke != null && inkCanvas.Strokes.Contains(fallbackOriginalStroke))
|
||||||
|
inkCanvas.Strokes.Remove(fallbackOriginalStroke);
|
||||||
|
|
||||||
|
inkCanvas.Strokes.Add(replacementStrokes);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_currentCommitType = CommitReason.UserInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将沿线速度映射为压感并与硬件压感混合,快写略细、慢写略粗;在落笔时(及手写笔移动时由调用方)统一施加。
|
/// 将沿线速度映射为压感并与硬件压感混合,快写略细、慢写略粗;在落笔时(及手写笔移动时由调用方)统一施加。
|
||||||
/// 无压感设备上系统可能将 <see cref="DrawingAttributes.IgnorePressure"/> 置为 true,此处强制关闭以便粗细随合成压感变化。
|
/// 无压感设备上系统可能将 <see cref="DrawingAttributes.IgnorePressure"/> 置为 true,此处强制关闭以便粗细随合成压感变化。
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace Ink_Canvas
|
|||||||
private readonly Guid RealtimeVelocityBrushTipAppliedGuid = new Guid("74E57D95-945F-4A8C-B52A-7D3EF2D4FD5B");
|
private readonly Guid RealtimeVelocityBrushTipAppliedGuid = new Guid("74E57D95-945F-4A8C-B52A-7D3EF2D4FD5B");
|
||||||
internal const int MouseRealtimeStrokeId = -100001;
|
internal const int MouseRealtimeStrokeId = -100001;
|
||||||
private readonly HashSet<int> _activeRealtimeTouchStrokeIds = new HashSet<int>();
|
private readonly HashSet<int> _activeRealtimeTouchStrokeIds = new HashSet<int>();
|
||||||
|
private readonly HashSet<int> _activeTouchStrokeIds = new HashSet<int>();
|
||||||
|
|
||||||
private sealed class OneEuroFilter
|
private sealed class OneEuroFilter
|
||||||
{
|
{
|
||||||
@@ -1202,6 +1203,28 @@ namespace Ink_Canvas
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((isInMultiTouchMode || Settings.Gesture.IsEnableMultiTouchMode)
|
||||||
|
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||||
|
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||||
|
&& inkCanvas.EditingMode != InkCanvasEditingMode.Select)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||||
|
var touchId = e.TouchDevice.Id;
|
||||||
|
var p = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
_activeTouchStrokeIds.Add(touchId);
|
||||||
|
var sv = GetStrokeVisual(touchId);
|
||||||
|
sv.Add(new StylusPoint(p.X, p.Y, 0.5f));
|
||||||
|
sv.Redraw();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Settings.Canvas.EnablePalmEraser && !isPalmEraserActive && drawingShapeMode == 0)
|
if (Settings.Canvas.EnablePalmEraser && !isPalmEraserActive && drawingShapeMode == 0)
|
||||||
{
|
{
|
||||||
var touchPoint = e.GetTouchPoint(inkCanvas);
|
var touchPoint = e.GetTouchPoint(inkCanvas);
|
||||||
@@ -1314,23 +1337,38 @@ namespace Ink_Canvas
|
|||||||
EraserOverlay_PointerMove(sender, touchPoint.Position);
|
EraserOverlay_PointerMove(sender, touchPoint.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ShouldUseRealtimeVelocityBrushTipForTouch())
|
|
||||||
return;
|
|
||||||
|
|
||||||
var touchId = e.TouchDevice.Id;
|
var touchId = e.TouchDevice.Id;
|
||||||
if (!_activeRealtimeTouchStrokeIds.Contains(touchId))
|
if (ShouldUseRealtimeVelocityBrushTipForTouch())
|
||||||
|
{
|
||||||
|
if (!_activeRealtimeTouchStrokeIds.Contains(touchId))
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var p = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
var sv = GetStrokeVisual(touchId);
|
||||||
|
if (TryAppendRealtimeVelocityBrushTipPoint(sv, touchId, p))
|
||||||
|
sv.ForceRedraw();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var p = e.GetTouchPoint(inkCanvas).Position;
|
|
||||||
var sv = GetStrokeVisual(touchId);
|
|
||||||
if (TryAppendRealtimeVelocityBrushTipPoint(sv, touchId, p))
|
|
||||||
sv.ForceRedraw();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
if (_activeTouchStrokeIds.Contains(touchId))
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine(ex);
|
try
|
||||||
|
{
|
||||||
|
var p = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
var sv = GetStrokeVisual(touchId);
|
||||||
|
sv.Add(new StylusPoint(p.X, p.Y, 0.5f));
|
||||||
|
sv.Redraw();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1389,6 +1427,34 @@ namespace Ink_Canvas
|
|||||||
_activeRealtimeTouchStrokeIds.Remove(touchId);
|
_activeRealtimeTouchStrokeIds.Remove(touchId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_activeTouchStrokeIds.Contains(touchId))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sv = GetStrokeVisual(touchId);
|
||||||
|
sv?.Redraw();
|
||||||
|
var stroke = sv?.Stroke;
|
||||||
|
if (stroke != null)
|
||||||
|
{
|
||||||
|
inkCanvas.Strokes.Add(stroke);
|
||||||
|
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(stroke));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (VisualCanvasList.TryGetValue(touchId, out var visualCanvas) && inkCanvas.Children.Contains(visualCanvas))
|
||||||
|
inkCanvas.Children.Remove(visualCanvas);
|
||||||
|
StrokeVisualList.Remove(touchId);
|
||||||
|
VisualCanvasList.Remove(touchId);
|
||||||
|
TouchDownPointsList.Remove(touchId);
|
||||||
|
CleanupRealtimeBrushTipState(touchId);
|
||||||
|
_activeTouchStrokeIds.Remove(touchId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint && !isPalmEraserActive)
|
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint && !isPalmEraserActive)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user