Bladeren bron

Distanc wip

flabbet 3 jaren geleden
bovenliggende
commit
ba0c9cd643

+ 5 - 0
PixiEditor/Views/Dialogs/PalettesBrowser.xaml.cs

@@ -440,6 +440,11 @@ namespace PixiEditor.Views.Dialogs
             var palette = _localPalettesFetcher.CachedPalettes.FirstOrDefault(x => x.FileName == finalFileName);
             if (palette != null)
             {
+                if (SortedResults == null)
+                {
+                    SortedResults = new WpfObservableRangeCollection<Palette>();
+                }
+
                 if (SortedResults.Contains(palette))
                 {
                     SortedResults.Move(SortedResults.IndexOf(palette), 0);

+ 1 - 1
PixiEditor/Views/UserControls/Palettes/PaletteColor.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              xmlns:palettes="clr-namespace:PixiEditor.Views.UserControls.Palettes"
-             mc:Ignorable="d"
+             mc:Ignorable="d" MouseDown="PaletteColor_OnMouseDown"
              d:DesignHeight="45" d:DesignWidth="45" Name="uc" MouseMove="PaletteColor_OnMouseMove">
     <UserControl.Resources>
         <converters:SKColorToMediaColorConverter x:Key="SKColorToMediaColorConverter" />

+ 23 - 6
PixiEditor/Views/UserControls/Palettes/PaletteColor.xaml.cs

@@ -1,4 +1,5 @@
-using System.Windows;
+using System;
+using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using SkiaSharp;
@@ -39,7 +40,8 @@ public partial class PaletteColor : UserControl
     public static readonly DependencyProperty CornerRadiusProperty =
         DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(PaletteColor), new PropertyMetadata(new CornerRadius(5f)));
 
-
+    private Point prevPos;
+    private Point clickPoint;
 
     public PaletteColor()
     {
@@ -51,10 +53,25 @@ public partial class PaletteColor : UserControl
         PaletteColor color = sender as PaletteColor;
         if (color != null && e.LeftButton == MouseButtonState.Pressed)
         {
-            DataObject data = new DataObject();
-            data.SetData(PaletteColor.PaletteColorDaoFormat, color.Color.ToString());
-            DragDrop.DoDragDrop(color, data, DragDropEffects.Move);
-            e.Handled = true;
+            var newPos = e.GetPosition(this) - clickPoint;
+            Vector delta = new Vector(newPos.X - prevPos.X, newPos.Y - prevPos.Y);
+            if (Math.Abs(delta.Length) > 10)
+            {
+                DataObject data = new DataObject();
+                data.SetData(PaletteColor.PaletteColorDaoFormat, color.Color.ToString());
+                DragDrop.DoDragDrop(color, data, DragDropEffects.Move);
+                e.Handled = true;
+            }
+
+            prevPos = new Point(newPos.X, newPos.Y);
+        }
+    }
+
+    private void PaletteColor_OnMouseDown(object sender, MouseButtonEventArgs e)
+    {
+        if (e.ChangedButton == MouseButton.Left)
+        {
+            clickPoint = e.GetPosition(this);
         }
     }
 }