星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PracticeWindow.xaml.cs 15KB

11 months ago
4 years ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
4 years ago
11 months ago
4 years ago
4 years ago
11 months ago
4 years ago
4 years ago
4 years ago
4 years ago
11 months ago
11 months ago
4 years ago
11 months ago
11 months ago
4 years ago
11 months ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
4 years ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
4 years ago
11 months ago
4 years ago
4 years ago
11 months ago
11 months ago
4 years ago
4 years ago
11 months ago
11 months ago
11 months ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. using Common.system;
  2. using System;
  3. using System.Threading;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Ink;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using XHWK.Model;
  10. namespace XHWK.WKTool
  11. {
  12. /// <summary>
  13. /// 录屏画板
  14. /// </summary>
  15. public partial class PracticeWindow
  16. {
  17. //声明一个 DrawingAttributes 类型的变量
  18. private DrawingAttributes _drawingAttributes;
  19. private DrawingAttributes _drawing;
  20. private ViewModel _viewModel;
  21. /// <summary>
  22. /// 0 画笔 1 矩形 2 圆形
  23. /// </summary>
  24. #pragma warning disable CS0414
  25. private int _flg;
  26. #pragma warning restore CS0414
  27. /// <summary>
  28. /// 当前画笔颜色
  29. /// </summary>
  30. private Color _colour = Colors.Red;
  31. /// <summary>
  32. /// 当前画笔宽
  33. /// </summary>
  34. private int _wit = 2;
  35. /// <summary>
  36. /// 当前画笔高
  37. /// </summary>
  38. private int _hei = 2;
  39. public PracticeWindow()
  40. {
  41. InitializeComponent();
  42. InitTqlpPen();
  43. }
  44. public void Initialize(string imgPath = null)
  45. {
  46. _flg = 0;
  47. BlackboardCanvas.Strokes.Clear();
  48. BlackboardCanvas.UseCustomCursor = true;
  49. //blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
  50. //加背景 废弃更利于讲解ppt
  51. //if (File.Exists(_imgPath))
  52. //{
  53. // imgCanvas.Source = new BitmapImage(new Uri(_imgPath));
  54. //}
  55. //创建 DrawingAttributes 类的一个实例
  56. _drawingAttributes = new DrawingAttributes();
  57. //drawingAttributes.StylusTip = StylusTip.Rectangle;
  58. //drawingAttributes.IsHighlighter = false;
  59. //drawingAttributes.IgnorePressure = true;
  60. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  61. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  62. BlackboardCanvas.DefaultDrawingAttributes = _drawingAttributes;
  63. Pen();
  64. //blackboard_canvas.Cursor = Cursors.Pen;
  65. //Cursor cus = new Cursor(@"G:\06.cur");
  66. //blackboard_canvas.Cursor = cus;
  67. _viewModel = new ViewModel { InkStrokes = new StrokeCollection(), };
  68. DataContext = _viewModel;
  69. //APP.W_ScreenRecordingToolbarWindow.Owner = this;
  70. //APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  71. }
  72. /// <summary>
  73. /// 画笔颜色事件 白色
  74. /// </summary>
  75. public void White()
  76. {
  77. //flg = 0;
  78. _drawingAttributes.Color = Colors.White;
  79. _colour = Colors.White;
  80. }
  81. /// <summary>
  82. /// 画笔颜色事件 红色
  83. /// </summary>
  84. public void Red()
  85. {
  86. _drawingAttributes.Color = Colors.Red;
  87. _colour = Colors.Red;
  88. }
  89. /// <summary>
  90. /// 画笔颜色事件 黑色
  91. /// </summary>
  92. public void Gray()
  93. {
  94. //flg = 0;
  95. _drawingAttributes.Color = Colors.Black;
  96. _colour = Colors.Black;
  97. }
  98. /// <summary>
  99. /// 画笔颜色事件 青色
  100. /// </summary>
  101. public void CyanBlue()
  102. {
  103. //flg = 0;
  104. _drawingAttributes.Color = Colors.LimeGreen;
  105. _colour = Colors.LimeGreen;
  106. }
  107. /// <summary>
  108. /// 画笔颜色事件 黄色
  109. /// </summary>
  110. public void Yellow()
  111. {
  112. //flg = 0;
  113. _drawingAttributes.Color = Colors.Gold;
  114. _colour = Colors.Gold;
  115. }
  116. /// <summary>
  117. /// 画笔颜色事件 蓝色
  118. /// </summary>
  119. public void Blue()
  120. {
  121. //flg = 0;
  122. _drawingAttributes.Color = Colors.DeepSkyBlue;
  123. _colour = Colors.DeepSkyBlue;
  124. }
  125. /// <summary>
  126. /// 画笔粗细事件 细
  127. /// </summary>
  128. public void Fine()
  129. {
  130. //flg = 0;
  131. _drawingAttributes.Width = 1;
  132. _drawingAttributes.Height = 1;
  133. _wit = 1;
  134. _hei = 1;
  135. }
  136. /// <summary>
  137. /// 画笔粗细事件 中
  138. /// </summary>
  139. public void In()
  140. {
  141. //flg = 0;
  142. _drawingAttributes.Width = 3;
  143. _drawingAttributes.Height = 3;
  144. _wit = 3;
  145. _hei = 3;
  146. }
  147. /// <summary>
  148. /// 画笔粗细事件 粗
  149. /// </summary>
  150. public void Crude()
  151. {
  152. //flg = 0;
  153. _drawingAttributes.Width = 5;
  154. _drawingAttributes.Height = 5;
  155. _wit = 5;
  156. _hei = 5;
  157. }
  158. /// <summary>
  159. /// 橡皮
  160. /// </summary>
  161. public void Eraser()
  162. {
  163. _flg = 0;
  164. //this.type = ZPenType.Erase;
  165. BlackboardCanvas.UseCustomCursor = false;
  166. BlackboardCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
  167. BlackboardCanvas.EraserShape = new EllipseStylusShape(
  168. 64,
  169. 64,
  170. 0
  171. );
  172. }
  173. /// <summary>
  174. /// 画笔
  175. /// </summary>
  176. public void Pen()
  177. {
  178. _flg = 0;
  179. BlackboardCanvas.EditingMode = InkCanvasEditingMode.Ink;
  180. BlackboardCanvas.UseCustomCursor = true;
  181. _drawingAttributes.FitToCurve = true;
  182. _drawingAttributes.IgnorePressure = false;
  183. BlackboardCanvas.Cursor = Cursors.Pen;
  184. }
  185. /// <summary>
  186. /// 圆
  187. /// </summary>
  188. public void Round()
  189. {
  190. _flg = 2;
  191. _drawingAttributes = new DrawingAttributes
  192. {
  193. Color = _colour,
  194. Width = _wit,
  195. Height = _hei,
  196. StylusTip = StylusTip.Rectangle,
  197. //FitToCurve = true,
  198. IsHighlighter = false,
  199. IgnorePressure = true,
  200. };
  201. BlackboardCanvas.DefaultDrawingAttributes = _drawingAttributes;
  202. BlackboardCanvas.EditingMode = InkCanvasEditingMode.None;
  203. BlackboardCanvas.Cursor = Cursors.Cross;
  204. }
  205. /// <summary>
  206. /// 矩形
  207. /// </summary>
  208. public void Rectangle()
  209. {
  210. _flg = 1;
  211. _drawingAttributes = new DrawingAttributes
  212. {
  213. Color = _colour,
  214. Width = _wit,
  215. Height = _hei,
  216. StylusTip = StylusTip.Rectangle,
  217. //FitToCurve = true,
  218. IsHighlighter = false,
  219. IgnorePressure = true,
  220. };
  221. BlackboardCanvas.DefaultDrawingAttributes = _drawingAttributes;
  222. BlackboardCanvas.EditingMode = InkCanvasEditingMode.None;
  223. BlackboardCanvas.Cursor = Cursors.Cross;
  224. }
  225. /// <summary>
  226. /// 鼠标中键点击
  227. /// </summary>
  228. private void SwitchPages()
  229. {
  230. try
  231. {
  232. new Thread(
  233. () =>
  234. {
  235. Thread.Sleep(500);
  236. MouseEventCommon.MouseMiddleClickEvent(0);
  237. }
  238. ).Start();
  239. }
  240. catch (Exception ex)
  241. {
  242. MessageBox.Show(ex.Message);
  243. }
  244. }
  245. private void blackboard_canvas_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  246. {
  247. if (App.W_ScreenRecordingToolbarWindow.flg == 10)
  248. {
  249. App.W_ScreenRecordingToolbarWindow.flg = 0;
  250. }
  251. else
  252. {
  253. App.W_ScreenRecordingToolbarWindow.flg = 1;
  254. }
  255. ReturnPractice();
  256. //模拟切到ppt
  257. SwitchPages();
  258. //Hide();
  259. }
  260. /// <summary>
  261. /// 退出批注并清空画板
  262. /// </summary>
  263. public void ReturnPractice()
  264. {
  265. BlackboardCanvas.Strokes.Clear();
  266. new Thread(
  267. () =>
  268. {
  269. Dispatcher.Invoke(() => { App.W_ScreenRecordingToolbarWindow.ModifyState(); });
  270. _flg = 0;
  271. Thread.Sleep(500);
  272. Dispatcher.Invoke(
  273. () =>
  274. {
  275. Owner = null;
  276. App.W_PracticeWindow.Hide();
  277. }
  278. );
  279. }
  280. ).Start();
  281. }
  282. #region 点阵笔相关
  283. #region 值初始化
  284. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  285. ///// <summary>
  286. ///// 画板
  287. ///// </summary>
  288. //private Graphics graphics;
  289. #endregion 值初始化
  290. private bool _isFirst = true;
  291. private StylusPointCollection _stylusPoints = new StylusPointCollection();
  292. private StylusPoint _stylusPoint;
  293. private Stroke _strokes;
  294. /// <summary>
  295. /// 引用user32.dll动态链接库(windows api),
  296. /// 使用库中定义 API:SetCursorPos
  297. /// 设置光标位置
  298. /// </summary>
  299. [System.Runtime.InteropServices.DllImport("user32.dll")]
  300. private static extern int SetCursorPos(int x, int y);
  301. #endregion 点阵笔相关
  302. #region 腾千里手写笔
  303. /// <summary>
  304. /// 是否在书写
  305. /// </summary>
  306. private bool _isTqlPenDown;
  307. /// <summary>
  308. /// TQL点阵笔宽高
  309. /// </summary>
  310. //static float TQLA4_WIDTH = (float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  311. //static float TQLA4_HEIGHT = (float)1512 / (float)150 * (float)25.4 / (float)1.524;
  312. private const float TQLA4_WIDTH = 2480 / (float)300 * (float)25.4 / (float)1.524;
  313. private const float TQLA4_HEIGHT = 3509 / (float)300 * (float)25.4 / (float)1.524;
  314. /// <summary>
  315. /// 初始化
  316. /// </summary>
  317. public void InitTqlpPen()
  318. {
  319. if (App.TQLPenevents == null)
  320. {
  321. App.TQLPenevents = new PenEvents(2);
  322. }
  323. else
  324. {
  325. App.TQLPenevents.InToType = 2;
  326. }
  327. }
  328. /// <summary>
  329. /// 笔落下
  330. /// </summary>
  331. public void TqlDown()
  332. {
  333. _isTqlPenDown = true;
  334. App.W_ScreenRecordingToolbarWindow.PenPractice();
  335. if (_strokes != null && _strokes.StylusPoints.Count > 1)
  336. {
  337. _isFirst = true;
  338. }
  339. _stylusPoints = new StylusPointCollection();
  340. _stylusPoint = new StylusPoint();
  341. _strokes = null;
  342. }
  343. /// <summary>
  344. /// 笔抬起
  345. /// </summary>
  346. public void TqlUp()
  347. {
  348. _isTqlPenDown = false;
  349. if (_strokes != null && _strokes.StylusPoints.Count > 1)
  350. {
  351. _isFirst = true;
  352. }
  353. _stylusPoints = new StylusPointCollection();
  354. _stylusPoint = new StylusPoint();
  355. _strokes = null;
  356. }
  357. /// <summary>
  358. /// 笔书写
  359. /// </summary>
  360. /// <param name="cx"></param>
  361. /// <param name="cy"></param>
  362. /// <param name="force"></param>
  363. public void TqlPenWrite
  364. (
  365. double cx,
  366. double cy,
  367. int force
  368. )
  369. {
  370. if (Visibility == Visibility.Visible)
  371. {
  372. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  373. if (!_isTqlPenDown)
  374. {
  375. return;
  376. }
  377. double propW = BlackboardCanvas.ActualWidth / TQLA4_HEIGHT;
  378. double propH = BlackboardCanvas.ActualHeight / TQLA4_WIDTH;
  379. double tempX = cy * propW;
  380. double tempY = (TQLA4_WIDTH - cx) * propH;
  381. Dispatcher.Invoke(
  382. () =>
  383. {
  384. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  385. //添加笔画
  386. if (_isFirst)
  387. {
  388. _stylusPoint.X = tempX;
  389. _stylusPoint.Y = tempY;
  390. _stylusPoints.Add(_stylusPoint);
  391. if (_stylusPoints.Count > 1)
  392. {
  393. _drawing = new DrawingAttributes
  394. {
  395. Color = _colour,
  396. Width = _wit * 4.5,
  397. Height = _wit * 4.5,
  398. FitToCurve = true,
  399. IgnorePressure = false
  400. };
  401. _strokes = new Stroke(_stylusPoints);
  402. _strokes.DrawingAttributes = _drawing;
  403. BlackboardCanvas.Strokes.Add(_strokes);
  404. _isFirst = false;
  405. }
  406. }
  407. else
  408. {
  409. if (BlackboardCanvas.Strokes.Count > 0)
  410. {
  411. _stylusPoint.X = tempX;
  412. _stylusPoint.Y = tempY;
  413. _stylusPoints.Add(_stylusPoint);
  414. _strokes = new Stroke(_stylusPoints);
  415. _drawing = new DrawingAttributes
  416. {
  417. Color = _colour,
  418. Width = _wit * 4.5,
  419. Height = _wit * 4.5,
  420. FitToCurve = true,
  421. IgnorePressure = false
  422. };
  423. _strokes.DrawingAttributes = _drawing;
  424. //viewModel.InkStrokes.Add(strokes);
  425. BlackboardCanvas.Strokes[BlackboardCanvas.Strokes.Count - 1] = _strokes;
  426. }
  427. }
  428. //设置鼠标位置
  429. if (tempX > 0 && tempY > 0)
  430. {
  431. //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  432. SetCursorPos((int)((float)tempX * (PrimaryScreen.DpiX / 96f)), (int)((float)tempY * (PrimaryScreen.DpiY / 96f)));
  433. }
  434. }
  435. );
  436. }
  437. }
  438. #endregion 腾千里手写笔
  439. }
  440. }