代码清理

This commit is contained in:
PrefacedCorg
2025-08-03 16:46:33 +08:00
parent 745b798d89
commit 11a5a7fdbe
73 changed files with 5733 additions and 3857 deletions
@@ -1,3 +1,4 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Collections.Generic;
using System.Windows;
@@ -7,21 +8,24 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Point = System.Windows.Point;
namespace Ink_Canvas {
public partial class MainWindow : Window {
namespace Ink_Canvas
{
public partial class MainWindow : Window
{
#region Floating Control
private object lastBorderMouseDownObject;
private void Border_MouseDown(object sender, MouseButtonEventArgs e) {
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
// 如果发送者是 RandomDrawPanel 或 SingleDrawPanel,且它们被隐藏,则不处理事件
if (sender is SimpleStackPanel panel) {
if ((panel == RandomDrawPanel || panel == SingleDrawPanel) &&
panel.Visibility != Visibility.Visible) {
if (sender is SimpleStackPanel panel)
{
if ((panel == RandomDrawPanel || panel == SingleDrawPanel) &&
panel.Visibility != Visibility.Visible)
{
return;
}
}
@@ -30,22 +34,26 @@ namespace Ink_Canvas {
private bool isStrokeSelectionCloneOn;
private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) {
private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
if (isStrokeSelectionCloneOn) {
if (isStrokeSelectionCloneOn)
{
BorderStrokeSelectionClone.Background = Brushes.Transparent;
isStrokeSelectionCloneOn = false;
}
else {
else
{
BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
isStrokeSelectionCloneOn = true;
}
}
private void BorderStrokeSelectionCloneToNewBoard_MouseUp(object sender, MouseButtonEventArgs e) {
private void BorderStrokeSelectionCloneToNewBoard_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
var strokes = inkCanvas.GetSelectedStrokes();
@@ -55,23 +63,28 @@ namespace Ink_Canvas {
inkCanvas.Strokes.Add(strokes);
}
private void BorderStrokeSelectionDelete_MouseUp(object sender, MouseButtonEventArgs e) {
private void BorderStrokeSelectionDelete_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
SymbolIconDelete_MouseUp(sender, e);
}
private void GridPenWidthDecrease_MouseUp(object sender, MouseButtonEventArgs e) {
private void GridPenWidthDecrease_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
ChangeStrokeThickness(0.8);
}
private void GridPenWidthIncrease_MouseUp(object sender, MouseButtonEventArgs e) {
private void GridPenWidthIncrease_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
ChangeStrokeThickness(1.25);
}
private void ChangeStrokeThickness(double multipler) {
foreach (var stroke in inkCanvas.GetSelectedStrokes()) {
private void ChangeStrokeThickness(double multipler)
{
foreach (var stroke in inkCanvas.GetSelectedStrokes())
{
var newWidth = stroke.DrawingAttributes.Width * multipler;
var newHeight = stroke.DrawingAttributes.Height * multipler;
if (!(newWidth >= DrawingAttributes.MinWidth) || !(newWidth <= DrawingAttributes.MaxWidth)
@@ -92,16 +105,19 @@ namespace Ink_Canvas {
}
}
private void GridPenWidthRestore_MouseUp(object sender, MouseButtonEventArgs e) {
private void GridPenWidthRestore_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
foreach (var stroke in inkCanvas.GetSelectedStrokes()) {
foreach (var stroke in inkCanvas.GetSelectedStrokes())
{
stroke.DrawingAttributes.Width = inkCanvas.DefaultDrawingAttributes.Width;
stroke.DrawingAttributes.Height = inkCanvas.DefaultDrawingAttributes.Height;
}
}
private void ImageFlipHorizontal_MouseUp(object sender, MouseButtonEventArgs e) {
private void ImageFlipHorizontal_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
var m = new Matrix();
@@ -137,7 +153,8 @@ namespace Ink_Canvas {
//updateBorderStrokeSelectionControlLocation();
}
private void ImageFlipVertical_MouseUp(object sender, MouseButtonEventArgs e) {
private void ImageFlipVertical_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
var m = new Matrix();
@@ -166,8 +183,9 @@ namespace Ink_Canvas {
}
}
// ... existing code ...
private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) {
// ... existing code ...
private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
var m = new Matrix();
@@ -196,7 +214,8 @@ namespace Ink_Canvas {
}
}
private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e) {
private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
var m = new Matrix();
@@ -235,27 +254,33 @@ namespace Ink_Canvas {
private bool isGridInkCanvasSelectionCoverMouseDown;
private StrokeCollection StrokesSelectionClone = new StrokeCollection();
private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e) {
private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e)
{
isGridInkCanvasSelectionCoverMouseDown = true;
}
private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e) {
private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!isGridInkCanvasSelectionCoverMouseDown) return;
isGridInkCanvasSelectionCoverMouseDown = false;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
private void BtnSelect_Click(object sender, RoutedEventArgs e) {
private void BtnSelect_Click(object sender, RoutedEventArgs e)
{
ExitMultiTouchModeIfNeeded();
forceEraser = true;
drawingShapeMode = 0;
inkCanvas.IsManipulationEnabled = false;
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
if (inkCanvas.GetSelectedStrokes().Count == inkCanvas.Strokes.Count) {
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select)
{
if (inkCanvas.GetSelectedStrokes().Count == inkCanvas.Strokes.Count)
{
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
}
else {
else
{
var selectedStrokes = new StrokeCollection();
foreach (var stroke in inkCanvas.Strokes)
if (stroke.GetBounds().Width > 0 && stroke.GetBounds().Height > 0)
@@ -263,7 +288,8 @@ namespace Ink_Canvas {
inkCanvas.Select(selectedStrokes);
}
}
else {
else
{
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
}
}
@@ -272,14 +298,17 @@ namespace Ink_Canvas {
private double BorderStrokeSelectionControlHeight = 80.0;
private bool isProgramChangeStrokeSelection;
private void inkCanvas_SelectionChanged(object sender, EventArgs e) {
private void inkCanvas_SelectionChanged(object sender, EventArgs e)
{
if (isProgramChangeStrokeSelection) return;
if (inkCanvas.GetSelectedStrokes().Count == 0) {
if (inkCanvas.GetSelectedStrokes().Count == 0)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
// 当没有选中笔画时,检查是否有选中的UIElement
CheckUIElementSelection();
}
else {
else
{
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
BorderStrokeSelectionClone.Background = Brushes.Transparent;
isStrokeSelectionCloneOn = false;
@@ -304,7 +333,8 @@ namespace Ink_Canvas {
}
}
private void updateBorderStrokeSelectionControlLocation() {
private void updateBorderStrokeSelectionControlLocation()
{
var borderLeft = (inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Right -
BorderStrokeSelectionControlWidth) / 2;
var borderTop = inkCanvas.GetSelectionBounds().Bottom + 1;
@@ -319,11 +349,13 @@ namespace Ink_Canvas {
BorderStrokeSelectionControl.Margin = new Thickness(borderLeft, borderTop, 0, 0);
}
private void GridInkCanvasSelectionCover_ManipulationStarting(object sender, ManipulationStartingEventArgs e) {
private void GridInkCanvasSelectionCover_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.Mode = ManipulationModes.All;
}
private void GridInkCanvasSelectionCover_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
private void GridInkCanvasSelectionCover_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if (StrokeManipulationHistory?.Count > 0)
{
timeMachine.CommitStrokeManipulationHistory(StrokeManipulationHistory);
@@ -344,9 +376,12 @@ namespace Ink_Canvas {
}
}
private void GridInkCanvasSelectionCover_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) {
try {
if (dec.Count >= 1) {
private void GridInkCanvasSelectionCover_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
try
{
if (dec.Count >= 1)
{
bool disableScale = dec.Count >= 3;
var md = e.DeltaManipulation;
var trans = md.Translation; // 获得位移矢量
@@ -372,10 +407,12 @@ namespace Ink_Canvas {
strokes = StrokesSelectionClone;
else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection)
m.RotateAt(rotate, center.X, center.Y); // 旋转
foreach (var stroke in strokes) {
foreach (var stroke in strokes)
{
stroke.Transform(m, false);
try {
try
{
stroke.DrawingAttributes.Width *= md.Scale.X;
stroke.DrawingAttributes.Height *= md.Scale.Y;
}
@@ -394,15 +431,18 @@ namespace Ink_Canvas {
private Point lastTouchPointOnGridInkCanvasCover = new Point(0, 0);
private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e) {
private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e)
{
dec.Add(e.TouchDevice.Id);
//设备1个的时候,记录中心点
if (dec.Count == 1) {
if (dec.Count == 1)
{
var touchPoint = e.GetTouchPoint(null);
centerPoint = touchPoint.Position;
lastTouchPointOnGridInkCanvasCover = touchPoint.Position;
if (isStrokeSelectionCloneOn) {
if (isStrokeSelectionCloneOn)
{
var strokes = inkCanvas.GetSelectedStrokes();
isProgramChangeStrokeSelection = true;
inkCanvas.Select(new StrokeCollection());
@@ -411,7 +451,8 @@ namespace Ink_Canvas {
isProgramChangeStrokeSelection = false;
inkCanvas.Strokes.Add(StrokesSelectionClone);
}
else {
else
{
// 新增:启动套索选择模式
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
inkCanvas.Select(new StrokeCollection());
@@ -419,11 +460,13 @@ namespace Ink_Canvas {
}
}
private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEventArgs e) {
private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEventArgs e)
{
dec.Remove(e.TouchDevice.Id);
if (dec.Count >= 1) return;
isProgramChangeStrokeSelection = false;
if (lastTouchPointOnGridInkCanvasCover == e.GetTouchPoint(null).Position) {
if (lastTouchPointOnGridInkCanvasCover == e.GetTouchPoint(null).Position)
{
if (!(lastTouchPointOnGridInkCanvasCover.X < inkCanvas.GetSelectionBounds().Left) &&
!(lastTouchPointOnGridInkCanvasCover.Y < inkCanvas.GetSelectionBounds().Top) &&
!(lastTouchPointOnGridInkCanvasCover.X > inkCanvas.GetSelectionBounds().Right) &&
@@ -431,17 +474,20 @@ namespace Ink_Canvas {
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = new StrokeCollection();
}
else if (inkCanvas.GetSelectedStrokes().Count == 0) {
else if (inkCanvas.GetSelectedStrokes().Count == 0)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
StrokesSelectionClone = new StrokeCollection();
}
else {
else
{
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
StrokesSelectionClone = new StrokeCollection();
}
}
private void LassoSelect_Click(object sender, RoutedEventArgs e) {
private void LassoSelect_Click(object sender, RoutedEventArgs e)
{
ExitMultiTouchModeIfNeeded();
forceEraser = false;
forcePointEraser = false;
@@ -450,7 +496,8 @@ namespace Ink_Canvas {
SetCursorBasedOnEditingMode(inkCanvas);
}
private void BtnLassoSelect_Click(object sender, RoutedEventArgs e) {
private void BtnLassoSelect_Click(object sender, RoutedEventArgs e)
{
ExitMultiTouchModeIfNeeded();
forceEraser = false;
forcePointEraser = false;