Browse Source

Added Copy Main Color button to tool color setting

CPKreuz 4 years ago
parent
commit
ea70be9e72

+ 5 - 5
PixiEditor/Models/Tools/ToolSettings/Settings/ColorSetting.cs

@@ -4,6 +4,7 @@ using System.Windows.Interactivity;
 using System.Windows.Media;
 using ColorPicker;
 using PixiEditor.Helpers.Behaviours;
+using PixiEditor.Views;
 
 namespace PixiEditor.Models.Tools.ToolSettings.Settings
 {
@@ -17,16 +18,15 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
             Value = Color.FromArgb(255, 255, 255, 255);
         }
 
-        private PortableColorPicker GenerateColorPicker()
+        private ToolSettingColorPicker GenerateColorPicker()
         {
             var resourceDictionary = new ResourceDictionary();
             resourceDictionary.Source = new System.Uri(
                 "pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml",
                 System.UriKind.RelativeOrAbsolute);
-            PortableColorPicker picker = new PortableColorPicker
+            ToolSettingColorPicker picker = new ToolSettingColorPicker
             {
-                Style = (Style)resourceDictionary["DefaultColorPickerStyle"],
-                SecondaryColor = System.Windows.Media.Colors.Black
+                Style = (Style)resourceDictionary["DefaultColorPickerStyle"]
             };
             Binding binding = new Binding("Value")
             {
@@ -34,7 +34,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
             };
             GlobalShortcutFocusBehavior behavor = new GlobalShortcutFocusBehavior();
             Interaction.GetBehaviors(picker).Add(behavor);
-            picker.SetBinding(PortableColorPicker.SelectedColorProperty, binding);
+            picker.SetBinding(ToolSettingColorPicker.SelectedColorProperty, binding);
             return picker;
         }
     }

+ 16 - 0
PixiEditor/Views/UserControls/ToolSettingColorPicker.xaml

@@ -0,0 +1,16 @@
+<UserControl x:Class="PixiEditor.Views.ToolSettingColorPicker"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PixiEditor.Views.UserControls" xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker"
+             mc:Ignorable="d" 
+             x:Name="uc"
+             d:Background="{StaticResource AccentColor}">
+    <Grid>
+        <StackPanel Orientation="Horizontal">
+            <colorpicker:PortableColorPicker x:Name="ColorPicker" SelectedColor="{Binding SelectedColor, ElementName=uc}"/>
+            <Button Command="{Binding CopyMainColorCommand, ElementName=uc}" Style="{StaticResource DarkRoundButton}" FontSize="12" Width="100" Margin="5,0,0,0">Copy Main Color</Button>
+        </StackPanel>
+    </Grid>
+</UserControl>

+ 49 - 0
PixiEditor/Views/UserControls/ToolSettingColorPicker.xaml.cs

@@ -0,0 +1,49 @@
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Media;
+using ColorPicker;
+using PixiEditor.Helpers;
+using PixiEditor.ViewModels;
+
+namespace PixiEditor.Views
+{
+    /// <summary>
+    /// Interaction logic for ToolSettingColorPicker.xaml.
+    /// </summary>
+    public partial class ToolSettingColorPicker : UserControl
+    {
+        public static DependencyProperty SelectedColorProperty =
+            DependencyProperty.Register(nameof(SelectedColor), typeof(Color), typeof(ToolSettingColorPicker));
+
+        public Color SelectedColor
+        {
+            get => (Color)GetValue(SelectedColorProperty);
+            set
+            {
+                SetValue(SelectedColorProperty, value);
+            }
+        }
+
+        public static readonly DependencyProperty CopyMainColorCommandProperty = DependencyProperty.Register(
+            nameof(CopyMainColorCommand), typeof(RelayCommand), typeof(ToolSettingColorPicker));
+
+        public RelayCommand CopyMainColorCommand
+        {
+            get { return (RelayCommand)GetValue(CopyMainColorCommandProperty); }
+            set { SetValue(CopyMainColorCommandProperty, value); }
+        }
+
+        public ToolSettingColorPicker()
+        {
+            InitializeComponent();
+
+            CopyMainColorCommand = new RelayCommand(CopyMainColor);
+        }
+
+        public void CopyMainColor(object parameter)
+        {
+            SelectedColor = ViewModelMain.Current.ColorsSubViewModel.PrimaryColor;
+        }
+    }
+}