|
@@ -0,0 +1,408 @@
|
|
1
|
+using Common.system;
|
|
2
|
+using System;
|
|
3
|
+using System.Collections.Generic;
|
|
4
|
+using System.Linq;
|
|
5
|
+using System.Text;
|
|
6
|
+using System.Threading;
|
|
7
|
+using System.Threading.Tasks;
|
|
8
|
+using System.Windows;
|
|
9
|
+using System.Windows.Controls;
|
|
10
|
+using System.Windows.Data;
|
|
11
|
+using System.Windows.Documents;
|
|
12
|
+using System.Windows.Ink;
|
|
13
|
+using System.Windows.Input;
|
|
14
|
+using System.Windows.Media;
|
|
15
|
+using System.Windows.Media.Imaging;
|
|
16
|
+using System.Windows.Shapes;
|
|
17
|
+using TStudyDigitalPen.HID;
|
|
18
|
+
|
|
19
|
+namespace XHPZ.Desktop
|
|
20
|
+{
|
|
21
|
+ /// <summary>
|
|
22
|
+ /// PracticeWindow.xaml 的交互逻辑
|
|
23
|
+ /// </summary>
|
|
24
|
+ public partial class PracticeWindow : Window
|
|
25
|
+ {
|
|
26
|
+ private DrawingAttributes drawingAttributes;
|
|
27
|
+ public PracticeWindow()
|
|
28
|
+ {
|
|
29
|
+ InitializeComponent();
|
|
30
|
+ InitPen();
|
|
31
|
+ }
|
|
32
|
+ /// <summary>
|
|
33
|
+ /// 初始化
|
|
34
|
+ /// </summary>
|
|
35
|
+ /// <param name="_imgPath"></param>
|
|
36
|
+ public void Initialize(string _imgPath = null)
|
|
37
|
+ {
|
|
38
|
+ blackboard_canvas.Strokes.Clear();
|
|
39
|
+ blackboard_canvas.UseCustomCursor = true;
|
|
40
|
+ //创建 DrawingAttributes 类的一个实例
|
|
41
|
+ drawingAttributes = new DrawingAttributes();
|
|
42
|
+ blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
|
|
43
|
+ Pen();
|
|
44
|
+ }
|
|
45
|
+ public void InitPen()
|
|
46
|
+ {
|
|
47
|
+ //stroke = new List<System.Drawing.Point>();
|
|
48
|
+ //获取点阵笔实例,并绑定点阵笔事件
|
|
49
|
+ //将授权文件内容传入,获取点阵笔对象实例
|
|
50
|
+ APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
|
|
51
|
+ //绑定笔连接事件
|
|
52
|
+ APP.digitalPen.PenConnected += OnPenConnect;
|
|
53
|
+ //绑定笔断开事件
|
|
54
|
+ APP.digitalPen.PenDisconnect += OnPenDisconnect;
|
|
55
|
+ //绑定笔书写输出坐标事件
|
|
56
|
+ APP.digitalPen.PenCoordinate += OnPenCoordinate;
|
|
57
|
+ //绑定抬笔事件
|
|
58
|
+ APP.digitalPen.PenUp += OnPenUp;
|
|
59
|
+ //绑定落笔事件
|
|
60
|
+ APP.digitalPen.PenDown += OnPenDown;
|
|
61
|
+ APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
|
|
62
|
+ APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
|
|
63
|
+ //完成初始化点阵笔,开始与点阵笔通信
|
|
64
|
+ ERROR_CODE ER = APP.digitalPen.Start();
|
|
65
|
+ //判断是否成功
|
|
66
|
+ //if (ER != ERROR_CODE.ERROR_OK)
|
|
67
|
+ //{
|
|
68
|
+ // MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
|
|
69
|
+ //}
|
|
70
|
+ }
|
|
71
|
+ /// <summary>
|
|
72
|
+ /// 画笔
|
|
73
|
+ /// </summary>
|
|
74
|
+ public void Pen()
|
|
75
|
+ {
|
|
76
|
+ blackboard_canvas.EditingMode = InkCanvasEditingMode.Ink;
|
|
77
|
+ blackboard_canvas.UseCustomCursor = true;
|
|
78
|
+ drawingAttributes.FitToCurve = true;
|
|
79
|
+ drawingAttributes.IgnorePressure = false;
|
|
80
|
+ blackboard_canvas.Cursor = Cursors.Pen;
|
|
81
|
+ }
|
|
82
|
+ /// <summary>
|
|
83
|
+ /// 笔连接
|
|
84
|
+ /// </summary>
|
|
85
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
86
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
87
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
88
|
+ private void OnPenConnect(ulong time, string penSerial, int penType)
|
|
89
|
+ {
|
|
90
|
+ if (CheckAccess())
|
|
91
|
+ {
|
|
92
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
|
|
93
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
94
|
+ }
|
|
95
|
+ else
|
|
96
|
+ {
|
|
97
|
+ APP.PenSerial = penSerial;
|
|
98
|
+ APP.PenStatus = true;
|
|
99
|
+ this.penSerial = penSerial;
|
|
100
|
+ //连接后,在获取笔数据前,可以清除笔内的历史数据
|
|
101
|
+ //APP.digitalPen.ClearMemory(penSerial);
|
|
102
|
+
|
|
103
|
+ //开始接收笔数据
|
|
104
|
+ APP.digitalPen.GetPenData(penSerial);
|
|
105
|
+ //UpdateDevStatus();
|
|
106
|
+ ////Dispatcher.Invoke(new Action(() =>
|
|
107
|
+ ////{
|
|
108
|
+ //// txbNotConnected.Text = "已连接";
|
|
109
|
+ //// txbNotConnecteds.Text = "已连接";
|
|
110
|
+ ////}));
|
|
111
|
+
|
|
112
|
+ }
|
|
113
|
+ }
|
|
114
|
+ /// <summary>
|
|
115
|
+ /// 笔断开
|
|
116
|
+ /// </summary>
|
|
117
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
118
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
119
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
120
|
+ private void OnPenDisconnect(ulong time, string penSerial, int penType)
|
|
121
|
+ {
|
|
122
|
+ if (CheckAccess())
|
|
123
|
+ {
|
|
124
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
|
|
125
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
126
|
+ }
|
|
127
|
+ else
|
|
128
|
+ {
|
|
129
|
+ APP.PenSerial = penSerial;
|
|
130
|
+ APP.PenStatus = false;
|
|
131
|
+ //UpdateDevStatus();
|
|
132
|
+ ////Dispatcher.Invoke(new Action(() =>
|
|
133
|
+ ////{
|
|
134
|
+ //// txbNotConnected.Text = "未连接";
|
|
135
|
+ //// txbNotConnecteds.Text = "未连接";
|
|
136
|
+ ////}));
|
|
137
|
+ }
|
|
138
|
+ }
|
|
139
|
+ /// <summary>
|
|
140
|
+ /// 笔序列号
|
|
141
|
+ /// </summary>
|
|
142
|
+ private string penSerial;
|
|
143
|
+
|
|
144
|
+ /// <summary>
|
|
145
|
+ /// 笔是否在点
|
|
146
|
+ /// </summary>
|
|
147
|
+ private bool isPenDown;
|
|
148
|
+ /// <summary>
|
|
149
|
+ /// 笔书写,收到坐标
|
|
150
|
+ /// </summary>
|
|
151
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
152
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
153
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
154
|
+ /// <param name="pageSerial">点阵地址</param>
|
|
155
|
+ /// <param name="cx">x坐标</param>
|
|
156
|
+ /// <param name="cy">y坐标</param>
|
|
157
|
+ /// <param name="force">压力值</param>
|
|
158
|
+ private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
|
|
159
|
+ {
|
|
160
|
+ if (this.Visibility == Visibility.Visible)
|
|
161
|
+ {
|
|
162
|
+ if (CheckAccess())
|
|
163
|
+ {
|
|
164
|
+ Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
|
|
165
|
+ Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
|
|
166
|
+ }
|
|
167
|
+ else
|
|
168
|
+ {
|
|
169
|
+ //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
|
|
170
|
+ if (!isPenDown)
|
|
171
|
+ {
|
|
172
|
+ return;
|
|
173
|
+ }
|
|
174
|
+ stroke.Add(new System.Drawing.Point(cx, cy));
|
|
175
|
+
|
|
176
|
+ double PropW = blackboard_canvas.ActualWidth / A4_HEIGHT;
|
|
177
|
+ double PropH = blackboard_canvas.ActualHeight / A4_WIDTH;
|
|
178
|
+ //点
|
|
179
|
+ double testX = cy * PropW;
|
|
180
|
+ double testY = (A4_WIDTH - cx) * PropH;
|
|
181
|
+ //pageSerial //点阵IP地址 与打印的页面关联
|
|
182
|
+ if (true)
|
|
183
|
+ {
|
|
184
|
+ Dispatcher.Invoke(new Action(() =>
|
|
185
|
+ {
|
|
186
|
+ float Pressure = force / 100f;
|
|
187
|
+ ////添加笔画
|
|
188
|
+ //myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
|
|
189
|
+
|
|
190
|
+ if (isFirst)
|
|
191
|
+ {
|
|
192
|
+ stylusPoint.X = testX;
|
|
193
|
+ stylusPoint.Y = testY;
|
|
194
|
+ //_color.A = (byte)(Pressure * 255f);
|
|
195
|
+ //stylusPoint.PressureFactor = Pressure;
|
|
196
|
+
|
|
197
|
+ //for(int i=0;i<100;i++)
|
|
198
|
+ //{
|
|
199
|
+ // stylusPoint.X--;
|
|
200
|
+ // stylusPoint.Y--;
|
|
201
|
+ // stylusPoints.Add(stylusPoint);
|
|
202
|
+ //}
|
|
203
|
+ stylusPoints.Add(stylusPoint);
|
|
204
|
+ if (stylusPoints.Count > 1)
|
|
205
|
+ {
|
|
206
|
+ drawing = new DrawingAttributes
|
|
207
|
+ {
|
|
208
|
+ Color = Colour,
|
|
209
|
+ Width = Wit * 4.5,
|
|
210
|
+ Height = Wit * 4.5,
|
|
211
|
+ FitToCurve = true,
|
|
212
|
+ IgnorePressure = false
|
|
213
|
+ };
|
|
214
|
+
|
|
215
|
+ //blackboard_canvas.Strokes = new StrokeCollection();
|
|
216
|
+ strokes = new Stroke(stylusPoints);
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+ strokes.DrawingAttributes = drawing;
|
|
220
|
+ //blackboard_canvas.Strokes.Add(strokes);
|
|
221
|
+
|
|
222
|
+ blackboard_canvas.Strokes.Add(strokes);
|
|
223
|
+ isFirst = false;
|
|
224
|
+ }
|
|
225
|
+ }
|
|
226
|
+ else
|
|
227
|
+ {
|
|
228
|
+ if (blackboard_canvas.Strokes.Count > 0)
|
|
229
|
+ {
|
|
230
|
+ stylusPoint.X = testX;
|
|
231
|
+ stylusPoint.Y = testY;
|
|
232
|
+ stylusPoints.Add(stylusPoint);
|
|
233
|
+ strokes = new Stroke(stylusPoints);
|
|
234
|
+ drawing = new DrawingAttributes
|
|
235
|
+ {
|
|
236
|
+ Color = Colour,
|
|
237
|
+ Width = Wit * 4.5,
|
|
238
|
+ Height = Wit * 4.5,
|
|
239
|
+ FitToCurve = true,
|
|
240
|
+ IgnorePressure = false
|
|
241
|
+ };
|
|
242
|
+ strokes.DrawingAttributes = drawing;
|
|
243
|
+
|
|
244
|
+ //viewModel.InkStrokes.Add(strokes);
|
|
245
|
+ blackboard_canvas.Strokes[blackboard_canvas.Strokes.Count - 1] = strokes;
|
|
246
|
+ }
|
|
247
|
+ }
|
|
248
|
+
|
|
249
|
+ //设置鼠标位置
|
|
250
|
+ if (testX > 0 && testY > 0)
|
|
251
|
+ {
|
|
252
|
+ //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
|
|
253
|
+ SetCursorPos((int)((float)testX * (PrimaryScreen.DpiX / 96f)), (int)((float)testY * (PrimaryScreen.DpiY / 96f)));
|
|
254
|
+ }
|
|
255
|
+ }));
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+ bool isFirst = true;
|
|
262
|
+ private StylusPointCollection stylusPoints = new StylusPointCollection();
|
|
263
|
+ private StylusPoint stylusPoint = new StylusPoint();
|
|
264
|
+ private Stroke strokes;
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+ /// <summary>
|
|
269
|
+ /// 抬笔
|
|
270
|
+ /// </summary>
|
|
271
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
272
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
273
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
274
|
+ private void OnPenUp(ulong time, string penSerial, int penType)
|
|
275
|
+ {
|
|
276
|
+ if (CheckAccess())
|
|
277
|
+ {
|
|
278
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
|
|
279
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
280
|
+ }
|
|
281
|
+ else
|
|
282
|
+ {
|
|
283
|
+ isPenDown = false;
|
|
284
|
+ APP.PenSerial = penSerial;
|
|
285
|
+
|
|
286
|
+ stroke.Clear();
|
|
287
|
+ }
|
|
288
|
+ //if (APP.pageData.currpage > 0)
|
|
289
|
+ //{
|
|
290
|
+ // Dispatcher.Invoke(new Action(() =>
|
|
291
|
+ // {
|
|
292
|
+ // myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
|
|
293
|
+ // }));
|
|
294
|
+ //}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+ if (strokes != null && strokes.StylusPoints.Count > 1)
|
|
298
|
+ {
|
|
299
|
+ isFirst = true;
|
|
300
|
+ }
|
|
301
|
+ stylusPoints = new StylusPointCollection();
|
|
302
|
+ stylusPoint = new StylusPoint();
|
|
303
|
+ strokes = null;
|
|
304
|
+ }
|
|
305
|
+ /// <summary>
|
|
306
|
+ /// 落笔
|
|
307
|
+ /// </summary>
|
|
308
|
+ /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
|
|
309
|
+ /// <param name="penSerial">点阵笔序列号</param>
|
|
310
|
+ /// <param name="penType">点阵笔型号编号</param>
|
|
311
|
+ private void OnPenDown(ulong time, string penSerial, int penType)
|
|
312
|
+ {
|
|
313
|
+ if (CheckAccess())
|
|
314
|
+ {
|
|
315
|
+ Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
|
|
316
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
|
|
317
|
+ }
|
|
318
|
+ else
|
|
319
|
+ {
|
|
320
|
+ isPenDown = true;
|
|
321
|
+ APP.W_ScreenRecordingToolbarWindow.PenPractice();
|
|
322
|
+ }
|
|
323
|
+ }
|
|
324
|
+ /// <summary>
|
|
325
|
+ /// 电池电量
|
|
326
|
+ /// </summary>
|
|
327
|
+ /// <param name="time"></param>
|
|
328
|
+ /// <param name="penSerial"></param>
|
|
329
|
+ /// <param name="penType"></param>
|
|
330
|
+ /// <param name="capacity"></param>
|
|
331
|
+ private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
|
|
332
|
+ {
|
|
333
|
+ if (CheckAccess())
|
|
334
|
+ {
|
|
335
|
+ Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
|
|
336
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
|
|
337
|
+ }
|
|
338
|
+ else
|
|
339
|
+ {
|
|
340
|
+ //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
|
|
341
|
+ }
|
|
342
|
+ }
|
|
343
|
+ /// <summary>
|
|
344
|
+ /// 已用存储
|
|
345
|
+ /// </summary>
|
|
346
|
+ /// <param name="time"></param>
|
|
347
|
+ /// <param name="penSerial"></param>
|
|
348
|
+ /// <param name="penType"></param>
|
|
349
|
+ /// <param name="fillLevel"></param>
|
|
350
|
+ private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
|
|
351
|
+ {
|
|
352
|
+ if (CheckAccess())
|
|
353
|
+ {
|
|
354
|
+ Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
|
|
355
|
+ Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
|
|
356
|
+ }
|
|
357
|
+ else
|
|
358
|
+ {
|
|
359
|
+ //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
|
|
360
|
+ }
|
|
361
|
+ }
|
|
362
|
+ /// <summary>
|
|
363
|
+ /// 退出批注
|
|
364
|
+ /// </summary>
|
|
365
|
+ /// <param name="sender"></param>
|
|
366
|
+ /// <param name="e"></param>
|
|
367
|
+ private void blackboard_canvas_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
|
368
|
+ {
|
|
369
|
+ ReturnPractice();
|
|
370
|
+ SwitchPages();
|
|
371
|
+ }
|
|
372
|
+ /// <summary>
|
|
373
|
+ /// 退出批注并清空画板
|
|
374
|
+ /// </summary>
|
|
375
|
+ public void ReturnPractice()
|
|
376
|
+ {
|
|
377
|
+ blackboard_canvas.Strokes.Clear();
|
|
378
|
+ new Thread(new ThreadStart(new Action(() =>
|
|
379
|
+ {
|
|
380
|
+
|
|
381
|
+ Thread.Sleep(500);
|
|
382
|
+ Dispatcher.Invoke(() =>
|
|
383
|
+ {
|
|
384
|
+ Owner = null;
|
|
385
|
+ APP.W_PracticeWindow.Hide();
|
|
386
|
+ });
|
|
387
|
+ }))).Start();
|
|
388
|
+ }
|
|
389
|
+ /// <summary>
|
|
390
|
+ /// 鼠标中建点击
|
|
391
|
+ /// </summary>
|
|
392
|
+ void SwitchPages()
|
|
393
|
+ {
|
|
394
|
+ try
|
|
395
|
+ {
|
|
396
|
+ new Thread(() =>
|
|
397
|
+ {
|
|
398
|
+ Thread.Sleep(500);
|
|
399
|
+ MouseEventCommon.MouseMiddleClickEvent(0);
|
|
400
|
+ }).Start();
|
|
401
|
+ }
|
|
402
|
+ catch (Exception ex)
|
|
403
|
+ {
|
|
404
|
+ MessageBox.Show(ex.Message);
|
|
405
|
+ }
|
|
406
|
+ }
|
|
407
|
+ }
|
|
408
|
+}
|