Browse Source

Added New Layer button and layer sorting

flabbet 5 years ago
parent
commit
174b7cdb26

+ 8 - 1
PixiEditorDotNetCore3/Models/Layers/Layer.cs

@@ -55,7 +55,7 @@ namespace PixiEditorDotNetCore3.Models.Layers
             LayerBitmap.Unlock();
         }
 
-       
+
         public byte[] ConvertBitmapToBytes()
         {            
             LayerBitmap.Lock();
@@ -72,5 +72,12 @@ namespace PixiEditorDotNetCore3.Models.Layers
             return byteArray;
         }
 
+        public void Resize(int newWidth, int newHeight)
+        {
+            LayerBitmap.Resize(newWidth, newHeight, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
+            Height = newHeight;
+            Width = newWidth;
+        }
+
     }
 }

+ 2 - 2
PixiEditorDotNetCore3/Styles/ThemeStyle.xaml

@@ -16,8 +16,8 @@
 
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsEnabled" Value="False">
-                            <Setter Property="Background" Value="#404040"/>
-                            <Setter Property="Foreground" Value="White"/>
+                            <Setter Property="Background" Value="Transparent"/>
+                            <Setter Property="Foreground" Value="Gray"/>
                             <Setter Property="Cursor" Value="Arrow"/>
                         </Trigger>
                         <Trigger Property="IsMouseOver" Value="True">

+ 22 - 0
PixiEditorDotNetCore3/ViewModels/ViewModelMain.cs

@@ -5,6 +5,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Drawing.Drawing2D;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -40,6 +41,8 @@ namespace PixiEditor.ViewModels
         public RelayCommand MouseUpCommand { get; set; }
         public RelayCommand RecenterZoomboxCommand { get; set; }
         public RelayCommand OpenFileCommand { get; set; }
+        public RelayCommand SetActiveLayerCommand { get; set; }
+        public RelayCommand NewLayerCommand { get; set; }
 
         private Image _activeImage;
 
@@ -165,6 +168,8 @@ namespace PixiEditor.ViewModels
             MouseUpCommand = new RelayCommand(MouseUp);
             RecenterZoomboxCommand = new RelayCommand(RecenterZoombox);
             OpenFileCommand = new RelayCommand(OpenFile);
+            SetActiveLayerCommand = new RelayCommand(SetActiveLayer);
+            NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
             primaryToolSet = new ToolsManager(new List<Tool> { new PixiTools.PenTool(), new PixiTools.FloodFill(), new PixiTools.LineTool(),
             new PixiTools.CircleTool(), new PixiTools.RectangleTool(), new PixiTools.EarserTool(), new PixiTools.BrightnessTool()});
             UndoManager.SetMainRoot(this);
@@ -284,6 +289,7 @@ namespace PixiEditor.ViewModels
             }
         }
 
+
         private void ExecuteColorPicker(Coordinates cords)
         {
             if (Mouse.LeftButton == MouseButtonState.Pressed)
@@ -380,5 +386,21 @@ namespace PixiEditor.ViewModels
 
             MessageBox.Show("This feature is not implemented yet.", "Feature not implemented", MessageBoxButton.OK, MessageBoxImage.Information);
         }
+
+        public void SetActiveLayer(object parameter)
+        {
+            ActiveLayer = Layers[(int) parameter];
+        }
+
+        public void NewLayer(object parameter)
+        {
+            Layers.Add(new Layer("New Layer", Layers[0].Width, Layers[0].Height));
+            Layers.Move(Layers.Count - 1, 0);
+        }
+
+        public bool CanCreateNewLayer(object parameter)
+        {
+            return Layers.Count > 0;
+        }
     }
 }

+ 9 - 5
PixiEditorDotNetCore3/Views/MainWindow.xaml

@@ -198,13 +198,17 @@
         </Grid>
 
         <StackPanel Grid.Column="2" Grid.Row="1" Orientation="Vertical">
-            <ListView ItemsSource="{Binding Layers}">
-                <ListView.ItemTemplate>
+            <Button Command="{Binding NewLayerCommand}" Height="30" Content="New Layer" HorizontalAlignment="Stretch" Margin="5" Style="{StaticResource DarkRoundButton}"/>
+            <ItemsControl ItemsSource="{Binding Layers}" AlternationCount="9999">
+                
+                <ItemsControl.ItemTemplate>
                     <DataTemplate>
-                        <TextBlock Text="{Binding Name}"></TextBlock>
+                        <Button Content="{Binding Name}" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, 
+                            Path=DataContext.SetActiveLayerCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                            Path=(ItemsControl.AlternationIndex)}"/>
                     </DataTemplate>
-                </ListView.ItemTemplate>
-            </ListView>
+                </ItemsControl.ItemTemplate>
+            </ItemsControl>
         </StackPanel>
 
     </Grid>