Browse Source

Show layers in a reversed (correct) order

Equbuxu 3 years ago
parent
commit
fe53cf0312

+ 6 - 6
src/PixiEditorPrototype/Models/DocumentStructureHelper.cs

@@ -88,7 +88,7 @@ namespace PixiEditorPrototype.Models
             return false;
         }
 
-        public void MoveStructureMember(Guid guid, bool up)
+        public void MoveStructureMember(Guid guid, bool toSmallerIndex)
         {
             var path = FindPath(guid);
             if (path.Count < 2)
@@ -96,21 +96,21 @@ namespace PixiEditorPrototype.Models
             if (path.Count == 2)
             {
                 int curIndex = doc.StructureRoot.Children.IndexOf(path[0]);
-                if (curIndex == 0 && up || curIndex == doc.StructureRoot.Children.Count - 1 && !up)
+                if (curIndex == 0 && toSmallerIndex || curIndex == doc.StructureRoot.Children.Count - 1 && !toSmallerIndex)
                     return;
-                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, doc.StructureRoot.GuidValue, up ? curIndex - 1 : curIndex + 1));
+                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, doc.StructureRoot.GuidValue, toSmallerIndex ? curIndex - 1 : curIndex + 1));
                 return;
             }
             var folder = (FolderViewModel)path[1];
             int index = folder.Children.IndexOf(path[0]);
-            if (up && index > 0 || !up && index < folder.Children.Count - 1)
+            if (toSmallerIndex && index > 0 || !toSmallerIndex && index < folder.Children.Count - 1)
             {
-                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, path[1].GuidValue, up ? index - 1 : index + 1));
+                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, path[1].GuidValue, toSmallerIndex ? index - 1 : index + 1));
             }
             else
             {
                 int parentIndex = ((FolderViewModel)path[2]).Children.IndexOf(folder);
-                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, path[2].GuidValue, up ? parentIndex : parentIndex + 1));
+                doc.ActionAccumulator.AddAction(new MoveStructureMember_Action(guid, path[2].GuidValue, toSmallerIndex ? parentIndex : parentIndex + 1));
             }
         }
     }

+ 45 - 0
src/PixiEditorPrototype/ReverseOrderStackPanel.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Linq;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PixiEditorPrototype
+{
+    public class ReversedOrderStackPanel : StackPanel
+    {
+        protected override Size ArrangeOverride(Size arrangeSize)
+        {
+            bool fHorizontal = Orientation == Orientation.Horizontal;
+            Rect rcChild = new Rect(arrangeSize);
+            double previousChildSize = 0.0;
+
+            System.Collections.Generic.IEnumerable<UIElement> children = InternalChildren.Cast<UIElement>().Reverse();
+            foreach (UIElement child in children)
+            {
+                if (child == null)
+                {
+                    continue;
+                }
+
+                if (fHorizontal)
+                {
+                    rcChild.X += previousChildSize;
+                    previousChildSize = child.DesiredSize.Width;
+                    rcChild.Width = previousChildSize;
+                    rcChild.Height = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
+                }
+                else
+                {
+                    rcChild.Y += previousChildSize;
+                    previousChildSize = child.DesiredSize.Height;
+                    rcChild.Height = previousChildSize;
+                    rcChild.Width = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
+                }
+
+                child.Arrange(rcChild);
+            }
+
+            return arrangeSize;
+        }
+    }
+}

+ 2 - 2
src/PixiEditorPrototype/ViewModels/StructureMemberViewModel.cs

@@ -49,8 +49,8 @@ namespace PixiEditorPrototype.ViewModels
         {
             this.member = member;
             Document = doc;
-            MoveUpCommand = new(_ => Document.StructureHelper.MoveStructureMember(GuidValue, true));
-            MoveDownCommand = new(_ => Document.StructureHelper.MoveStructureMember(GuidValue, false));
+            MoveUpCommand = new(_ => Document.StructureHelper.MoveStructureMember(GuidValue, false));
+            MoveDownCommand = new(_ => Document.StructureHelper.MoveStructureMember(GuidValue, true));
             UpdateOpacityCommand = new(UpdateOpacity);
             EndOpacityUpdateCommand = new(EndOpacityUpdate);
         }

+ 6 - 0
src/PixiEditorPrototype/Views/DocumentView.xaml

@@ -4,6 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PixiEditorPrototype.Views"
+             xmlns:pe="clr-namespace:PixiEditorPrototype"
              xmlns:models="clr-namespace:PixiEditorPrototype.Models"
              xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker"
              xmlns:behaviors="clr-namespace:PixiEditorPrototype.Behaviors"
@@ -34,6 +35,11 @@
                     <TextBlock Text="{Binding SelectedStructureMember.Opacity, StringFormat=N2}" TextAlignment="Center" d:Text="1.00" Width="30"></TextBlock>
                 </StackPanel>
                 <TreeView ItemsSource="{Binding StructureRoot.Children}">
+                    <TreeView.ItemsPanel>
+                        <ItemsPanelTemplate>
+                            <pe:ReversedOrderStackPanel/>
+                        </ItemsPanelTemplate>
+                    </TreeView.ItemsPanel>
                     <i:Interaction.Triggers>
                         <i:EventTrigger EventName="SelectedItemChanged">
                             <i:InvokeCommandAction Command="{Binding ChangeSelectedItemCommand}" PassEventArgsToCommand="True"/>