Browse Source

Fixed double click drop, improved drag n drop, fixed prev window opacity

flabbet 4 years ago
parent
commit
7663ded8d3

+ 2 - 2
PixiEditor/Views/UserControls/LayerGroupControl.xaml.cs

@@ -23,8 +23,8 @@ namespace PixiEditor.Views.UserControls
             set { SetValue(GroupGuidProperty, value); }
         }
 
-        private const string LayerGroupControlDataName = "PixiEditor.Views.UserControls.LayerGroupControl";
-        private const string LayerContainerDataName = "PixiEditor.Views.UserControls.LayerStructureItemContainer";
+        public const string LayerGroupControlDataName = "PixiEditor.Views.UserControls.LayerGroupControl";
+        public const string LayerContainerDataName = "PixiEditor.Views.UserControls.LayerStructureItemContainer";
 
         // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty GroupGuidProperty =

+ 7 - 4
PixiEditor/Views/UserControls/LayerItem.xaml

@@ -23,11 +23,11 @@
         <Grid>
             <Grid.RowDefinitions>
                 <RowDefinition Height="10"/>
-                <RowDefinition Height="15"/>
-                <RowDefinition Height="10"/>
+                <RowDefinition Height="25"/>
+ 
             </Grid.RowDefinitions>
             <Grid AllowDrop="True" DragEnter="Grid_DragEnter" Drop="Grid_Drop_Top" DragLeave="Grid_DragLeave" Grid.Row="0" Grid.ColumnSpan="3" Background="Transparent"/>
-            <Grid Grid.Row="1" Grid.RowSpan="3" Margin="0,-10,0,0" VerticalAlignment="Center" DragEnter="Grid_DragEnter" DragLeave="Grid_DragLeave">
+            <Grid Grid.Row="1" Grid.RowSpan="3" Margin="0,-10,0,0" VerticalAlignment="Center" AllowDrop="False">
                 <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="30"/>
                     <ColumnDefinition Width="*"/>
@@ -48,8 +48,11 @@
                     VerticalAlignment="Center"
                     Text="{Binding LayerName, ElementName=uc, Mode=TwoWay}" />
                 </StackPanel>
+                <Grid Margin="0, 0, 0, -2.5" DragEnter="Grid_DragEnter" VerticalAlignment="Bottom" Height="10" Drop="Grid_Drop_Below"  DragLeave="Grid_DragLeave" Grid.Row="2" Grid.Column="0" AllowDrop="True"  Background="Transparent" Name="dropBelowGrid"/>
+                <Grid Margin="0, 0, 0, -2.5" VerticalAlignment="Bottom" Height="10" Grid.Row="2" Grid.Column="1" Background="{Binding ElementName=dropBelowGrid, Path=Background}"/>
+                
+                <Grid Margin="0, 0, 0, -2.5" DragEnter="Grid_DragEnter" VerticalAlignment="Bottom" Height="10" Drop="Grid_Drop_Bottom" DragLeave="Grid_DragLeave" Grid.Row="2" Grid.Column="2" AllowDrop="True"  Background="Transparent"/>
             </Grid>
-            <Grid DragEnter="Grid_DragEnter" Drop="Grid_Drop_Bottom" DragLeave="Grid_DragLeave" Grid.Row="2" AllowDrop="True" Grid.ColumnSpan="3" Background="Transparent"/>
         </Grid>
     </Border>
 </UserControl>

+ 14 - 3
PixiEditor/Views/UserControls/LayerItem.xaml.cs

@@ -155,7 +155,7 @@ namespace PixiEditor.Views
             RemoveDragEffect(item);
         }
 
