66using System . Windows . Controls ;
77using System . Windows . Ink ;
88using System . Windows . Input ;
9+ using System . Windows . Media ;
910using System . Windows . Media . Imaging ;
1011using WinForms = System . Windows . Forms ;
1112using ShowWrite . Models ;
@@ -30,6 +31,10 @@ private enum ToolMode { None, Move, Pen, Eraser }
3031 private D . Point _lastMousePos ;
3132 private bool _isPanning = false ;
3233
34+ // 新增:缩放比例 & 用户笔宽
35+ private double currentZoom = 1.0 ;
36+ private double userPenWidth = 2.0 ;
37+
3338 public MainWindow ( )
3439 {
3540 InitializeComponent ( ) ;
@@ -55,9 +60,17 @@ public MainWindow()
5560 {
5661 MessageBox . Show ( "未找到可用摄像头。" , "错误" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
5762 }
63+
64+ UpdatePenAttributes ( ) ;
65+ }
66+
67+ private void UpdatePenAttributes ( )
68+ {
69+ Ink . DefaultDrawingAttributes . Width = userPenWidth / currentZoom ;
70+ Ink . DefaultDrawingAttributes . Height = userPenWidth / currentZoom ;
5871 }
5972
60- #region ģʽ�л�
73+ #region 模式切换
6174 private void SetMode ( ToolMode mode , bool initial = false )
6275 {
6376 _currentMode = mode ;
@@ -85,18 +98,19 @@ private void SetMode(ToolMode mode, bool initial = false)
8598 private void MoveBtn_Click ( object sender , RoutedEventArgs e )
8699 {
87100 if ( _currentMode != ToolMode . Move ) SetMode ( ToolMode . Move ) ;
88- else MoveBtn . IsChecked = true ; // ��ֹȡ��ѡ��
101+ else MoveBtn . IsChecked = true ;
89102 }
90103
91104 private void PenBtn_Click ( object sender , RoutedEventArgs e )
92105 {
93106 if ( _currentMode == ToolMode . Pen )
94107 {
95- var dlg = new WinForms . ColorDialog ( ) ;
96- if ( dlg . ShowDialog ( ) == WinForms . DialogResult . OK )
108+ var dlg = new PenSettingsWindow ( Ink . DefaultDrawingAttributes . Color , userPenWidth ) ;
109+ if ( dlg . ShowDialog ( ) == true )
97110 {
98- Ink . DefaultDrawingAttributes . Color = System . Windows . Media . Color . FromArgb (
99- dlg . Color . A , dlg . Color . R , dlg . Color . G , dlg . Color . B ) ;
111+ Ink . DefaultDrawingAttributes . Color = dlg . SelectedColor ;
112+ userPenWidth = dlg . SelectedWidth ;
113+ UpdatePenAttributes ( ) ;
100114 }
101115 PenBtn . IsChecked = true ;
102116 }
@@ -106,6 +120,8 @@ private void PenBtn_Click(object sender, RoutedEventArgs e)
106120 }
107121 }
108122
123+
124+
109125 private void EraserBtn_Click ( object sender , RoutedEventArgs e )
110126 {
111127 if ( _currentMode != ToolMode . Eraser ) SetMode ( ToolMode . Eraser ) ;
@@ -151,8 +167,10 @@ private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
151167 if ( _currentMode == ToolMode . Move || _currentMode == ToolMode . Pen )
152168 {
153169 double zoom = e . Delta > 0 ? 1.1 : 0.9 ;
154- ZoomTransform . ScaleX *= zoom ;
155- ZoomTransform . ScaleY *= zoom ;
170+ currentZoom *= zoom ;
171+ ZoomTransform . ScaleX = currentZoom ;
172+ ZoomTransform . ScaleY = currentZoom ;
173+ UpdatePenAttributes ( ) ;
156174 }
157175 }
158176
@@ -175,11 +193,12 @@ private void VideoArea_ManipulationDelta(object sender, ManipulationDeltaEventAr
175193 return ;
176194
177195 var delta = e . DeltaManipulation ;
178-
179- ZoomTransform . ScaleX *= delta . Scale . X ;
180- ZoomTransform . ScaleY *= delta . Scale . Y ;
196+ currentZoom *= delta . Scale . X ;
197+ ZoomTransform . ScaleX = currentZoom ;
198+ ZoomTransform . ScaleY = currentZoom ;
181199 PanTransform . X += delta . Translation . X ;
182200 PanTransform . Y += delta . Translation . Y ;
201+ UpdatePenAttributes ( ) ;
183202
184203 e . Handled = true ;
185204 }
@@ -310,9 +329,6 @@ private void OpenPerspectiveCorrection_Click(object sender, RoutedEventArgs e)
310329 }
311330 }
312331
313- #endregion
314-
315- #region ���߷���
316332 private BitmapImage BitmapToBitmapImage ( D . Bitmap bitmap )
317333 {
318334 using var memory = new MemoryStream ( ) ;
0 commit comments