Browse Source

zhao:1录屏批注增加点阵笔,2显示隐藏录屏工具栏

tags/录制修改前
耀 4 years ago
parent
commit
7849f41218

+ 352
- 0
XHWK.WKTool/PracticeWindow.xaml.cs View File

@@ -9,6 +9,8 @@ using System.Windows.Ink;
9 9
 using System.Windows.Input;
10 10
 using System.Windows.Media;
11 11
 
12
+using TStudyDigitalPen.HID;
13
+
12 14
 using XHWK.Model;
13 15
 
14 16
 namespace XHWK.WKTool
@@ -42,6 +44,7 @@ namespace XHWK.WKTool
42 44
         public PracticeWindow()
43 45
         {
44 46
             InitializeComponent();
47
+            InitPen();
45 48
         }
46 49
         public void Initialize(string _imgPath = null)
47 50
         {
@@ -434,6 +437,355 @@ namespace XHWK.WKTool
434 437
                 });
435 438
             }))).Start();
436 439
         }
440
+
441
+
442
+        #region 点阵笔相关
443
+        #region 值初始化
444
+        // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
445
+
446
+        /// <summary>
447
+        /// A4点阵纸点阵宽度
448
+        /// </summary>
449
+        private const int A4_WIDTH = 5600;
450
+
451
+        /// <summary>
452
+        /// A4点阵纸点阵高度
453
+        /// </summary>
454
+        private const int A4_HEIGHT = 7920;
455
+
456
+        ///// <summary>
457
+        ///// 画板
458
+        ///// </summary>
459
+        //private Graphics graphics;
460
+
461
+        /// <summary>
462
+        /// 笔画坐标数组
463
+        /// </summary>
464
+        private List<System.Drawing.Point> stroke;
465
+
466
+        /// <summary>
467
+        /// 笔序列号
468
+        /// </summary>
469
+        private string penSerial;
470
+
471
+        /// <summary>
472
+        /// 笔是否在点
473
+        /// </summary>
474
+        private bool isPenDown;
475
+
476
+        //当前点阵地址
477
+        private string currentPageSerial = string.Empty;
478
+
479
+        //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
480
+        //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
481
+        private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
482
+        #endregion
483
+        public void InitPen()
484
+        {
485
+            stroke = new List<System.Drawing.Point>();
486
+            //获取点阵笔实例,并绑定点阵笔事件
487
+            //将授权文件内容传入,获取点阵笔对象实例
488
+            APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
489
+            //绑定笔连接事件
490
+            APP.digitalPen.PenConnected += OnPenConnect;
491
+            //绑定笔断开事件
492
+            APP.digitalPen.PenDisconnect += OnPenDisconnect;
493
+            //绑定笔书写输出坐标事件
494
+            APP.digitalPen.PenCoordinate += OnPenCoordinate;
495
+            //绑定抬笔事件
496
+            APP.digitalPen.PenUp += OnPenUp;
497
+            //绑定落笔事件
498
+            APP.digitalPen.PenDown += OnPenDown;
499
+            APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
500
+            APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
501
+            //完成初始化点阵笔,开始与点阵笔通信
502
+            ERROR_CODE ER = APP.digitalPen.Start();
503
+
504
+            ////绑定笔在新的点阵地址页面书写事件
505
+            //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
506
+            ////绑定笔信息事件
507
+            //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
508
+            //启动接收笔数据,完成初始化工作
509
+            //ERROR_CODE rc = APP.digitalPen.Start();
510
+            //判断是否成功
511
+            if (ER != ERROR_CODE.ERROR_OK)
512
+            {
513
+                MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
514
+            }
515
+        }
516
+
517
+        /// <summary>
518
+        /// 落笔
519
+        /// </summary>
520
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
521
+        /// <param name="penSerial">点阵笔序列号</param>
522
+        /// <param name="penType">点阵笔型号编号</param>
523
+        private void OnPenDown(ulong time, string penSerial, int penType)
524
+        {
525
+            if (CheckAccess())
526
+            {
527
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
528
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
529
+            }
530
+            else
531
+            {
532
+                isPenDown = true;
533
+            }
534
+        }
535
+
536
+        /// <summary>
537
+        /// 抬笔
538
+        /// </summary>
539
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
540
+        /// <param name="penSerial">点阵笔序列号</param>
541
+        /// <param name="penType">点阵笔型号编号</param>
542
+        private void OnPenUp(ulong time, string penSerial, int penType)
543
+        {
544
+            if (CheckAccess())
545
+            {
546
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
547
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
548
+            }
549
+            else
550
+            {
551
+                isPenDown = false;
552
+                APP.PenSerial = penSerial;
553
+
554
+                stroke.Clear();
555
+            }
556
+            //if (APP.pageData.currpage > 0)
557
+            //{
558
+            //    Dispatcher.Invoke(new Action(() =>
559
+            //    {
560
+            //        myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
561
+            //    }));
562
+            //}
563
+
564
+
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
+        private void OnPenDisconnect(ulong time, string penSerial, int penType)
574
+        {
575
+            if (CheckAccess())
576
+            {
577
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
578
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
579
+            }
580
+            else
581
+            {
582
+                APP.PenSerial = penSerial;
583
+                APP.PenStatus = false;
584
+                //UpdateDevStatus();
585
+                ////Dispatcher.Invoke(new Action(() =>
586
+                ////{
587
+                ////    txbNotConnected.Text = "未连接";
588
+                ////    txbNotConnecteds.Text = "未连接";
589
+                ////}));
590
+            }
591
+        }
592
+
593
+        /// <summary>
594
+        /// 笔连接
595
+        /// </summary>
596
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
597
+        /// <param name="penSerial">点阵笔序列号</param>
598
+        /// <param name="penType">点阵笔型号编号</param>
599
+        private void OnPenConnect(ulong time, string penSerial, int penType)
600
+        {
601
+            if (CheckAccess())
602
+            {
603
+                Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
604
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
605
+            }
606
+            else
607
+            {
608
+                APP.PenSerial = penSerial;
609
+                APP.PenStatus = true;
610
+                this.penSerial = penSerial;
611
+                //连接后,在获取笔数据前,可以清除笔内的历史数据
612
+                //APP.digitalPen.ClearMemory(penSerial);
613
+
614
+                //开始接收笔数据
615
+                APP.digitalPen.GetPenData(penSerial);
616
+                //UpdateDevStatus();
617
+                ////Dispatcher.Invoke(new Action(() =>
618
+                ////{
619
+                ////    txbNotConnected.Text = "已连接";
620
+                ////    txbNotConnecteds.Text = "已连接";
621
+                ////}));
622
+
623
+            }
624
+        }
625
+        /// <summary>
626
+        /// 电池电量
627
+        /// </summary>
628
+        /// <param name="time"></param>
629
+        /// <param name="penSerial"></param>
630
+        /// <param name="penType"></param>
631
+        /// <param name="capacity"></param>
632
+        private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
633
+        {
634
+            if (CheckAccess())
635
+            {
636
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
637
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
638
+            }
639
+            else
640
+            {
641
+                //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
642
+            }
643
+        }
644
+
645
+        /// <summary>
646
+        /// 已用存储
647
+        /// </summary>
648
+        /// <param name="time"></param>
649
+        /// <param name="penSerial"></param>
650
+        /// <param name="penType"></param>
651
+        /// <param name="fillLevel"></param>
652
+        private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
653
+        {
654
+            if (CheckAccess())
655
+            {
656
+                Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
657
+                Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
658
+            }
659
+            else
660
+            {
661
+                //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
662
+            }
663
+        }
664
+
665
+        /// <summary>
666
+        /// 笔书写,收到坐标
667
+        /// </summary>
668
+        /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
669
+        /// <param name="penSerial">点阵笔序列号</param>
670
+        /// <param name="penType">点阵笔型号编号</param>
671
+        /// <param name="pageSerial">点阵地址</param>
672
+        /// <param name="cx">x坐标</param>
673
+        /// <param name="cy">y坐标</param>
674
+        /// <param name="force">压力值</param>
675
+        private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
676
+        {
677
+            if (CheckAccess())
678
+            {
679
+                Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
680
+                Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
681
+            }
682
+            else
683
+            {
684
+                //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
685
+                if (!isPenDown)
686
+                {
687
+                    return;
688
+                }
689
+                stroke.Add(new System.Drawing.Point(cx, cy));
690
+
691
+                double PropW = blackboard_canvas.ActualWidth / A4_HEIGHT;
692
+                double PropH = blackboard_canvas.ActualHeight / A4_WIDTH;
693
+                //点
694
+                double testX = cy * PropW;
695
+                double testY = (A4_WIDTH - cx) * PropH;
696
+                //pageSerial //点阵IP地址  与打印的页面关联
697
+                if (APP.pageData.currpage > 0)
698
+                {
699
+                    Dispatcher.Invoke(new Action(() =>
700
+                    {
701
+                        float Pressure = force / 100f;
702
+                        //添加笔画
703
+                        //myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
704
+
705
+                        //设置鼠标位置
706
+                        if (testX > 0 && testY > 0)
707
+                        {
708
+                            //System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
709
+                            SetCursorPos((int)testX, (int)testY);
710
+                        }
711
+                    }));
712
+                }
713
+
714
+            }
715
+        }
716
+
717
+        /// <summary>
718
+        /// 停止笔
719
+        /// </summary>
720
+        public void StopDigitalPen()
721
+        {
722
+            //停止,释放资源
723
+            APP.digitalPen.Stop();
724
+        }
725
+        /// <summary>
726
+        /// 清空笔内存储
727
+        /// </summary>
728
+        public void ClearPenStorage()
729
+        {
730
+            if (!string.IsNullOrEmpty(penSerial))
731
+            {
732
+                APP.digitalPen.ClearMemory(penSerial);
733
+            }
734
+        }
735
+        /// <summary>
736
+        /// 获取剩余电量
737
+        /// </summary>
738
+        public void GetPenElectricityQuantity()
739
+        {
740
+            if (!string.IsNullOrEmpty(penSerial))
741
+            {
742
+                APP.digitalPen.GetBatteryCapacity(penSerial);
743
+            }
744
+        }
745
+
746
+        /// <summary>
747
+        /// 获取存储空间
748
+        /// </summary>
749
+        public void GetUsedStorage()
750
+        {
751
+            if (!string.IsNullOrEmpty(penSerial))
752
+            {
753
+                APP.digitalPen.GetMemoryFillLevel(penSerial);
754
+            }
755
+        }
756
+
757
+        /// <summary>
758
+        /// 开启悬浮
759
+        /// </summary>
760
+        public void 开启悬浮()
761
+        {
762
+            if (!string.IsNullOrEmpty(penSerial))
763
+            {
764
+                APP.digitalPen.SetPenHoverMode(true, penSerial);
765
+            }
766
+        }
767
+
768
+        /// <summary>
769
+        /// 关闭悬浮
770
+        /// </summary>
771
+        public void 关闭悬浮()
772
+        {
773
+            if (!string.IsNullOrEmpty(penSerial))
774
+            {
775
+                APP.digitalPen.SetPenHoverMode(false, penSerial);
776
+            }
777
+        }
778
+
779
+        /// <summary>
780
+        /// 引用user32.dll动态链接库(windows api),
781
+        /// 使用库中定义 API:SetCursorPos
782
+        /// 设置光标位置
783
+        /// </summary>
784
+        [System.Runtime.InteropServices.DllImport("user32.dll")]
785
+        private static extern int SetCursorPos(int x, int y);
786
+
787
+        #endregion
788
+
437 789
     }
