ColorDropBoxPop.xaml.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using WinForm = System.Windows.Forms;
  18. namespace PDF_Master.CustomControl
  19. {
  20. /// <summary>
  21. /// ColorDropBoxPop.xaml 的交互逻辑
  22. /// </summary>
  23. public class ColorToBrushConverter : IValueConverter
  24. {
  25. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  26. {
  27. if (value is Color)
  28. {
  29. return new SolidColorBrush((Color)value);
  30. }
  31. return Brushes.Transparent;
  32. }
  33. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  34. {
  35. throw new NotImplementedException();
  36. }
  37. }
  38. /// <summary>
  39. /// ColorDropBoxPop.xaml 的交互逻辑
  40. /// </summary>
  41. public partial class ColorDropBoxPop : UserControl
  42. {
  43. public event EventHandler<Color> ColorSelected;
  44. public ObservableCollection<Color> RecentlyColors { get; private set; }
  45. public ObservableCollection<Color> ThemeColors { get; private set; }
  46. public ColorDropBoxPop()
  47. {
  48. InitializeComponent();
  49. SetLangText();
  50. RecentlyColors = new ObservableCollection<Color>();
  51. ThemeColors = new ObservableCollection<Color>();
  52. CreateThemeColors();
  53. RecentlyColorList.ItemsSource = RecentlyColors;
  54. ThemeColorList.ItemsSource = ThemeColors;
  55. }
  56. private void SetLangText()
  57. {
  58. //RecentlyColorText.Text = App.MainPageLoader.GetString("Themes_RecentlyUsed");
  59. //TransparentText.Text = App.MainPageLoader.GetString("Themes_Transparent");
  60. //OtherColorsText.Text = App.MainPageLoader.GetString("Themes_More");
  61. //ThemeColorsText.Text = App.MainPageLoader.GetString("ProperPanel_Color");
  62. }
  63. public void CreateThemeColors()
  64. {
  65. ThemeColors.Add(Color.FromRgb(0xFF, 0xFF, 0xFF));
  66. ThemeColors.Add(Color.FromRgb(0x00, 0x00, 0x00));
  67. ThemeColors.Add(Color.FromRgb(0x25, 0x1C, 0x16));
  68. ThemeColors.Add(Color.FromRgb(0xCC, 0x00, 0x00));
  69. ThemeColors.Add(Color.FromRgb(0xCC, 0x4E, 0x00));
  70. ThemeColors.Add(Color.FromRgb(0x99, 0x70, 0x00));
  71. ThemeColors.Add(Color.FromRgb(0x1C, 0x70, 0x17));
  72. ThemeColors.Add(Color.FromRgb(0x00, 0x8D, 0x99));
  73. ThemeColors.Add(Color.FromRgb(0x00, 0x3F, 0x99));
  74. ThemeColors.Add(Color.FromRgb(0x61, 0x00, 0x99));
  75. ThemeColors.Add(Color.FromRgb(0x88, 0x88, 0x88));
  76. ThemeColors.Add(Color.FromRgb(0x1B, 0x1B, 0x1B));
  77. ThemeColors.Add(Color.FromRgb(0x4A, 0x37, 0x2C));
  78. ThemeColors.Add(Color.FromRgb(0xFF, 0x00, 0x00));
  79. ThemeColors.Add(Color.FromRgb(0xFF, 0x61, 0x00));
  80. ThemeColors.Add(Color.FromRgb(0xCC, 0x96, 0x00));
  81. ThemeColors.Add(Color.FromRgb(0x27, 0x9D, 0x20));
  82. ThemeColors.Add(Color.FromRgb(0x00, 0xBC, 0xCC));
  83. ThemeColors.Add(Color.FromRgb(0x00, 0x54, 0xcc));
  84. ThemeColors.Add(Color.FromRgb(0x82, 0x00, 0xcc));
  85. ThemeColors.Add(Color.FromRgb(0xA0, 0xA0, 0xA0));
  86. ThemeColors.Add(Color.FromRgb(0x29, 0x29, 0x29));
  87. ThemeColors.Add(Color.FromRgb(0x6E, 0x53, 0x42));
  88. ThemeColors.Add(Color.FromRgb(0xFF, 0x33, 0x33));
  89. ThemeColors.Add(Color.FromRgb(0xFF, 0x81, 0x33));
  90. ThemeColors.Add(Color.FromRgb(0xFF, 0xBB, 0x00));
  91. ThemeColors.Add(Color.FromRgb(0x32, 0xCA, 0x29));
  92. ThemeColors.Add(Color.FromRgb(0x00, 0xEB, 0xFF));
  93. ThemeColors.Add(Color.FromRgb(0x00, 0x69, 0xFF));
  94. ThemeColors.Add(Color.FromRgb(0xA2, 0x00, 0xFF));
  95. ThemeColors.Add(Color.FromRgb(0xB8, 0xB8, 0xB8));
  96. ThemeColors.Add(Color.FromRgb(0x44, 0x44, 0x44));
  97. ThemeColors.Add(Color.FromRgb(0x93, 0x6E, 0x58));
  98. ThemeColors.Add(Color.FromRgb(0xFF, 0x66, 0x66));
  99. ThemeColors.Add(Color.FromRgb(0xFF, 0xA0, 0x66));
  100. ThemeColors.Add(Color.FromRgb(0xFF, 0xC9, 0x33));
  101. ThemeColors.Add(Color.FromRgb(0x38, 0xE0, 0x2E));
  102. ThemeColors.Add(Color.FromRgb(0x33, 0xEF, 0xFF));
  103. ThemeColors.Add(Color.FromRgb(0x33, 0x87, 0xFF));
  104. ThemeColors.Add(Color.FromRgb(0xB5, 0x33, 0xFF));
  105. ThemeColors.Add(Color.FromRgb(0xCF, 0xCF, 0xCF));
  106. ThemeColors.Add(Color.FromRgb(0x5F, 0x5F, 0x5F));
  107. ThemeColors.Add(Color.FromRgb(0xB8, 0x8A, 0x6E));
  108. ThemeColors.Add(Color.FromRgb(0xFF, 0x99, 0x99));
  109. ThemeColors.Add(Color.FromRgb(0xFF, 0xB0, 0x80));
  110. ThemeColors.Add(Color.FromRgb(0xFF, 0xD6, 0x66));
  111. ThemeColors.Add(Color.FromRgb(0x60, 0xE6, 0x58));
  112. ThemeColors.Add(Color.FromRgb(0x66, 0xF3, 0xFF));
  113. ThemeColors.Add(Color.FromRgb(0x66, 0xA5, 0xFF));
  114. ThemeColors.Add(Color.FromRgb(0xC7, 0x66, 0xFF));
  115. ThemeColors.Add(Color.FromRgb(0xE7, 0xE7, 0xE7));
  116. ThemeColors.Add(Color.FromRgb(0x7A, 0x7A, 0x7A));
  117. ThemeColors.Add(Color.FromRgb(0xC6, 0xA1, 0x8B));
  118. ThemeColors.Add(Color.FromRgb(0xFF, 0xCC, 0xCC));
  119. ThemeColors.Add(Color.FromRgb(0xFF, 0xC4, 0x9F));
  120. ThemeColors.Add(Color.FromRgb(0xFF, 0xE4, 0x99));
  121. ThemeColors.Add(Color.FromRgb(0x88, 0xEC, 0x82));
  122. ThemeColors.Add(Color.FromRgb(0x99, 0xF7, 0xFF));
  123. ThemeColors.Add(Color.FromRgb(0x99, 0xC3, 0xFF));
  124. ThemeColors.Add(Color.FromRgb(0xDA, 0x99, 0xFF));
  125. }
  126. private void SystemColorPicker_ClickPop(object sender, MouseButtonEventArgs e)
  127. {
  128. this.Visibility = Visibility.Collapsed;
  129. WinForm.ColorDialog colorPicker = new WinForm.ColorDialog();
  130. WinForm.DialogResult result = colorPicker.ShowDialog();
  131. if (result == WinForm.DialogResult.OK)
  132. {
  133. Color selectColor = Color.FromArgb(colorPicker.Color.A, colorPicker.Color.R, colorPicker.Color.G, colorPicker.Color.B);
  134. AddColorToRecent(selectColor);
  135. if (ColorSelected != null)
  136. {
  137. ColorSelected?.Invoke(this, selectColor);
  138. }
  139. }
  140. }
  141. private void TransparentColor_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  142. {
  143. if (ColorSelected != null)
  144. {
  145. ColorSelected?.Invoke(this, Colors.Transparent);
  146. }
  147. this.Visibility = Visibility.Collapsed;
  148. }
  149. private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  150. {
  151. this.Visibility = Visibility.Collapsed;
  152. Rectangle clickRectangle = sender as Rectangle;
  153. if (clickRectangle != null)
  154. {
  155. SolidColorBrush fillBrush = clickRectangle.Fill as SolidColorBrush;
  156. if (fillBrush != null)
  157. {
  158. AddColorToRecent(fillBrush.Color);
  159. if (ColorSelected != null)
  160. {
  161. ColorSelected?.Invoke(this, fillBrush.Color);
  162. }
  163. }
  164. }
  165. }
  166. public void AddColorToRecent(Color recentColor)
  167. {
  168. if(recentColor==Colors.Transparent)
  169. {
  170. return;
  171. }
  172. if (RecentlyColors.AsEnumerable().Where(x => x == recentColor).Count() == 0)
  173. {
  174. while (RecentlyColors.Count >= 10)
  175. {
  176. RecentlyColors.RemoveAt(0);
  177. }
  178. RecentlyColors.Add(recentColor);
  179. }
  180. }
  181. public void SetTransparentPanelVisible(bool visible)
  182. {
  183. TransparentPanel.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
  184. }
  185. }
  186. }