ThemeControl.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. using GeekDesk.Constant;
  2. using GeekDesk.Control.Other;
  3. using GeekDesk.Util;
  4. using GeekDesk.ViewModel;
  5. using Microsoft.Win32;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Controls.Primitives;
  17. using System.Windows.Data;
  18. using System.Windows.Documents;
  19. using System.Windows.Input;
  20. using System.Windows.Interop;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Effects;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. using System.Windows.Threading;
  27. namespace GeekDesk.Control.UserControls.Config
  28. {
  29. enum ColorType
  30. {
  31. COLOR_1 = 1,
  32. COLOR_2 = 2,
  33. TEXT_COLOR = 3
  34. }
  35. /// <summary>
  36. /// MotionControl.xaml 的交互逻辑
  37. /// </summary>
  38. public partial class ThemeControl : System.Windows.Controls.UserControl
  39. {
  40. private static ColorType colorType;
  41. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  42. private System.Windows.Controls.Primitives.ToggleButton toggleButton = null;
  43. public ThemeControl()
  44. {
  45. InitializeComponent();
  46. if (appConfig.BGStyle != BGStyle.GradientBac)
  47. {
  48. GradientBGConf.Visibility = Visibility.Collapsed;
  49. ImgBGConf.Visibility = Visibility.Visible;
  50. }
  51. else
  52. {
  53. ImgBGConf.Visibility = Visibility.Collapsed;
  54. GradientBGConf.Visibility = Visibility.Visible;
  55. }
  56. }
  57. /// <summary>
  58. /// 修改背景图片
  59. /// </summary>
  60. /// <param name="sender"></param>
  61. /// <param name="e"></param>
  62. private void BGButton_Click(object sender, RoutedEventArgs e)
  63. {
  64. try
  65. {
  66. OpenFileDialog ofd = new OpenFileDialog
  67. {
  68. Multiselect = false, //只允许选中单个文件
  69. Filter = "图像文件(*.png, *.jpg)|*.png;*.jpg;*.gif"
  70. };
  71. if (ofd.ShowDialog() == true)
  72. {
  73. appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
  74. appConfig.BacImgName = ofd.FileName;
  75. }
  76. }
  77. catch (Exception ex)
  78. {
  79. LogUtil.WriteErrorLog(ex, "修改背景失败,已重置为默认背景!");
  80. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  81. }
  82. BGSettingUtil.BGSetting();
  83. }
  84. private void DefaultButton_Click(object sender, RoutedEventArgs e)
  85. {
  86. try
  87. {
  88. appConfig.BitmapImage = ImageUtil.Base64ToBitmapImage(Constants.DEFAULT_BAC_IMAGE_BASE64);
  89. appConfig.BacImgName = "系统默认";
  90. }
  91. catch (Exception ex)
  92. {
  93. LogUtil.WriteErrorLog(ex, "修改背景失败2,已重置为默认背景!");
  94. HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
  95. }
  96. BGSettingUtil.BGSetting();
  97. }
  98. private void ColorButton_Click(object sender, RoutedEventArgs e)
  99. {
  100. string tag = (sender as Button).Tag.ToString();
  101. switch (tag)
  102. {
  103. case "Color1":
  104. colorType = ColorType.COLOR_1;break;
  105. case "Color2":
  106. colorType = ColorType.COLOR_2;break;
  107. default:
  108. colorType = ColorType.TEXT_COLOR;break;
  109. }
  110. ColorPanel.Visibility = Visibility.Visible;
  111. }
  112. /// <summary>
  113. /// 取消按钮事件
  114. /// </summary>
  115. /// <param name="sender"></param>
  116. /// <param name="e"></param>
  117. private void MyColorPicker_Canceled(object sender, EventArgs e)
  118. {
  119. MyColorPickerClose(sender);
  120. }
  121. private void MyColorPicker_Confirmed(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  122. {
  123. MyColorPickerClose(sender);
  124. }
  125. private void MyColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
  126. {
  127. SolidColorBrush scb = MyColorPicker.SelectedBrush;
  128. switch (colorType)
  129. {
  130. case ColorType.COLOR_1:
  131. appConfig.GradientBGParam.Color1 = scb.ToString();break;
  132. case ColorType.COLOR_2:
  133. appConfig.GradientBGParam.Color2 = scb.ToString(); break;
  134. default:
  135. appConfig.TextColor = scb.ToString();break;
  136. }
  137. }
  138. /// <summary>
  139. /// 移动窗口
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  144. {
  145. if (e.LeftButton == MouseButtonState.Pressed)
  146. {
  147. Window.GetWindow(this).DragMove();
  148. }
  149. }
  150. private void PreviewSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  151. {
  152. CheckButtonUpClass cbu = new CheckButtonUpClass
  153. {
  154. e = e
  155. };
  156. System.Threading.ThreadStart ts = new System.Threading.ThreadStart(cbu.CheckButtonUp);
  157. System.Threading.Thread t = new System.Threading.Thread(ts);
  158. t.Start();
  159. }
  160. private class CheckButtonUpClass
  161. {
  162. public MouseButtonEventArgs e;
  163. public void CheckButtonUp()
  164. {
  165. while (true)
  166. {
  167. if (e.LeftButton == MouseButtonState.Released)
  168. {
  169. App.Current.Dispatcher.Invoke((Action)(() =>
  170. {
  171. AppData appData = MainWindow.appData;
  172. ObservableCollection<IconInfo> selectIcons = appData.AppConfig.SelectedMenuIcons;
  173. appData.AppConfig.SelectedMenuIcons = null;
  174. appData.AppConfig.SelectedMenuIcons = selectIcons;
  175. }));
  176. return;
  177. }
  178. System.Threading.Thread.Sleep(50);
  179. }
  180. }
  181. }
  182. private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
  183. {
  184. toggleButton = e.OriginalSource as System.Windows.Controls.Primitives.ToggleButton;
  185. }
  186. private void MyColorPickerClose(object sender)
  187. {
  188. if (toggleButton != null && toggleButton.IsChecked == true)
  189. {
  190. HandyControl.Controls.ColorPicker cp = sender as HandyControl.Controls.ColorPicker;
  191. const BindingFlags InstanceBindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
  192. Type type = cp.GetType();
  193. toggleButton.IsChecked = false;
  194. MethodInfo mi = type.GetMethod("ToggleButtonDropper_Click", InstanceBindFlags);
  195. mi.Invoke(cp, new object[] { null, null });
  196. }
  197. ColorPanel.Visibility = Visibility.Collapsed;
  198. }
  199. public void BGStyle_Changed(object sender, RoutedEventArgs e)
  200. {
  201. BGSettingUtil.BGSetting();
  202. if (appConfig.BGStyle != BGStyle.GradientBac)
  203. {
  204. GradientBGConf.Visibility = Visibility.Collapsed;
  205. ImgBGConf.Visibility = Visibility.Visible;
  206. } else
  207. {
  208. ImgBGConf.Visibility = Visibility.Collapsed;
  209. GradientBGConf.Visibility = Visibility.Visible;
  210. }
  211. }
  212. private void BGOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  213. {
  214. BGSettingUtil.BGSetting();
  215. }
  216. private void Color_TargetUpdated(object sender, DataTransferEventArgs e)
  217. {
  218. BGSettingUtil.BGSetting();
  219. }
  220. private void SysBG_Click(object sender, RoutedEventArgs e)
  221. {
  222. GradientBGDialog gbg = new GradientBGDialog();
  223. gbg.dialog = HandyControl.Controls.Dialog.Show(gbg, "SysBGDialog");
  224. }
  225. }
  226. }