438 790
 }
439 791
 

+ 10
- 0
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

@@ -1,6 +1,7 @@
1 1
 using Common.system;
2 2
 
3 3
 using System;
4
+using System.Collections.Generic;
4 5
 using System.Drawing;
5 6
 using System.IO;
6 7
 using System.Threading;
@@ -11,6 +12,8 @@ using System.Windows.Media;
11 12
 using System.Windows.Media.Imaging;
12 13
 using System.Windows.Threading;
13 14
 
15
+using TStudyDigitalPen.HID;
16
+
14 17
 using XHWK.Model;
15 18
 
16 19
 namespace XHWK.WKTool
@@ -93,6 +96,7 @@ namespace XHWK.WKTool
93 96
                 };
94 97
                 //practiceWin.Owner = this;
95 98
             }
99
+            APP.W_PracticeWindow.InitPen();
96 100
             APP.W_PracticeWindow.Show();
97 101
             new Thread(new ThreadStart(new Action(() =>
98 102
             {
@@ -599,6 +603,7 @@ namespace XHWK.WKTool
599 603
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
600 604
             }
601 605
             APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
606
+            APP.W_XHMicroLessonSystemWindow.InitPen();
602 607
             APP.W_XHMicroLessonSystemWindow.Show();
603 608
             if (!IsFirstRS)
604 609
             {
@@ -760,6 +765,7 @@ namespace XHWK.WKTool
760 765
                         };
761 766
                         //practiceWin.Owner = this;
762 767
                     }
768
+                    APP.W_PracticeWindow.InitPen();
763 769
                     APP.W_PracticeWindow.Initialize();// imagePath);
764 770
                     flg = 11;
765 771
                     APP.W_PracticeWindow.Blue();
@@ -963,6 +969,7 @@ namespace XHWK.WKTool
963 969
         }
964 970
         #endregion
965 971
         #endregion
972
+
966 973
         /// <summary>
967 974
         /// 停止录屏
968 975
         /// </summary>
@@ -1063,6 +1070,7 @@ namespace XHWK.WKTool
1063 1070
                         };
