Browse Source

Added move layer to back and front via context menu

Frytek 5 years ago
parent
commit
848c4f28cb

+ 26 - 0
PixiEditor/ViewModels/ViewModelMain.cs

@@ -33,6 +33,8 @@ namespace PixiEditor.ViewModels
         public RelayCommand NewLayerCommand { get; set; }
         public RelayCommand NewLayerCommand { get; set; }
         public RelayCommand ReloadImageCommand { get; set; }
         public RelayCommand ReloadImageCommand { get; set; }
         public RelayCommand DeleteLayerCommand { get; set; }
         public RelayCommand DeleteLayerCommand { get; set; }
+        public RelayCommand MoveToBackCommand { get; set; }
+        public RelayCommand MoveToFrontCommand { get; set; }
 
 
         private double _mouseXonCanvas;
         private double _mouseXonCanvas;
 
 
@@ -144,6 +146,8 @@ namespace PixiEditor.ViewModels
             SetActiveLayerCommand = new RelayCommand(SetActiveLayer);
             SetActiveLayerCommand = new RelayCommand(SetActiveLayer);
             NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
             NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
             DeleteLayerCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
             DeleteLayerCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
+            MoveToBackCommand = new RelayCommand(MoveLayerToBack, CanMoveToBack);
+            MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
             ToolSet = new List<Tool> { new PixiTools.PenTool(), new PixiTools.FloodFill(), new PixiTools.LineTool(),
             ToolSet = new List<Tool> { new PixiTools.PenTool(), new PixiTools.FloodFill(), new PixiTools.LineTool(),
             new PixiTools.CircleTool(), new PixiTools.RectangleTool(), new PixiTools.EarserTool(), new PixiTools.BrightnessTool() };       
             new PixiTools.CircleTool(), new PixiTools.RectangleTool(), new PixiTools.EarserTool(), new PixiTools.BrightnessTool() };       
             UndoManager.SetMainRoot(this);
             UndoManager.SetMainRoot(this);
@@ -164,6 +168,28 @@ namespace PixiEditor.ViewModels
                 new LayerChanges(e.OldPixelsValues, e.ChangedLayerIndex));
                 new LayerChanges(e.OldPixelsValues, e.ChangedLayerIndex));
         }
         }
 
 
+        public void MoveLayerToFront(object parameter)
+        {
+            int oldIndex = (int)parameter;
+            BitmapUtility.Layers.Move(oldIndex, oldIndex + 1);
+        }
+
+        public void MoveLayerToBack(object parameter)
+        {
+            int oldIndex = (int)parameter;
+            BitmapUtility.Layers.Move(oldIndex, oldIndex - 1);
+        }
+
+        public bool CanMoveToFront(object property)
+        {
+            return BitmapUtility.Layers.Count - 1 > (int)property;
+        }
+
+        public bool CanMoveToBack(object property)
+        {
+            return (int)property > 0;
+        }
+
         public void SetActiveLayer(object parameter)
         public void SetActiveLayer(object parameter)
         {
         {
             BitmapUtility.SetActiveLayer((int)parameter);
             BitmapUtility.SetActiveLayer((int)parameter);

+ 4 - 3
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using PixiEditor.Helpers;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
@@ -19,12 +20,12 @@ namespace PixiEditor.Views
     /// </summary>
     /// </summary>
     public partial class EditableTextBlock : UserControl
     public partial class EditableTextBlock : UserControl
     {
     {
+
         public EditableTextBlock()
         public EditableTextBlock()
         {
         {
-            InitializeComponent();            
+            InitializeComponent();
         }
         }
 
 
-
         public Visibility TextBlockVisibility
         public Visibility TextBlockVisibility
         {
         {
             get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
             get { return (Visibility)GetValue(TextBlockVisibilityProperty); }

+ 7 - 2
PixiEditor/Views/MainWindow.xaml

@@ -195,7 +195,7 @@
                         <xcad:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False" CanClose="False" CanAutoHide="False" CanDockAsTabbedDocument="False" CanFloat="True">
                         <xcad:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False" CanClose="False" CanAutoHide="False" CanDockAsTabbedDocument="False" CanFloat="True">
                             <StackPanel  Orientation="Vertical">
                             <StackPanel  Orientation="Vertical">
                                 <Button Command="{Binding NewLayerCommand}" Height="30" Content="New Layer" HorizontalAlignment="Stretch" Margin="5" Style="{StaticResource DarkRoundButton}"/>
                                 <Button Command="{Binding NewLayerCommand}" Height="30" Content="New Layer" HorizontalAlignment="Stretch" Margin="5" Style="{StaticResource DarkRoundButton}"/>
-                                    <ItemsControl ItemsSource="{Binding BitmapUtility.Layers}" x:Name="layersItemsControl" AlternationCount="9999">
+                                    <ItemsControl AllowDrop="True" ItemsSource="{Binding BitmapUtility.Layers}" x:Name="layersItemsControl" AlternationCount="9999">
                                         <ItemsControl.ItemsPanel>
                                         <ItemsControl.ItemsPanel>
                                             <ItemsPanelTemplate>
                                             <ItemsPanelTemplate>
                                                 <ui:ReversedOrderStackPanel Orientation="Vertical"/>
                                                 <ui:ReversedOrderStackPanel Orientation="Vertical"/>
@@ -212,10 +212,15 @@
                                                             <Button.ContextMenu>
                                                             <Button.ContextMenu>
                                                                 <ContextMenu>
                                                                 <ContextMenu>
                                                                     <MenuItem Header="Delete" Command="{Binding DeleteLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                                                     <MenuItem Header="Delete" Command="{Binding DeleteLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                            Path=(ItemsControl.AlternationIndex)}"/>
+                                                                    <MenuItem Header="Move to front" Command="{Binding MoveToFrontCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                            Path=(ItemsControl.AlternationIndex)}"/>
+                                                                    <MenuItem Header="Move to back" Command="{Binding MoveToBackCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                             Path=(ItemsControl.AlternationIndex)}"/>
                             Path=(ItemsControl.AlternationIndex)}"/>
                                                                 </ContextMenu>
                                                                 </ContextMenu>
                                                             </Button.ContextMenu>
                                                             </Button.ContextMenu>
-                                                            <vws:EditableTextBlock Text="{Binding Name, Mode=TwoWay}"/>
+                                                            <vws:EditableTextBlock x:Name="layerNameTB" Text="{Binding Name, Mode=TwoWay}">
+                                                            </vws:EditableTextBlock>
                                                         </Button>
                                                         </Button>
                                                     </DockPanel>
                                                     </DockPanel>
                                                 </Border>
                                                 </Border>

+ 1 - 1
PixiEditor/Views/MainWindow.xaml.cs

@@ -25,6 +25,6 @@ namespace PixiEditor
         public MainWindow()
         public MainWindow()
         {
         {
             InitializeComponent();
             InitializeComponent();
-        }
+        }
     }
     }
 }
 }