星火直播PC
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ZBlackboardWindow.xaml.cs 20KB

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