1064 1071
                         //practiceWin.Owner = this;
1065 1072
                     }
1073
+                    APP.W_PracticeWindow.InitPen();
1066 1074
                     APP.W_PracticeWindow.Initialize();//imagePath);
1067 1075
                     flg = 10;
1068 1076
                     APP.W_PracticeWindow.Red();
@@ -1127,6 +1135,7 @@ namespace XHWK.WKTool
1127 1135
                         };
1128 1136
                         //practiceWin.Owner = this;
1129 1137
                     }
1138
+                    APP.W_PracticeWindow.InitPen();
1130 1139
                     APP.W_PracticeWindow.Initialize();//imagePath);
1131 1140
 
1132 1141
                     if (flg == 0)
@@ -1214,6 +1223,7 @@ namespace XHWK.WKTool
1214 1223
                 }
1215 1224
             }
1216 1225
             APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
1226
+            APP.W_XHMicroLessonSystemWindow.InitPen();
1217 1227
             APP.W_XHMicroLessonSystemWindow.Show();
1218 1228
             Hide();
1219 1229
         }

+ 16
- 10
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

@@ -197,7 +197,6 @@ namespace XHWK.WKTool
197 197
             Initialize();
198 198
             InitPen();
199 199
             InitlbPen();
200
-
201 200
         }
