ThemeControl.xaml.cs 8.5 KB

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