星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PracticeWindow.xaml.cs 31KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Ink;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using XHWK.Model;
  11. namespace XHWK.WKTool
  12. {
  13. /// <summary>
  14. /// 录屏画板
  15. /// </summary>
  16. public partial class PracticeWindow : Window
  17. {
  18. //声明一个 DrawingAttributes 类型的变量
  19. private DrawingAttributes drawingAttributes;
  20. private DrawingAttributes drawing;
  21. private ViewModel viewModel;
  22. /// <summary>
  23. /// 0 画笔 1 矩形 2 圆形
  24. /// </summary>
  25. private int flg = 0;
  26. /// <summary>
  27. /// 当前画笔颜色
  28. /// </summary>
  29. private Color Colour = Colors.Red;
  30. /// <summary>
  31. /// 当前画笔宽
  32. /// </summary>
  33. private int Wit = 2;
  34. /// <summary>
  35. /// 当前画笔高
  36. /// </summary>
  37. private int Hei = 2;
  38. public PracticeWindow()
  39. {
  40. InitializeComponent();
  41. InitTQLPPen();
  42. }
  43. public void Initialize(string _imgPath = null)
  44. {
  45. flg = 0;
  46. blackboard_canvas.Strokes.Clear();
  47. blackboard_canvas.UseCustomCursor = true;
  48. //blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
  49. //加背景 废弃更利于讲解ppt
  50. //if (File.Exists(_imgPath))
  51. //{
  52. // imgCanvas.Source = new BitmapImage(new Uri(_imgPath));
  53. //}
  54. //创建 DrawingAttributes 类的一个实例
  55. drawingAttributes = new DrawingAttributes();
  56. //drawingAttributes.StylusTip = StylusTip.Rectangle;
  57. //drawingAttributes.IsHighlighter = false;
  58. //drawingAttributes.IgnorePressure = true;
  59. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  60. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  61. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  62. Pen();
  63. //blackboard_canvas.Cursor = Cursors.Pen;
  64. //Cursor cus = new Cursor(@"G:\06.cur");
  65. //blackboard_canvas.Cursor = cus;
  66. viewModel = new ViewModel
  67. {
  68. InkStrokes = new StrokeCollection(),
  69. };
  70. DataContext = viewModel;
  71. //APP.W_ScreenRecordingToolbarWindow.Owner = this;
  72. //APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  73. }
  74. /// <summary>
  75. /// 画笔颜色事件 白色
  76. /// </summary>
  77. /// <param name="sender"></param>
  78. /// <param name="e"></param>
  79. public void White()
  80. {
  81. //flg = 0;
  82. drawingAttributes.Color = Colors.White;
  83. Colour = Colors.White;
  84. }
  85. /// <summary>
  86. /// 画笔颜色事件 红色
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. public void Red()
  91. {
  92. drawingAttributes.Color = Colors.Red;
  93. Colour = Colors.Red;
  94. }
  95. /// <summary>
  96. /// 画笔颜色事件 黑色
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. public void Gray()
  101. {
  102. //flg = 0;
  103. drawingAttributes.Color = Colors.Black;
  104. Colour = Colors.Black;
  105. }
  106. /// <summary>
  107. /// 画笔颜色事件 青色
  108. /// </summary>
  109. /// <param name="sender"></param>
  110. /// <param name="e"></param>
  111. public void CyanBlue()
  112. {
  113. //flg = 0;
  114. drawingAttributes.Color = Colors.LimeGreen;
  115. Colour = Colors.LimeGreen;
  116. }
  117. /// <summary>
  118. /// 画笔颜色事件 黄色
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. public void Yellow()
  123. {
  124. //flg = 0;
  125. drawingAttributes.Color = Colors.Gold;
  126. Colour = Colors.Gold;
  127. }
  128. /// <summary>
  129. /// 画笔颜色事件 蓝色
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. public void Blue()
  134. {
  135. //flg = 0;
  136. drawingAttributes.Color = Colors.DeepSkyBlue;
  137. Colour = Colors.DeepSkyBlue;
  138. }
  139. /// <summary>
  140. /// 画笔粗细事件 细
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. public void Fine()
  145. {
  146. //flg = 0;
  147. drawingAttributes.Width = 1;
  148. drawingAttributes.Height = 1;
  149. Wit = 1;
  150. Hei = 1;
  151. }
  152. /// <summary>
  153. /// 画笔粗细事件 中
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. public void In()
  158. {
  159. //flg = 0;
  160. drawingAttributes.Width = 3;
  161. drawingAttributes.Height = 3;
  162. Wit = 3;
  163. Hei = 3;
  164. }
  165. /// <summary>
  166. /// 画笔粗细事件 粗
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. public void Crude()
  171. {
  172. //flg = 0;
  173. drawingAttributes.Width = 5;
  174. drawingAttributes.Height = 5;
  175. Wit = 5;
  176. Hei = 5;
  177. }
  178. /// <summary>
  179. /// 橡皮
  180. /// </summary>
  181. public void Eraser()
  182. {
  183. flg = 0;
  184. //this.type = ZPenType.Erase;
  185. blackboard_canvas.UseCustomCursor = false;
  186. blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
  187. blackboard_canvas.EraserShape = new EllipseStylusShape(64, 64, 0);
  188. }
  189. /// <summary>
  190. /// 画笔
  191. /// </summary>
  192. public void Pen()
  193. {
  194. flg = 0;
  195. blackboard_canvas.EditingMode = InkCanvasEditingMode.Ink;
  196. blackboard_canvas.UseCustomCursor = true;
  197. drawingAttributes.FitToCurve = true;
  198. drawingAttributes.IgnorePressure = false;
  199. blackboard_canvas.Cursor = Cursors.Pen;
  200. }
  201. /// <summary>
  202. /// 圆
  203. /// </summary>
  204. public void Round()
  205. {
  206. flg = 2;
  207. drawingAttributes = new DrawingAttributes
  208. {
  209. Color = Colour,
  210. Width = Wit,
  211. Height = Hei,
  212. StylusTip = StylusTip.Rectangle,
  213. //FitToCurve = true,
  214. IsHighlighter = false,
  215. IgnorePressure = true,
  216. };
  217. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  218. blackboard_canvas.EditingMode = InkCanvasEditingMode.None;
  219. blackboard_canvas.Cursor = Cursors.Cross;
  220. }
  221. /// <summary>
  222. /// 矩形
  223. /// </summary>
  224. public void Rectangle()
  225. {
  226. flg = 1;
  227. drawingAttributes = new DrawingAttributes
  228. {
  229. Color = Colour,
  230. Width = Wit,
  231. Height = Hei,
  232. StylusTip = StylusTip.Rectangle,
  233. //FitToCurve = true,
  234. IsHighlighter = false,
  235. IgnorePressure = true,
  236. };
  237. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  238. blackboard_canvas.EditingMode = InkCanvasEditingMode.None;
  239. blackboard_canvas.Cursor = Cursors.Cross;
  240. }
  241. private System.Windows.Point iniP;
  242. private void blackboard_canvas_MouseDown(object sender, MouseButtonEventArgs e)
  243. {
  244. if (flg != 0)
  245. {
  246. if (e.LeftButton == MouseButtonState.Pressed)
  247. {
  248. iniP = e.GetPosition(blackboard_canvas);
  249. }
  250. }
  251. }
  252. private Stroke StrokeRound;
  253. private Stroke StrokeRectangle;
  254. private void blackboard_canvas_MouseMove(object sender, MouseEventArgs e)
  255. {
  256. if (flg != 0)
  257. {
  258. if (e.LeftButton == MouseButtonState.Pressed)
  259. {
  260. // Draw square
  261. if (flg == 1)
  262. {
  263. System.Windows.Point endP = e.GetPosition(blackboard_canvas);
  264. List<System.Windows.Point> pointList = new List<System.Windows.Point>
  265. {
  266. new System.Windows.Point(iniP.X, iniP.Y),
  267. new System.Windows.Point(iniP.X, endP.Y),
  268. new System.Windows.Point(endP.X, endP.Y),
  269. new System.Windows.Point(endP.X, iniP.Y),
  270. new System.Windows.Point(iniP.X, iniP.Y),
  271. };
  272. //Stroke stroke1 = new Stroke(drawingAttributesRound);
  273. StylusPointCollection point = new StylusPointCollection(pointList);
  274. Stroke stroke = new Stroke(point)
  275. {
  276. DrawingAttributes = blackboard_canvas.DefaultDrawingAttributes.Clone()
  277. };
  278. if (StrokeRectangle != null)
  279. {
  280. viewModel.InkStrokes.Remove(StrokeRectangle);
  281. }
  282. StrokeRectangle = stroke;
  283. viewModel.InkStrokes.Add(stroke);
  284. }
  285. // Draw Eclipse
  286. else if (flg == 2)
  287. {
  288. System.Windows.Point endP = e.GetPosition(blackboard_canvas);
  289. List<System.Windows.Point> pointList = GenerateEclipseGeometry(iniP, endP);
  290. StylusPointCollection point = new StylusPointCollection(pointList);
  291. Stroke stroke = new Stroke(point)
  292. {
  293. DrawingAttributes = blackboard_canvas.DefaultDrawingAttributes.Clone()
  294. };
  295. //viewModel.InkStrokes.Clear();
  296. if (StrokeRound != null)
  297. {
  298. viewModel.InkStrokes.Remove(StrokeRound);
  299. }
  300. StrokeRound = stroke;
  301. viewModel.InkStrokes.Add(stroke);
  302. }
  303. }
  304. }
  305. }
  306. private List<System.Windows.Point> GenerateEclipseGeometry(System.Windows.Point st, System.Windows.Point ed)
  307. {
  308. double a = 0.5 * (ed.X - st.X);
  309. double b = 0.5 * (ed.Y - st.Y);
  310. List<System.Windows.Point> pointList = new List<System.Windows.Point>();
  311. for (double r = 0; r <= 2 * Math.PI; r = r + 0.01)
  312. {
  313. pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
  314. }
  315. return pointList;
  316. }
  317. /// <summary>
  318. /// 鼠标松开时
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void blackboard_canvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  323. {
  324. StrokeRound = null;
  325. StrokeRectangle = null;
  326. }
  327. /// <summary>
  328. /// 鼠标右键
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  333. {
  334. if (APP.W_ScreenRecordingToolbarWindow.flg == 10)
  335. {
  336. APP.W_ScreenRecordingToolbarWindow.flg = 0;
  337. }
  338. else
  339. {
  340. APP.W_ScreenRecordingToolbarWindow.flg = 1;
  341. }
  342. Hide();
  343. }
  344. /// <summary>
  345. /// 鼠标中键点击
  346. /// </summary>
  347. private void SwitchPages()
  348. {
  349. try
  350. {
  351. new Thread(() =>
  352. {
  353. Thread.Sleep(500);
  354. MouseEventCommon.MouseMiddleClickEvent(0);
  355. }).Start();
  356. }
  357. catch (Exception ex)
  358. {
  359. MessageBox.Show(ex.Message);
  360. }
  361. }
  362. private void blackboard_canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  363. {
  364. if (APP.W_ScreenRecordingToolbarWindow.flg == 10)
  365. {
  366. APP.W_ScreenRecordingToolbarWindow.flg = 0;
  367. }
  368. else
  369. {
  370. APP.W_ScreenRecordingToolbarWindow.flg = 1;
  371. }
  372. Hide();
  373. }
  374. private void blackboard_canvas_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  375. {
  376. if (APP.W_ScreenRecordingToolbarWindow.flg == 10)
  377. {
  378. APP.W_ScreenRecordingToolbarWindow.flg = 0;
  379. }
  380. else
  381. {
  382. APP.W_ScreenRecordingToolbarWindow.flg = 1;
  383. }
  384. ReturnPractice();
  385. //模拟切到ppt
  386. SwitchPages();
  387. //Hide();
  388. }
  389. /// <summary>
  390. /// 退出批注并清空画板
  391. /// </summary>
  392. public void ReturnPractice()
  393. {
  394. blackboard_canvas.Strokes.Clear();
  395. new Thread(new ThreadStart(new Action(() =>
  396. {
  397. Dispatcher.Invoke(() =>
  398. {
  399. APP.W_ScreenRecordingToolbarWindow.ModifyState();
  400. });
  401. flg = 0;
  402. Thread.Sleep(500);
  403. Dispatcher.Invoke(() =>
  404. {
  405. Owner = null;
  406. APP.W_PracticeWindow.Hide();
  407. });
  408. }))).Start();
  409. }
  410. #region 点阵笔相关
  411. #region 值初始化
  412. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  413. /// <summary>
  414. /// A4点阵纸点阵宽度
  415. /// </summary>
  416. private const int A4_WIDTH = 5600;
  417. /// <summary>
  418. /// A4点阵纸点阵高度
  419. /// </summary>
  420. private const int A4_HEIGHT = 7920;
  421. ///// <summary>
  422. ///// 画板
  423. ///// </summary>
  424. //private Graphics graphics;
  425. /// <summary>
  426. /// 笔画坐标数组
  427. /// </summary>
  428. private List<System.Drawing.Point> stroke;
  429. /// <summary>
  430. /// 笔序列号
  431. /// </summary>
  432. private string penSerial;
  433. /// <summary>
  434. /// 笔是否在点
  435. /// </summary>
  436. private bool isPenDown;
  437. #endregion 值初始化
  438. /// <summary>
  439. /// 落笔
  440. /// </summary>
  441. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  442. /// <param name="penSerial">点阵笔序列号</param>
  443. /// <param name="penType">点阵笔型号编号</param>
  444. private void OnPenDown(ulong time, string penSerial, int penType)
  445. {
  446. if (CheckAccess())
  447. {
  448. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  449. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  450. }
  451. else
  452. {
  453. isPenDown = true;
  454. APP.W_ScreenRecordingToolbarWindow.PenPractice();
  455. }
  456. }
  457. /// <summary>
  458. /// 抬笔
  459. /// </summary>
  460. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  461. /// <param name="penSerial">点阵笔序列号</param>
  462. /// <param name="penType">点阵笔型号编号</param>
  463. private void OnPenUp(ulong time, string penSerial, int penType)
  464. {
  465. if (CheckAccess())
  466. {
  467. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  468. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  469. }
  470. else
  471. {
  472. isPenDown = false;
  473. APP.PenSerial = penSerial;
  474. stroke.Clear();
  475. }
  476. if (strokes != null && strokes.StylusPoints.Count > 1)
  477. {
  478. isFirst = true;
  479. }
  480. stylusPoints = new StylusPointCollection();
  481. stylusPoint = new StylusPoint();
  482. strokes = null;
  483. }
  484. /// <summary>
  485. /// 笔断开
  486. /// </summary>
  487. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  488. /// <param name="penSerial">点阵笔序列号</param>
  489. /// <param name="penType">点阵笔型号编号</param>
  490. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  491. {
  492. if (CheckAccess())
  493. {
  494. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  495. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  496. }
  497. else
  498. {
  499. APP.PenSerial = penSerial;
  500. APP.PenStatus = false;
  501. //UpdateDevStatus();
  502. ////Dispatcher.Invoke(new Action(() =>
  503. ////{
  504. //// txbNotConnected.Text = "未连接";
  505. //// txbNotConnecteds.Text = "未连接";
  506. ////}));
  507. }
  508. }
  509. /// <summary>
  510. /// 笔连接
  511. /// </summary>
  512. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  513. /// <param name="penSerial">点阵笔序列号</param>
  514. /// <param name="penType">点阵笔型号编号</param>
  515. private void OnPenConnect(ulong time, string penSerial, int penType)
  516. {
  517. if (CheckAccess())
  518. {
  519. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  520. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  521. }
  522. else
  523. {
  524. APP.PenSerial = penSerial;
  525. APP.PenStatus = true;
  526. this.penSerial = penSerial;
  527. }
  528. }
  529. /// <summary>
  530. /// 电池电量
  531. /// </summary>
  532. /// <param name="time"></param>
  533. /// <param name="penSerial"></param>
  534. /// <param name="penType"></param>
  535. /// <param name="capacity"></param>
  536. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  537. {
  538. if (CheckAccess())
  539. {
  540. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  541. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  542. }
  543. else
  544. {
  545. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  546. }
  547. }
  548. /// <summary>
  549. /// 已用存储
  550. /// </summary>
  551. /// <param name="time"></param>
  552. /// <param name="penSerial"></param>
  553. /// <param name="penType"></param>
  554. /// <param name="fillLevel"></param>
  555. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  556. {
  557. if (CheckAccess())
  558. {
  559. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  560. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  561. }
  562. else
  563. {
  564. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  565. }
  566. }
  567. /// <summary>
  568. /// 笔书写,收到坐标
  569. /// </summary>
  570. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  571. /// <param name="penSerial">点阵笔序列号</param>
  572. /// <param name="penType">点阵笔型号编号</param>
  573. /// <param name="pageSerial">点阵地址</param>
  574. /// <param name="cx">x坐标</param>
  575. /// <param name="cy">y坐标</param>
  576. /// <param name="force">压力值</param>
  577. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  578. {
  579. if (this.Visibility == Visibility.Visible)
  580. {
  581. if (CheckAccess())
  582. {
  583. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  584. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  585. }
  586. else
  587. {
  588. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  589. if (!isPenDown)
  590. {
  591. return;
  592. }
  593. stroke.Add(new System.Drawing.Point(cx, cy));
  594. double PropW = blackboard_canvas.ActualWidth / A4_HEIGHT;
  595. double PropH = blackboard_canvas.ActualHeight / A4_WIDTH;
  596. //点
  597. double testX = cy * PropW;
  598. double testY = (A4_WIDTH - cx) * PropH;
  599. //pageSerial //点阵IP地址 与打印的页面关联
  600. if (true)
  601. {
  602. Dispatcher.Invoke(new Action(() =>
  603. {
  604. float Pressure = force / 100f;
  605. ////添加笔画
  606. //myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
  607. if (isFirst)
  608. {
  609. stylusPoint.X = testX;
  610. stylusPoint.Y = testY;
  611. //_color.A = (byte)(Pressure * 255f);
  612. //stylusPoint.PressureFactor = Pressure;
  613. //for(int i=0;i<100;i++)
  614. //{
  615. // stylusPoint.X--;
  616. // stylusPoint.Y--;
  617. // stylusPoints.Add(stylusPoint);
  618. //}
  619. stylusPoints.Add(stylusPoint);
  620. if (stylusPoints.Count > 1)
  621. {
  622. drawing = new DrawingAttributes
  623. {
  624. Color = Colour,
  625. Width = Wit * 4.5,
  626. Height = Wit * 4.5,
  627. FitToCurve = true,
  628. IgnorePressure = false
  629. };
  630. //blackboard_canvas.Strokes = new StrokeCollection();
  631. strokes = new Stroke(stylusPoints);
  632. strokes.DrawingAttributes = drawing;
  633. //blackboard_canvas.Strokes.Add(strokes);
  634. blackboard_canvas.Strokes.Add(strokes);
  635. isFirst = false;
  636. }
  637. }
  638. else
  639. {
  640. if (blackboard_canvas.Strokes.Count > 0)
  641. {
  642. stylusPoint.X = testX;
  643. stylusPoint.Y = testY;
  644. stylusPoints.Add(stylusPoint);
  645. strokes = new Stroke(stylusPoints);
  646. drawing = new DrawingAttributes
  647. {
  648. Color = Colour,
  649. Width = Wit * 4.5,
  650. Height = Wit * 4.5,
  651. FitToCurve = true,
  652. IgnorePressure = false
  653. };
  654. strokes.DrawingAttributes = drawing;
  655. //viewModel.InkStrokes.Add(strokes);
  656. blackboard_canvas.Strokes[blackboard_canvas.Strokes.Count - 1] = strokes;
  657. }
  658. }
  659. //设置鼠标位置
  660. if (testX > 0 && testY > 0)
  661. {
  662. //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  663. SetCursorPos((int)((float)testX * (PrimaryScreen.DpiX / 96f)), (int)((float)testY * (PrimaryScreen.DpiY / 96f)));
  664. }
  665. }));
  666. }
  667. }
  668. }
  669. }
  670. private bool isFirst = true;
  671. private StylusPointCollection stylusPoints = new StylusPointCollection();
  672. private StylusPoint stylusPoint = new StylusPoint();
  673. private Stroke strokes;
  674. /// <summary>
  675. /// 引用user32.dll动态链接库(windows api),
  676. /// 使用库中定义 API:SetCursorPos
  677. /// 设置光标位置
  678. /// </summary>
  679. [System.Runtime.InteropServices.DllImport("user32.dll")]
  680. private static extern int SetCursorPos(int x, int y);
  681. #endregion 点阵笔相关
  682. #region 腾千里手写笔
  683. /// <summary>
  684. /// 是否在书写
  685. /// </summary>
  686. private bool isTQLPenDown = false;
  687. /// <summary>
  688. /// TQL点阵笔宽高
  689. /// </summary>
  690. //static float TQLA4_WIDTH = (float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  691. //static float TQLA4_HEIGHT = (float)1512 / (float)150 * (float)25.4 / (float)1.524;
  692. private static float TQLA4_WIDTH = (float)2480 / (float)300 * (float)25.4 / (float)1.524;
  693. private static float TQLA4_HEIGHT = (float)3509 / (float)300 * (float)25.4 / (float)1.524;
  694. /// <summary>
  695. /// 初始化
  696. /// </summary>
  697. public void InitTQLPPen()
  698. {
  699. if (APP.TQLPenevents == null)
  700. {
  701. APP.TQLPenevents = new PenEvents(2);
  702. }
  703. else
  704. {
  705. APP.TQLPenevents.InToType = 2;
  706. }
  707. }
  708. /// <summary>
  709. /// 笔落下
  710. /// </summary>
  711. public void TQLDown()
  712. {
  713. isTQLPenDown = true;
  714. APP.W_ScreenRecordingToolbarWindow.PenPractice();
  715. if (strokes != null && strokes.StylusPoints.Count > 1)
  716. {
  717. isFirst = true;
  718. }
  719. stylusPoints = new StylusPointCollection();
  720. stylusPoint = new StylusPoint();
  721. strokes = null;
  722. }
  723. /// <summary>
  724. /// 笔抬起
  725. /// </summary>
  726. public void TQLUp()
  727. {
  728. isTQLPenDown = false;
  729. if (strokes != null && strokes.StylusPoints.Count > 1)
  730. {
  731. isFirst = true;
  732. }
  733. stylusPoints = new StylusPointCollection();
  734. stylusPoint = new StylusPoint();
  735. strokes = null;
  736. }
  737. /// <summary>
  738. /// 笔书写
  739. /// </summary>
  740. /// <param name="cx"></param>
  741. /// <param name="cy"></param>
  742. /// <param name="force"></param>
  743. public void TQLPenWrite(double cx, double cy, int force)
  744. {
  745. if (this.Visibility == Visibility.Visible)
  746. {
  747. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  748. if (!isTQLPenDown)
  749. {
  750. return;
  751. }
  752. double PropW = blackboard_canvas.ActualWidth / TQLA4_HEIGHT;
  753. double PropH = blackboard_canvas.ActualHeight / TQLA4_WIDTH;
  754. double tempX = cy * PropW;
  755. double tempY = (TQLA4_WIDTH - cx) * PropH;
  756. Dispatcher.Invoke(new Action(() =>
  757. {
  758. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  759. float Pressure = (float)force / 1023f;
  760. //添加笔画
  761. if (isFirst)
  762. {
  763. stylusPoint.X = tempX;
  764. stylusPoint.Y = tempY;
  765. stylusPoints.Add(stylusPoint);
  766. if (stylusPoints.Count > 1)
  767. {
  768. drawing = new DrawingAttributes
  769. {
  770. Color = Colour,
  771. Width = Wit * 4.5,
  772. Height = Wit * 4.5,
  773. FitToCurve = true,
  774. IgnorePressure = false
  775. };
  776. strokes = new Stroke(stylusPoints);
  777. strokes.DrawingAttributes = drawing;
  778. blackboard_canvas.Strokes.Add(strokes);
  779. isFirst = false;
  780. }
  781. }
  782. else
  783. {
  784. if (blackboard_canvas.Strokes.Count > 0)
  785. {
  786. stylusPoint.X = tempX;
  787. stylusPoint.Y = tempY;
  788. stylusPoints.Add(stylusPoint);
  789. strokes = new Stroke(stylusPoints);
  790. drawing = new DrawingAttributes
  791. {
  792. Color = Colour,
  793. Width = Wit * 4.5,
  794. Height = Wit * 4.5,
  795. FitToCurve = true,
  796. IgnorePressure = false
  797. };
  798. strokes.DrawingAttributes = drawing;
  799. //viewModel.InkStrokes.Add(strokes);
  800. blackboard_canvas.Strokes[blackboard_canvas.Strokes.Count - 1] = strokes;
  801. }
  802. }
  803. //设置鼠标位置
  804. if (tempX > 0 && tempY > 0)
  805. {
  806. //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  807. SetCursorPos((int)((float)tempX * (PrimaryScreen.DpiX / 96f)), (int)((float)tempY * (PrimaryScreen.DpiY / 96f)));
  808. }
  809. }));
  810. }
  811. }
  812. #endregion 腾千里手写笔
  813. }
  814. }