202 201
         /// <summary>
203 202
         /// 初始化
@@ -993,6 +992,19 @@ namespace XHWK.WKTool
993 992
         {
994 993
             System.Diagnostics.Process.Start(APP.WKData.WkPath);
995 994
         }
995
+        /// <summary>
996
+        /// 更新隐藏录屏工具栏隐藏状态
997
+        /// </summary>
998
+        void UpdateHideSRToolConfig()
999
+        {
1000
+            //隐藏
1001
+            FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
1002
+            APP.IsHideSRTool = true;
1003
+
1004
+            //显示
1005
+            FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
1006
+            APP.IsHideSRTool = false;
1007
+        }
996 1008
         #endregion
997 1009
 
998 1010
         #region 画笔
@@ -5057,6 +5069,9 @@ namespace XHWK.WKTool
5057 5069
 
5058 5070
         #endregion
5059 5071
 
5072
+        /// <summary>
5073
+        /// 更新设备状态显示
5074
+        /// </summary>
5060 5075
         void UpdateDevStatus()
5061 5076
         {
5062 5077
             if (APP.BoardStatus && APP.PenStatus)
@@ -5601,15 +5616,6 @@ namespace XHWK.WKTool
5601 5616
         }
5602 5617
         #endregion
5603 5618
 
5604
-        private void Button_Click(object sender, RoutedEventArgs e)
5605
-        {
5606
-            robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND);
5607
-        }
5608
-
5609
-        private void Button_Click_1(object sender, RoutedEventArgs e)
5610
-        {
5611
-            robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE);
5612
-        }
5613 5619
     }
5614 5620
     public class PageData
5615 5621
     {

Loading…
Cancel
Save