From c3fd5551d88c74b5828bbbfcac02b1924dc9b2b7 Mon Sep 17 00:00:00 2001
From: CJK_mkp <113243675+CJKmkp@users.noreply.github.com>
Date: Sat, 8 Nov 2025 22:17:52 +0800
Subject: [PATCH] =?UTF-8?q?improve:=E5=BF=AB=E6=8A=BD=E6=8C=89=E9=92=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../QuickDrawFloatingButtonControl.xaml} | 26 +-
.../QuickDrawFloatingButtonControl.xaml.cs | 149 ++++++++
Ink Canvas/MainWindow.xaml | 74 +---
Ink Canvas/MainWindow.xaml.cs | 132 +------
Ink Canvas/Windows/QuickDrawFloatingButton.cs | 355 ------------------
5 files changed, 165 insertions(+), 571 deletions(-)
rename Ink Canvas/{Windows/QuickDrawFloatingButton.xaml => Controls/QuickDrawFloatingButtonControl.xaml} (86%)
create mode 100644 Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml.cs
delete mode 100644 Ink Canvas/Windows/QuickDrawFloatingButton.cs
diff --git a/Ink Canvas/Windows/QuickDrawFloatingButton.xaml b/Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml
similarity index 86%
rename from Ink Canvas/Windows/QuickDrawFloatingButton.xaml
rename to Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml
index 07786911..37a17947 100644
--- a/Ink Canvas/Windows/QuickDrawFloatingButton.xaml
+++ b/Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml
@@ -1,22 +1,19 @@
-
-
-
+
+
+
-
+
-
+
+
diff --git a/Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml.cs b/Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml.cs
new file mode 100644
index 00000000..c09e3f3b
--- /dev/null
+++ b/Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml.cs
@@ -0,0 +1,149 @@
+using Ink_Canvas.Windows;
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Threading;
+using MouseEventArgs = System.Windows.Input.MouseEventArgs;
+using HorizontalAlignment = System.Windows.HorizontalAlignment;
+using VerticalAlignment = System.Windows.VerticalAlignment;
+
+namespace Ink_Canvas.Controls
+{
+ ///
+ /// 快抽悬浮按钮控件
+ ///
+ public partial class QuickDrawFloatingButtonControl : UserControl
+ {
+ private bool _isDragging = false;
+ private Point _dragStartPoint;
+ private Point _controlStartPoint;
+
+ public QuickDrawFloatingButtonControl()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// 快抽按钮点击事件
+ ///
+ private void FloatingButton_Click(object sender, MouseButtonEventArgs e)
+ {
+ try
+ {
+ // 如果正在拖动,不触发点击事件
+ if (_isDragging) return;
+
+ // 打开快抽窗口
+ var quickDrawWindow = new QuickDrawWindow();
+ quickDrawWindow.ShowDialog();
+ }
+ catch (Exception ex)
+ {
+ Helpers.LogHelper.WriteLogToFile($"打开快抽窗口失败: {ex.Message}", Helpers.LogHelper.LogType.Error);
+ }
+ }
+
+ ///
+ /// 拖动区域鼠标按下事件
+ ///
+ private void DragArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ _isDragging = false;
+
+ // 记录鼠标在屏幕上的初始位置
+ _dragStartPoint = this.PointToScreen(e.GetPosition(this));
+
+ // 记录控件的初始位置
+ var parent = this.Parent as FrameworkElement;
+ if (parent != null)
+ {
+ var transform = this.TransformToVisual(parent);
+ var currentPos = transform.Transform(new Point(0, 0));
+ _controlStartPoint = currentPos;
+ }
+ else
+ {
+ var currentMargin = this.Margin;
+ _controlStartPoint = new Point(
+ double.IsNaN(currentMargin.Left) ? 0 : currentMargin.Left,
+ double.IsNaN(currentMargin.Top) ? 0 : currentMargin.Top);
+ }
+
+ ((UIElement)sender).CaptureMouse();
+ e.Handled = true;
+ }
+
+ ///
+ /// 拖动区域鼠标移动事件
+ ///
+ private void DragArea_MouseMove(object sender, MouseEventArgs e)
+ {
+ if (e.LeftButton == MouseButtonState.Pressed && ((UIElement)sender).IsMouseCaptured)
+ {
+ // 获取鼠标在屏幕上的当前位置
+ Point currentScreenPoint = this.PointToScreen(e.GetPosition(this));
+ Vector diff = currentScreenPoint - _dragStartPoint;
+
+ if (!_isDragging && (Math.Abs(diff.X) > 3 || Math.Abs(diff.Y) > 3))
+ {
+ _isDragging = true;
+ // 切换到绝对定位模式
+ this.HorizontalAlignment = HorizontalAlignment.Left;
+ this.VerticalAlignment = VerticalAlignment.Top;
+ }
+
+ if (_isDragging)
+ {
+ // 计算新位置
+ var parent = this.Parent as FrameworkElement;
+ if (parent != null)
+ {
+ // 计算屏幕坐标相对于父容器的位置
+ var parentPoint = parent.PointFromScreen(currentScreenPoint);
+ var startParentPoint = parent.PointFromScreen(_dragStartPoint);
+
+ // 计算相对于初始位置的偏移
+ double offsetX = parentPoint.X - startParentPoint.X;
+ double offsetY = parentPoint.Y - startParentPoint.Y;
+
+ // 新位置 = 初始位置 + 偏移
+ double newLeft = _controlStartPoint.X + offsetX;
+ double newTop = _controlStartPoint.Y + offsetY;
+
+ // 限制在父容器范围内
+ newLeft = Math.Max(0, Math.Min(newLeft, parent.ActualWidth - this.ActualWidth));
+ newTop = Math.Max(0, Math.Min(newTop, parent.ActualHeight - this.ActualHeight));
+
+ // 更新Margin
+ this.Margin = new Thickness(newLeft, newTop, 0, 0);
+ }
+ }
+ }
+ }
+
+ ///
+ /// 拖动区域鼠标释放事件
+ ///
+ private void DragArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ if (((UIElement)sender).IsMouseCaptured)
+ {
+ ((UIElement)sender).ReleaseMouseCapture();
+ }
+
+ if (_isDragging)
+ {
+ Dispatcher.BeginInvoke(new Action(() => { _isDragging = false; }),
+ DispatcherPriority.Background);
+ }
+ else
+ {
+ _isDragging = false;
+ }
+
+ e.Handled = true;
+ }
+ }
+}
+
diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index 552989f3..daf5c125 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -6,6 +6,7 @@
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:c="clr-namespace:Ink_Canvas.Converter"
xmlns:Controls="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
+ xmlns:controls="clr-namespace:Ink_Canvas.Controls"
mc:Ignorable="d"
AllowsTransparency="True"
WindowStyle="None"
@@ -3958,81 +3959,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Panel.ZIndex="1001"/>