-        private void HandleGridDrop(object sender, DragEventArgs e, bool above)
+        private void HandleGridDrop(object sender, DragEventArgs e, bool above, bool dropInParentFolder = false)
         {
             Grid item = sender as Grid;
             RemoveDragEffect(item);
@@ -164,8 +164,14 @@ namespace PixiEditor.Views
             {
                 var data = (LayerStructureItemContainer)e.Data.GetData("PixiEditor.Views.UserControls.LayerStructureItemContainer");
                 Guid layer = data.Layer.LayerGuid;
+                var doc = data.LayerCommandsViewModel.Owner.BitmapManager.ActiveDocument;
 
-                data.LayerCommandsViewModel.Owner.BitmapManager.ActiveDocument.MoveLayerInStructure(layer, LayerGuid, above);
+                doc.MoveLayerInStructure(layer, LayerGuid, above);
+                if (dropInParentFolder)
+                {
+                    Guid? groupGuid = doc.LayerStructure.GetGroupByLayer(layer)?.Parent?.GroupGuid;
+                    doc.LayerStructure.AssignParent(layer, groupGuid);
+                }
             }
 
             if (e.Data.GetDataPresent("PixiEditor.Views.UserControls.LayerGroupControl"))
@@ -194,6 +200,11 @@ namespace PixiEditor.Views
         private void Grid_Drop_Bottom(object sender, DragEventArgs e)
         {
             HandleGridDrop(sender, e, false);
-        }
+        }
+
+        private void Grid_Drop_Below(object sender, DragEventArgs e)
+        {
+            HandleGridDrop(sender, e, false, true);
+        }
     }
 }

+ 1 - 1
PixiEditor/Views/UserControls/LayersManager.xaml

@@ -60,7 +60,7 @@
         <TreeView TreeViewItem.PreviewMouseLeftButtonDown="TreeView_PreviewMouseLeftButtonDown"  Name="treeView" Grid.Row="2" Margin="0, -12, 0, 0" ItemsSource="{Binding LayerTreeRoot, ElementName=layersManager}"  SelectedItemChanged="TreeView_SelectedItemChanged">
                 <TreeView.ItemsPanel>
                     <ItemsPanelTemplate>
-                        <ui:ReversedOrderStackPanel/>
+                        <ui:ReversedOrderStackPanel AllowDrop="True" Drop="ReversedOrderStackPanel_Drop"/>
                     </ItemsPanelTemplate>
                 </TreeView.ItemsPanel>
                 <TreeView.Resources>

+ 8 - 3
PixiEditor/Views/UserControls/LayersManager.xaml.cs

@@ -156,7 +156,7 @@ namespace PixiEditor.Views.UserControls
                         new object[] { val }));
                 undoManager.SquashUndoChanges(2);
             }
-            else if(item is LayerGroup group)
+            else if (item is LayerGroup group)
             {
                 HandleGroupOpacityChange(group, val);
             }
@@ -164,7 +164,7 @@ namespace PixiEditor.Views.UserControls
 
         private void UpdateNumberInputLayerOpacityProcess(object[] args)
         {
-            if(args.Length > 0 && args[0] is float opacity)
+            if (args.Length > 0 && args[0] is float opacity)
             {
                 numberInput.Value = opacity * 100;
             }
@@ -179,12 +179,17 @@ namespace PixiEditor.Views.UserControls
         {
             if (e.ClickCount > 1)
             {
-                if(sender is TreeView treeView && treeView.SelectedItem is LayerGroup group)
+                if (sender is TreeView treeView && treeView.SelectedItem is LayerGroup group)
                 {
                     group.StructureData.IsRenaming = true;
                     e.Handled = true;
                 }
             }
         }
+
+        private void ReversedOrderStackPanel_Drop(object sender, DragEventArgs e)
+        {
+            
+        }
     }
 }

+ 8 - 2
PixiEditor/Views/UserControls/PreviewWindow.xaml

@@ -36,8 +36,14 @@
                             <Image VerticalAlignment="Top" HorizontalAlignment="Left" Source="{Binding LayerBitmap}"
                                                Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"
                                                RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="Uniform"
-                                               Opacity="{Binding Opacity}"
-                                               Width="{Binding Width}" Height="{Binding Height}" Margin="{Binding Offset}"  />
+                                               Width="{Binding Width}" Height="{Binding Height}" Margin="{Binding Offset}">
+                            <Image.Opacity>
+                                    <MultiBinding Converter="{converters:LayerToFinalOpacityConverter}">
+                                        <Binding Path="."/>
+                                        <Binding Path="Opacity"/>
+                                    </MultiBinding>
+                            </Image.Opacity>
+                            </Image>
                         </DataTemplate>
                     </ItemsControl.ItemTemplate>
                 </ItemsControl>