星火直播PC
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.

преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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.Media;
  8. using System.Windows.Media.Imaging;
  9. using XHZB.Desktop.Utils;
  10. using XHZB.Model;
  11. namespace XHZB.Desktop
  12. {
  13. /// <summary>
  14. /// 批注
  15. /// </summary>
  16. public partial class PracticeWindow : Window
  17. {
  18. private readonly ZBPageModel pageData = new ZBPageModel();
  19. private readonly BlackboardNew myblackboard;
  20. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  21. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  22. private readonly List<string> ImageInfo = new List<string>();
  23. private readonly int serverReturnCode = 0;
  24. //private readonly RegisterController registerController = new RegisterController();
  25. /// <summary>
  26. /// 保存图片路径
  27. /// </summary>
  28. private string Rfpath = string.Empty;
  29. /// <summary>
  30. /// 初始创建黑板
  31. /// </summary>
  32. private readonly bool isfirstload = true;
  33. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  34. private int Size = 3;
  35. private string AskidName = string.Empty;
  36. /// <summary>
  37. /// 批注
  38. /// </summary>
  39. public PracticeWindow()
  40. {
  41. InitializeComponent();
  42. if (isfirstload)
  43. {
  44. myblackboard = new BlackboardNew(blackboard_canvas, Colors.Red);
  45. initData();
  46. isfirstload = false;
  47. }
  48. }
  49. /// <summary>
  50. /// 初始化页面
  51. /// </summary>
  52. public void Initialize()
  53. {
  54. this.Opacity = 1;
  55. m_grid.Background = new SolidColorBrush(Colors.Black);
  56. AskidName = string.Empty;
  57. isFDetais = true;
  58. pageData.pagenum = ImageInfo.Count;
  59. Rfpath = string.Empty;
  60. Uri uri = new Uri(ImageInfo[pageData.currpage - 1], UriKind.Absolute);
  61. BitmapImage bitmapImage = new BitmapImage(uri);
  62. myblackboard.changepage(pageData.currpage - 1);
  63. m_image.Source = bitmapImage;
  64. }
  65. private void initData()
  66. {
  67. pageData.menuList.Add(new ZBMenuModel()
  68. {
  69. Name = "铅笔",
  70. Pic = "../Images/Blackboard/class_2s.png",
  71. Selected = true
  72. });
  73. pageData.menuList.Add(new ZBMenuModel()
  74. {
  75. Name = "颜色",
  76. Pic = "../Images/Blackboard/class_c1.png",
  77. Selected = false
  78. });
  79. pageData.menuList.Add(new ZBMenuModel()
  80. {
  81. Name = "粗细",
  82. Pic = "../Images/Blackboard/class_s1.png",
  83. Selected = false
  84. });
  85. pageData.menuList.Add(new ZBMenuModel()
  86. {
  87. Name = "橡皮",
  88. Pic = "../Images/Blackboard/class_3un.png",
  89. Selected = false
  90. });
  91. pageData.menuList.Add(new ZBMenuModel()
  92. {
  93. Name = "清空",
  94. Pic = "../Images/Blackboard/class_6un.png",
  95. Selected = false
  96. });
  97. pageData.menuList.Add(new ZBMenuModel()
  98. {
  99. Name = "撤销",
  100. Pic = "../Images/Blackboard/class_4un.png",
  101. Selected = false
  102. });
  103. pageData.menuList.Add(new ZBMenuModel()
  104. {
  105. Name = "恢复",
  106. Pic = "../Images/Blackboard/class_5un.png",
  107. Selected = false
  108. });
  109. pageData.menuList.Add(new ZBMenuModel()
  110. {
  111. Name = "退出",
  112. Pic = "../Images/Blackboard/class_7un.png",
  113. Selected = false
  114. });
  115. DataContext = pageData;
  116. }
  117. /// <summary>
  118. /// 暂修改为传图片地址 新增一页
  119. /// </summary>
  120. /// <param name="_imageInfo"></param>
  121. public void addImage(string _imageInfo)
  122. {
  123. ImageInfo.Add(_imageInfo);
  124. pageData.currpage = ImageInfo.Count;
  125. Initialize();
  126. }
  127. private void menu_item_Click(object sender, RoutedEventArgs e)
  128. {
  129. int clickindex = 0;
  130. List<Button> buttons = VTHelper.FindChilds<Button>(toolbar_list, "toolbar_item");
  131. for (int i = 0; i < buttons.Count; i++)
  132. {
  133. if (buttons[i] == sender)
  134. {
  135. clickindex = i;
  136. break;
  137. }
  138. }
  139. if (clickindex < pageData.menuList.Count)
  140. {
  141. //ZBMenu menudata = pageData.menuList[clickindex];
  142. if (clickindex == 0)
  143. {
  144. tip_Size.Visibility = Visibility.Collapsed;
  145. tip_Color.Visibility = Visibility.Collapsed;
  146. if (pageData.menuList[0].Selected)
  147. {
  148. }
  149. else
  150. {
  151. pageData.menuList[0].Selected = true;
  152. pageData.menuList[3].Selected = false;
  153. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  154. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  155. myblackboard.change_pen(Color, Size);
  156. }
  157. }
  158. if (clickindex == 1)
  159. {
  160. tip_Color.Visibility = Visibility.Visible;
  161. tip_Size.Visibility = Visibility.Collapsed;
  162. }
  163. if (clickindex == 2)
  164. {
  165. tip_Color.Visibility = Visibility.Collapsed;
  166. tip_Size.Visibility = Visibility.Visible;
  167. }
  168. else if (clickindex == 3)
  169. {
  170. tip_Color.Visibility = Visibility.Collapsed;
  171. pageData.menuList[0].Selected = false;
  172. pageData.menuList[3].Selected = true;
  173. pageData.menuList[0].Pic = "../Images/Blackboard/class_2un.png";
  174. pageData.menuList[3].Pic = "../Images/Blackboard/class_3s.png";
  175. myblackboard.change_erase();
  176. }
  177. else if (clickindex == 4)
  178. {
  179. tip_Size.Visibility = Visibility.Collapsed;
  180. tip_Color.Visibility = Visibility.Collapsed;
  181. myblackboard.clear();
  182. }
  183. else if (clickindex == 5)
  184. {
  185. tip_Size.Visibility = Visibility.Collapsed;
  186. tip_Color.Visibility = Visibility.Collapsed;
  187. myblackboard.undo();
  188. }
  189. else if (clickindex == 6)
  190. {
  191. tip_Size.Visibility = Visibility.Collapsed;
  192. tip_Color.Visibility = Visibility.Collapsed;
  193. myblackboard.redo();
  194. }
  195. else if (clickindex == 7)
  196. {
  197. tip_Size.Visibility = Visibility.Collapsed;
  198. tip_Color.Visibility = Visibility.Collapsed;
  199. //Hide();
  200. new Thread(new ThreadStart(new Action(() =>
  201. {
  202. Dispatcher.Invoke(new Action(() =>
  203. {
  204. m_image.Source = null;
  205. blackboard_canvas.Strokes.Clear();
  206. m_grid.Background = new SolidColorBrush(Colors.Transparent);
  207. this.Opacity = 0;
  208. }));
  209. Thread.Sleep(50);
  210. Dispatcher.Invoke(new Action(() =>
  211. {
  212. Hide();
  213. }));
  214. }))).Start();
  215. }
  216. }
  217. }
  218. // 保存图片
  219. private void save_button_Click(object sender, RoutedEventArgs e)
  220. {
  221. tip_Size.Visibility = Visibility.Collapsed;
  222. tip_Color.Visibility = Visibility.Collapsed;
  223. try
  224. {
  225. string filepath = APP.GetImagePath(out string serverSavePath);
  226. Rfpath = serverSavePath;
  227. //TeachingDataStatic.ClassScreenshot.Add(filepath);//统计截图
  228. ImageHelper.SaveUIToImage(m_grid, filepath, (int)Math.Round(m_grid.ActualWidth), (int)Math.Round(m_grid.ActualHeight));
  229. //}
  230. tip_tb.Text = "保存成功";
  231. tip_outer.Visibility = Visibility.Visible;
  232. new Thread(o =>
  233. {
  234. int seconds = 3;//通知持续5s后消失
  235. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(seconds));
  236. //Invoke到主进程中去执行
  237. Dispatcher.Invoke(new Action(() =>
  238. {
  239. tip_outer.Visibility = Visibility.Hidden;
  240. }));
  241. }).Start();
  242. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  243. }
  244. catch (Exception err)
  245. {
  246. Console.WriteLine(err.Message);
  247. }
  248. }
  249. /// <summary>
  250. /// 上一页
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void last_button_Click(object sender, RoutedEventArgs e)
  255. {
  256. tip_Size.Visibility = Visibility.Collapsed;
  257. tip_Color.Visibility = Visibility.Collapsed;
  258. if (pageData.currpage > 1)
  259. {
  260. pageData.currpage -= 1;
  261. Initialize();
  262. }
  263. }
  264. /// <summary>
  265. /// 下一页
  266. /// </summary>
  267. /// <param name="sender"></param>
  268. /// <param name="e"></param>
  269. private void next_btn_Click(object sender, RoutedEventArgs e)
  270. {
  271. tip_Size.Visibility = Visibility.Collapsed;
  272. tip_Color.Visibility = Visibility.Collapsed;
  273. if (pageData.currpage < pageData.pagenum)
  274. {
  275. pageData.currpage += 1;
  276. Initialize();
  277. }
  278. }
  279. private void Window_Activated(object sender, EventArgs e)
  280. {
  281. //Console.WriteLine("Window_Activated");
  282. }
  283. bool isFDetais = true;
  284. /// <summary>
  285. /// 简答题详情
  286. /// </summary>
  287. public void Detai(bool isDetai, string askidName)
  288. {
  289. isFDetais = isDetai;
  290. //AskidName = askidName;
  291. }
  292. private void Window_Deactivated(object sender, EventArgs e)
  293. {
  294. try
  295. {
  296. if (isFDetais)
  297. {
  298. ////Console.WriteLine("Window_Deactivated");
  299. ToolbarWindow toolbarWin = (ToolbarWindow)Owner;
  300. if (toolbarWin != null)
  301. {
  302. toolbarWin.Show();
  303. }
  304. Console.WriteLine("imageList.Count" + ImageInfo.Count);
  305. }
  306. }
  307. catch (Exception ex)
  308. {
  309. }
  310. }
  311. /// <summary>
  312. /// 课堂--保存图片服务-调用
  313. /// </summary>
  314. /// <returns></returns>
  315. private object InvokeServering()
  316. {
  317. //Savefile savefile = new Savefile
  318. //{
  319. // roomid = Shared.TeachingData.REQ_StartClass.roomid,
  320. // rfpath = Rfpath.Replace("\\", "/")
  321. //};
  322. //;
  323. //savefile.rftype = 2;
  324. //savefile.createid = ZCommonData.loginUser.userid;
  325. //savefile.schoolid = ZCommonData.loginUser.schoolid;
  326. //savefile.createtime = DataProvider.TimestampTotalSeconds();
  327. //ZSqliteManger.insertClassData(new ClassData()
  328. //{
  329. // unix = DataProvider.TimestampTotalSeconds(),
  330. // roomid = ZCommonData.roomid,
  331. // api = "savefile",
  332. // json = ZJsonHelper.ToJson(savefile),
  333. // askid = DataProvider.TimestampAddRandomNumber()
  334. //});
  335. return APP.ErrorMessage;
  336. }
  337. /// <summary>
  338. /// 课堂--保存图片服务-返回结果
  339. /// </summary>
  340. /// <returns></returns>
  341. public void InvokeServerCompate(object obj)
  342. {
  343. if (serverReturnCode == APP.ServerScuessCode)
  344. {
  345. }
  346. }
  347. /// <summary>
  348. /// 页面关闭
  349. /// </summary>
  350. /// <param name="sender"></param>
  351. /// <param name="e"></param>
  352. private void Window_Closed(object sender, EventArgs e)
  353. {
  354. tip_Size.Visibility = Visibility.Collapsed;
  355. tip_Color.Visibility = Visibility.Collapsed;
  356. click_closeClick();
  357. }
  358. #region 关闭委托
  359. /// <summary>
  360. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  361. /// </summary>
  362. /// <param name="sender"></param>
  363. /// <param name="e"></param>
  364. public delegate void CloseClick();
  365. /// <summary>
  366. /// 关闭委托 结束页面 创建人:赵耀 创建时间:2020年8月13日
  367. /// </summary>
  368. public event CloseClick click_closeClick;
  369. #endregion 关闭委托
  370. /// <summary>
  371. /// 画笔颜色事件 白色
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  376. {
  377. pageData.menuList[0].Selected = true;
  378. pageData.menuList[3].Selected = false;
  379. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  380. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  381. Color = Colors.White;
  382. myblackboard.change_pen(Color, Size);
  383. tip_Color.Visibility = Visibility.Collapsed;
  384. }
  385. /// <summary>
  386. /// 画笔颜色事件 红色
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. private void BtnRed_Click(object sender, RoutedEventArgs e)
  391. {
  392. pageData.menuList[0].Selected = true;
  393. pageData.menuList[3].Selected = false;
  394. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  395. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  396. Color = Colors.Red;
  397. myblackboard.change_pen(Color, Size);
  398. tip_Color.Visibility = Visibility.Collapsed;
  399. }
  400. /// <summary>
  401. /// 画笔颜色事件 灰色
  402. /// </summary>
  403. /// <param name="sender"></param>
  404. /// <param name="e"></param>
  405. private void BtnGray_Click(object sender, RoutedEventArgs e)
  406. {
  407. pageData.menuList[0].Selected = true;
  408. pageData.menuList[3].Selected = false;
  409. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  410. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  411. Color = Colors.Gray;
  412. myblackboard.change_pen(Color, Size);
  413. tip_Color.Visibility = Visibility.Collapsed;
  414. }
  415. /// <summary>
  416. /// 画笔颜色事件 青色
  417. /// </summary>
  418. /// <param name="sender"></param>
  419. /// <param name="e"></param>
  420. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  421. {
  422. pageData.menuList[0].Selected = true;
  423. pageData.menuList[3].Selected = false;
  424. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  425. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  426. Color = Colors.LimeGreen;
  427. myblackboard.change_pen(Color, Size);
  428. tip_Color.Visibility = Visibility.Collapsed;
  429. }
  430. /// <summary>
  431. /// 画笔颜色事件 黄色
  432. /// </summary>
  433. /// <param name="sender"></param>
  434. /// <param name="e"></param>
  435. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  436. {
  437. pageData.menuList[0].Selected = true;
  438. pageData.menuList[3].Selected = false;
  439. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  440. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  441. Color = Colors.Gold;
  442. myblackboard.change_pen(Color, Size);
  443. tip_Color.Visibility = Visibility.Collapsed;
  444. }
  445. /// <summary>
  446. /// 画笔颜色事件 蓝色
  447. /// </summary>
  448. /// <param name="sender"></param>
  449. /// <param name="e"></param>
  450. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  451. {
  452. pageData.menuList[0].Selected = true;
  453. pageData.menuList[3].Selected = false;
  454. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  455. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  456. Color = Colors.DeepSkyBlue;
  457. myblackboard.change_pen(Color, Size);
  458. tip_Color.Visibility = Visibility.Collapsed;
  459. }
  460. /// <summary>
  461. /// 细
  462. /// </summary>
  463. /// <param name="sender"></param>
  464. /// <param name="e"></param>
  465. private void BtnFine_Click(object sender, RoutedEventArgs e)
  466. {
  467. pageData.menuList[0].Selected = true;
  468. pageData.menuList[3].Selected = false;
  469. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  470. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  471. Size = 3;
  472. myblackboard.change_pen(Color, Size);
  473. tip_Size.Visibility = Visibility.Collapsed;
  474. }
  475. /// <summary>
  476. /// 中
  477. /// </summary>
  478. /// <param name="sender"></param>
  479. /// <param name="e"></param>
  480. private void BtnIn_Click(object sender, RoutedEventArgs e)
  481. {
  482. pageData.menuList[0].Selected = true;
  483. pageData.menuList[3].Selected = false;
  484. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  485. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  486. Size = 6;
  487. myblackboard.change_pen(Color, Size);
  488. tip_Size.Visibility = Visibility.Collapsed;
  489. }
  490. /// <summary>
  491. /// 粗
  492. /// </summary>
  493. /// <param name="sender"></param>
  494. /// <param name="e"></param>
  495. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  496. {
  497. pageData.menuList[0].Selected = true;
  498. pageData.menuList[3].Selected = false;
  499. pageData.menuList[0].Pic = "../Images/Blackboard/class_2s.png";
  500. pageData.menuList[3].Pic = "../Images/Blackboard/class_3un.png";
  501. Size = 12;
  502. myblackboard.change_pen(Color, Size);
  503. tip_Size.Visibility = Visibility.Collapsed;
  504. }
  505. }
  506. }