Przeglądaj źródła

Merge pull request #11 from flabbet/dev

0.0.3.1 update
Krzysztof Krysiński 5 lat temu
rodzic
commit
98b8243e05

BIN
PixiEditor/Images/SwapArrows.png


+ 28 - 0
PixiEditor/Models/Controllers/Shortcuts/Shortcut.cs

@@ -0,0 +1,28 @@
+using System.Windows.Input;
+
+namespace PixiEditor.Models.Controllers
+{
+    public class Shortcut
+    {
+        public Key ShortcutKey { get; set; }
+        public ModifierKeys Modifier { get; set; }
+        public ICommand Command { get; set; }
+        public object CommandParameter { get; set; }
+
+        public Shortcut(Key shortcutKey, ICommand command, object commandParameter = null, ModifierKeys modifier = ModifierKeys.None)
+        {
+            ShortcutKey = shortcutKey;
+            Modifier = modifier;
+            Command = command;
+            CommandParameter = commandParameter;
+        }
+
+        public void Execute()
+        {
+            if(Command.CanExecute(CommandParameter))
+            {
+                Command.Execute(CommandParameter);
+            }
+        }
+    }
+}

+ 38 - 0
PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Input;
+
+namespace PixiEditor.Models.Controllers
+{
+    public class ShortcutController
+    {
+        public static bool BlockShortcutExecution { get; set; }
+
+        public List<Shortcut> Shortcuts { get; set; }       
+
+        public ShortcutController()
+        {
+            Shortcuts = new List<Shortcut>();
+            
+        }
+
+        public void KeyPressed(Key key)
+        {
+            if (!BlockShortcutExecution)
+            {
+                Shortcut[] shortcuts = Shortcuts.FindAll(x => x.ShortcutKey == key).ToArray();
+                if (shortcuts.Length < 1) return;
+                shortcuts = shortcuts.OrderByDescending(x => x.Modifier).ToArray();
+                for (int i = 0; i < shortcuts.Length; i++)
+                {
+                    if (Keyboard.Modifiers.HasFlag(shortcuts[i].Modifier))
+                    {
+                        shortcuts[i].Execute();
+                        break;
+                    }
+                }
+            }
+        }
+    }
+}

+ 2 - 36
PixiEditor/Models/Controllers/UndoManager.cs

@@ -38,42 +38,7 @@ namespace PixiEditor.Models.Controllers
         {
             MainRoot = root;
         }
-
-        /// <summary>
-        /// Records changes, used to save multiple changes as one
-        /// </summary>
-        /// <param name="property">Record property name.</param>
-        /// <param name="oldValue">Old change value.</param>
-        /// <param name="newValue">New change value.</param>
-        /// <param name="undoDescription">Description of change.</param>
-        public static void RecordChanges(string property, object oldValue, object newValue, string undoDescription = "")
-        {
-            if (_stopRecording == false)
-            {
-                if (_recordedChanges.Count >= 2)
-                {
-                    _recordedChanges.RemoveAt(_recordedChanges.Count - 1);
-                }
-                _recordedChanges.Add(new Change(property, oldValue, newValue, undoDescription));
-
-            }
-        }
-
-        /// <summary>
-        /// Stops recording changes and saves it as one.
-        /// </summary>
-        public static void StopRecording()
-        {
-            _stopRecording = true;
-            if (_recordedChanges.Count > 0)
-            {
-                Change changeToSave = _recordedChanges[0];
-                changeToSave.NewValue = _recordedChanges.Last().OldValue;
-                AddUndoChange(changeToSave);
-                _recordedChanges.Clear();
-            }
-            _stopRecording = false;
-        }
+      
 
         public static void AddUndoChange(Change change)
         {
@@ -84,6 +49,7 @@ namespace PixiEditor.Models.Controllers
             _lastChangeWasUndo = false;
             UndoStack.Push(change);
         }
+
         /// <summary>
         /// Adds property change to UndoStack
         /// </summary>

+ 13 - 0
PixiEditor/Models/Layers/Layer.cs

@@ -41,6 +41,19 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private bool _isRenaming = false;
+
+        public bool IsRenaming
+        {
+            get { return _isRenaming; }
+            set
+            {
+                _isRenaming = value;
+                RaisePropertyChanged("IsRenaming");
+            }
+        }
+
+
         public WriteableBitmap LayerBitmap
         {
             get => _layerBitmap;

+ 2 - 1
PixiEditor/Models/Tools/ShapeTool.cs

@@ -2,7 +2,7 @@
 using PixiEditor.Models.Position;
 using System;
 using System.Collections.Generic;
-using System.Text;
+using System.Windows.Input;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools
@@ -16,6 +16,7 @@ namespace PixiEditor.Models.Tools
         public ShapeTool()
         {
             RequiresPreviewLayer = true;
+            Cursor = Cursors.Cross;
         }
 
         protected Coordinates[] BresenhamLine(int x1, int y1, int x2, int y2)

+ 2 - 3
PixiEditor/Models/Tools/Tool.cs

@@ -1,8 +1,6 @@
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
-using System;
-using System.Collections.Generic;
-using System.Text;
+using System.Windows.Input;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools
@@ -12,5 +10,6 @@ namespace PixiEditor.Models.Tools
         public abstract BitmapPixelChanges Use(Layer layer, Coordinates[] pixels, Color color, int toolSize);
         public abstract ToolType ToolType { get; }
         public bool RequiresPreviewLayer { get; set; }
+        public Cursor Cursor { get; set; } = Cursors.Arrow;
     }
 }

+ 5 - 0
PixiEditor/Models/Tools/Tools/PenTool.cs

@@ -3,6 +3,7 @@ using PixiEditor.Models.Position;
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Windows.Input;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools.Tools
@@ -11,6 +12,10 @@ namespace PixiEditor.Models.Tools.Tools
     {
         public override ToolType ToolType => ToolType.Pen;
 
+        public PenTool()
+        {
+            Cursor = Cursors.Pen;
+        }
 
         public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color, int toolSize)
         {

+ 56 - 46
PixiEditor/PixiEditor.csproj

@@ -1,47 +1,57 @@
-<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
-
-  <PropertyGroup>
-    <OutputType>WinExe</OutputType>
-    <TargetFramework>netcoreapp3.0</TargetFramework>
-    <UseWPF>true</UseWPF>
-    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
-    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
-    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
-    <AssemblyName>PixiEditor</AssemblyName>
-    <RootNamespace>PixiEditor</RootNamespace>
-    <RepositoryUrl>https://github.com/flabbet/PixiEditor</RepositoryUrl>
-    <PackageLicenseFile>LICENSE</PackageLicenseFile>
-  </PropertyGroup>
-  <ItemGroup>
-    <PackageReference Include="Expression.Blend.Sdk">
-      <Version>1.0.2</Version>
-    </PackageReference>
-    <PackageReference Include="Extended.Wpf.Toolkit">
-      <Version>3.8.1</Version>
-    </PackageReference>
-    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
-    <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
-    <PackageReference Include="WriteableBitmapEx">
-      <Version>1.6.5</Version>
-    </PackageReference>
-  </ItemGroup>
-  <ItemGroup>
-    <Resource Include="Images\BucketImage.png" />
-    <Resource Include="Images\CircleImage.png" />
-    <Resource Include="Images\Cross.png" />
-    <Resource Include="Images\EarserImage.png" />
-    <Resource Include="Images\LightenImage.png" />
-    <Resource Include="Images\LineImage.png" />
-    <Resource Include="Images\PenImage.png" />
-    <Resource Include="Images\PipetteImage.png" />
-    <Resource Include="Images\RectangleImage.png" />
-    <Resource Include="Images\transparentbg.png" />
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="..\LICENSE">
-      <Pack>True</Pack>
-      <PackagePath></PackagePath>
-    </None>
-  </ItemGroup>
-  
+<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
+
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <UseWPF>true</UseWPF>
+    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
+    <AssemblyName>PixiEditor</AssemblyName>
+    <RootNamespace>PixiEditor</RootNamespace>
+    <RepositoryUrl>https://github.com/flabbet/PixiEditor</RepositoryUrl>
+    <PackageLicenseFile>LICENSE</PackageLicenseFile>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <None Remove="Images\SwapArrows.png" />
+    <None Include="..\LICENSE">
+      <Pack>True</Pack>
+      <PackagePath></PackagePath>
+    </None>
+  </ItemGroup>
+  <ItemGroup>
+    <PackageReference Include="Expression.Blend.Sdk">
+      <Version>1.0.2</Version>
+    </PackageReference>
+    <PackageReference Include="Extended.Wpf.Toolkit">
+      <Version>3.8.1</Version>
+    </PackageReference>
+    <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
+    <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
+    <PackageReference Include="WriteableBitmapEx">
+      <Version>1.6.5</Version>
+    </PackageReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Resource Include="Images\BucketImage.png" />
+    <Resource Include="Images\CircleImage.png" />
+    <Resource Include="Images\Cross.png" />
+    <Resource Include="Images\EarserImage.png" />
+    <Resource Include="Images\LightenImage.png" />
+    <Resource Include="Images\LineImage.png" />
+    <Resource Include="Images\PenImage.png" />
+    <Resource Include="Images\PipetteImage.png" />
+    <Resource Include="Images\RectangleImage.png" />
+    <Resource Include="Images\SwapArrows.png" />
+    <Resource Include="Images\transparentbg.png" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="..\LICENSE">
+      <Pack>True</Pack>
+      <PackagePath></PackagePath>
+    </None>
+  </ItemGroup>
+  
 </Project>

+ 3 - 2
PixiEditor/Properties/AssemblyInfo.cs

@@ -51,5 +51,6 @@ using System.Windows;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.0.2.0")]
-[assembly: AssemblyFileVersion("9.0.2.0")]
+
+[assembly: AssemblyVersion("0.0.3.1")]
+[assembly: AssemblyFileVersion("0.0.3.1")]

+ 42 - 8
PixiEditor/Styles/ThemeStyle.xaml

@@ -66,6 +66,25 @@
     </Style>
 
 
+    <Style TargetType="Button" x:Key="ImageButtonStyle">
+        <Setter Property="OverridesDefaultStyle" Value="True"/>
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="Button">
+                    <Border BorderThickness="0" Opacity="{TemplateBinding Opacity}" Name="brd" Background="{TemplateBinding Background}">
+                        <ContentPresenter/>
+                    </Border>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsMouseOver" Value="True">
+                            <Setter Property="Opacity" TargetName="brd" Value="1"/>
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
+
+
     <Style TargetType="TextBox" x:Key="DarkTextBoxStyle">
         <Setter Property="Background" Value="#202020"/>
         <Setter Property="BorderThickness" Value="1"/>
@@ -87,20 +106,35 @@
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type ContextMenu}">
-                    <Border Background="#303030" BorderBrush="White" BorderThickness="1" Opacity="0.96">
+                    <Border Background="#202020" BorderBrush="Black" BorderThickness="1" Opacity="0.96">
                         <StackPanel ClipToBounds="True" Orientation="Vertical" IsItemsHost="True"/>
                     </Border>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
-    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
-        <Border Name="Border" >
-            <Grid>
-                <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
-            </Grid>
-        </Border>
-    </ControlTemplate>
+    <Style TargetType="MenuItem">
+        <Setter Property="OverridesDefaultStyle" Value="True"/>
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="MenuItem">
+                    <Border x:Name="Bd" Background="Transparent" Margin="10 0 10 0">
+                        <Grid>
+                            <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True" />
+                        </Grid>
+                    </Border>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsHighlighted"  Value="True">
+                            <Setter Property="Background" TargetName="Bd" Value="Gray"/>
+                        </Trigger>
+                        <Trigger Property="IsEnabled" Value="False">
+                            <Setter Property="Foreground" Value="Gray"/>
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
 
 
 </ResourceDictionary>

+ 56 - 1
PixiEditor/ViewModels/ViewModelMain.cs

@@ -13,6 +13,7 @@ using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Views;
 
 namespace PixiEditor.ViewModels
 {
@@ -23,6 +24,7 @@ namespace PixiEditor.ViewModels
         public RelayCommand GenerateDrawAreaCommand { get; set; } //Command that generates draw area
         public RelayCommand MouseMoveCommand { get; set; } //Command that is used to draw
         public RelayCommand MouseDownCommand { get; set; }
+        public RelayCommand KeyDownCommand { get; set; }
         public RelayCommand SaveFileCommand { get; set; } //Command that is used to save file
         public RelayCommand UndoCommand { get; set; }
         public RelayCommand RedoCommand { get; set; }
@@ -33,8 +35,10 @@ namespace PixiEditor.ViewModels
         public RelayCommand NewLayerCommand { get; set; }
         public RelayCommand ReloadImageCommand { get; set; }
         public RelayCommand DeleteLayerCommand { get; set; }
+        public RelayCommand RenameLayerCommand { get; set; }
         public RelayCommand MoveToBackCommand { get; set; }
         public RelayCommand MoveToFrontCommand { get; set; }
+        public RelayCommand SwapColorsCommand { get; set; }
 
         private double _mouseXonCanvas;
 
@@ -126,6 +130,8 @@ namespace PixiEditor.ViewModels
         public BitmapOperationsUtility BitmapUtility { get; set; }
         public PixelChangesController ChangesController { get; set; }
 
+        public ShortcutController ShortcutController { get; set; }
+
         public ViewModelMain()
         {
             PixiFilesManager.InitializeTempDirectories();
@@ -148,14 +154,46 @@ namespace PixiEditor.ViewModels
             DeleteLayerCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
             MoveToBackCommand = new RelayCommand(MoveLayerToBack, CanMoveToBack);
             MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
+            SwapColorsCommand = new RelayCommand(SwapColors);
+            KeyDownCommand = new RelayCommand(KeyDown);
+            RenameLayerCommand = new RelayCommand(RenameLayer);
             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() };
+            ShortcutController = new ShortcutController
+            {
+                Shortcuts = new List<Shortcut> { 
+                    new Shortcut(Key.B, SelectToolCommand, ToolType.Pen),
+                    new Shortcut(Key.X, SwapColorsCommand),
+                    new Shortcut(Key.O, OpenFileCommand, null, ModifierKeys.Control),
+                    new Shortcut(Key.E, SelectToolCommand, ToolType.Earser),
+                    new Shortcut(Key.O, SelectToolCommand, ToolType.ColorPicker),
+                    new Shortcut(Key.R, SelectToolCommand, ToolType.Rectangle),
+                    new Shortcut(Key.C, SelectToolCommand, ToolType.Circle),
+                    new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
+                    new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
+                    new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
+                    new Shortcut(Key.Y, RedoCommand, null, ModifierKeys.Control),
+                    new Shortcut(Key.Z, UndoCommand),
+                    new Shortcut(Key.S, UndoCommand, null, ModifierKeys.Control),
+                    new Shortcut(Key.N, GenerateDrawAreaCommand, null, ModifierKeys.Control),
+                }
+            };
             UndoManager.SetMainRoot(this);
             SetActiveTool(ToolType.Pen);
             BitmapUtility.PrimaryColor = PrimaryColor;
             ToolSize = 1;
         }
 
+        public void RenameLayer(object parameter)
+        {
+            BitmapUtility.Layers[(int)parameter].IsRenaming = true;
+        }
+
+        public void KeyDown(object parameter)
+        {
+            ShortcutController.KeyPressed(((KeyEventArgs)parameter).Key);
+        }
+
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         {
             Tuple<LayerChanges, LayerChanges> changes = ChangesController.PopChanges();
@@ -168,6 +206,13 @@ namespace PixiEditor.ViewModels
                 new LayerChanges(e.OldPixelsValues, e.ChangedLayerIndex));
         }
 
+        public void SwapColors(object parameter)
+        {
+            var tmp = PrimaryColor;
+            PrimaryColor = SecondaryColor;
+            SecondaryColor = tmp;
+        }
+
         public void MoveLayerToFront(object parameter)
         {
             int oldIndex = (int)parameter;
@@ -255,6 +300,16 @@ namespace PixiEditor.ViewModels
         private void SetActiveTool(ToolType tool)
         {
             BitmapUtility.SelectedTool = ToolSet.Find(x=> x.ToolType == tool);
+            Cursor cursor;
+            if (tool != ToolType.None && tool != ToolType.ColorPicker)
+            {
+               cursor = BitmapUtility.SelectedTool.Cursor;
+            }
+            else
+            {
+                cursor = Cursors.Arrow;
+            }
+            Mouse.OverrideCursor = cursor;
         }
         /// <summary>
         /// When mouse is up stops recording changes.

+ 1 - 3
PixiEditor/Views/EditableTextBlock.xaml

@@ -2,9 +2,7 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PixiEditor.Views"
-             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              mc:Ignorable="d" 
              d:DesignHeight="60" d:DesignWidth="100">

+ 46 - 8
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Helpers;
+using PixiEditor.Models.Controllers;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -36,12 +37,35 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty TextBlockVisibilityProperty =
             DependencyProperty.Register("TextBlockVisibility", typeof(Visibility), typeof(EditableTextBlock), new PropertyMetadata(Visibility.Visible));
 
-
-
+      
 
         // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty TextProperty =
-            DependencyProperty.Register("Text", typeof(string), typeof(EditableTextBlock), new PropertyMetadata(default(string)));
+            DependencyProperty.Register("Text", typeof(string), typeof(EditableTextBlock), new PropertyMetadata(default(string)));       
+
+
+
+
+        public bool IsEditing
+        {
+            get { return (bool)GetValue(EnableEditingProperty); }
+            set { SetValue(EnableEditingProperty, value);}
+        }
+
+        // Using a DependencyProperty as the backing store for EnableEditing.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty EnableEditingProperty =
+            DependencyProperty.Register("IsEditing", typeof(bool), typeof(EditableTextBlock), new PropertyMetadata(OnIsEditingChanged));
+
+        private static void OnIsEditingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            if((bool)e.NewValue == true)
+            {
+                EditableTextBlock tb = (EditableTextBlock)d;
+                tb.EnableEditing();
+                
+            }
+        }
+
 
         public string Text
         {
@@ -49,12 +73,26 @@ namespace PixiEditor.Views
             set { SetValue(TextProperty, value); }
         }
 
+        public void EnableEditing()
+        {
+            ShortcutController.BlockShortcutExecution = true;
+            TextBlockVisibility = Visibility.Hidden;
+            IsEditing = true;
+        }
+
+        private void DisableEditing()
+        {
+            TextBlockVisibility = Visibility.Visible;
+            ShortcutController.BlockShortcutExecution = false;
+            IsEditing = false;
+        }
+
 
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         {
-            if(e.ClickCount == 2)
+            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
             {
-                TextBlockVisibility = Visibility.Hidden;
+                EnableEditing();
             }
         }
 
@@ -62,18 +100,18 @@ namespace PixiEditor.Views
         {
             if(e.Key == Key.Enter)
             {
-                TextBlockVisibility = Visibility.Visible;
+                DisableEditing();
             }
         }
 
         private void TextBox_LostFocus(object sender, RoutedEventArgs e)
         {
-             TextBlockVisibility = Visibility.Visible;
+            DisableEditing();
         }
 
         private void textBox_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
         {
-               TextBlockVisibility = Visibility.Visible;
+            DisableEditing();
         }
     }
 }

+ 2 - 0
PixiEditor/Views/ImportFilePopup.xaml

@@ -12,6 +12,7 @@
     <Window.Resources>
         <vm:ImportFilePopupViewModel x:Key="ImportFilePopupViewModel"/>
     </Window.Resources>
+    <Border BorderBrush="Black" BorderThickness="1">
     <Grid Background="#303030">
         <Grid.RowDefinitions>
             <RowDefinition Height="4*"/>
@@ -54,4 +55,5 @@
         </StackPanel>
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10" Style="{StaticResource DarkRoundButton}" Content="OK" Command="{Binding OkCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
     </Grid>
+    </Border>
 </Window>

+ 51 - 57
PixiEditor/Views/MainWindow.xaml

@@ -11,35 +11,22 @@
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
         xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
-        xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"      
+        xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
+        xmlns:cmd="http://www.galasoft.ch/mvvmlight"
         mc:Ignorable="d"
-        Title="PixiEditor" Height="1000" Width="1600" Background="#FF252424" WindowStartupLocation="CenterScreen"  WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
+        Title="PixiEditor" Name="mainWindow" Height="1000" Width="1600" Background="#FF252424" WindowStartupLocation="CenterScreen"  WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
     <Window.Resources>
         <vm:ViewModelMain x:Key="ViewModelMain"/>
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
         <helpers:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
         <converters:BoolToColorConverter x:Key="BoolToColorConverter"/>
     </Window.Resources>
-    <Window.InputBindings>
-        <KeyBinding 
-            Modifiers="Ctrl" 
-            Key="N"                  
-            Command="{Binding GenerateDrawAreaCommand}"/>
-        <KeyBinding
-            Modifiers="Ctrl"
-            Key="S"
-            Command="{Binding SaveFileCommand}"/>
-        <KeyBinding
-            Modifiers="Ctrl"
-            Key="Z"
-            Command="{Binding UndoCommand}"/>
-        <KeyBinding 
-            Modifiers="Ctrl"
-            Key="Y"
-            Command="{Binding RedoCommand}"/>
 
-
-    </Window.InputBindings>
+    <i:Interaction.Triggers>
+        <i:EventTrigger EventName="KeyDown">
+            <cmd:EventToCommand Command="{Binding KeyDownCommand}" PassEventArgsToCommand="True"/>
+        </i:EventTrigger>
+    </i:Interaction.Triggers>
     <Grid>
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="60*"/>
@@ -119,7 +106,7 @@
             </Grid>
         </Grid>
 
-        <StackPanel Grid.Row="1" Grid.Column="0" Margin="0,5,5,0" Background="#404040">
+        <StackPanel Cursor="Arrow" Grid.Row="1" Grid.Column="0" Margin="0,5,5,0" Background="#404040">
             <TextBox Style="{StaticResource DarkTextBoxStyle}" Margin="0,10,0,0" Text="{Binding ToolSize, Mode=TwoWay,Converter={StaticResource ToolSizeToIntConverter}}" TextAlignment="Center" MaxLength="4">
                 <i:Interaction.Behaviors>
                     <behaviors:TextBoxNumericFinisherBehavior/>
@@ -160,7 +147,7 @@
                     <ImageBrush ImageSource="/Images/EarserImage.png" Stretch="Uniform"/>
                 </Button.Background>
             </Button>
-            <Button Style="{StaticResource ToolButtonStyle}" Command="{Binding SelectToolCommand, Mode=OneWay}" CommandParameter="Brightness" ToolTip="Makes pixel brighter or darker pixel (U)">
+            <Button Style="{StaticResource ToolButtonStyle}" Opacity="1" Command="{Binding SelectToolCommand, Mode=OneWay}" CommandParameter="Brightness" ToolTip="Makes pixel brighter or darker pixel (U)">
                 <Button.Background>
                     <ImageBrush ImageSource="/Images/LightenImage.png" Stretch="Uniform"/>
                 </Button.Background>
@@ -169,33 +156,38 @@
 
         <DockPanel Grid.Column="2" Grid.Row="1" Background="#404040">
             <Grid DockPanel.Dock="Top" HorizontalAlignment="Center" Width="100"  Margin="0,20,0,0" Height="100">
-            <Rectangle Height="70" Width="70" HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="Black" StrokeThickness="1" Panel.ZIndex="1">
-                <Rectangle.Fill>
-                    <SolidColorBrush Color="{Binding PrimaryColor, Mode=OneWay}"/>
-                </Rectangle.Fill>
-            </Rectangle>
-            <xctk:ColorPicker Width="70" Panel.ZIndex="2" Height="70" VerticalAlignment="Top" HorizontalAlignment="Left" UsingAlphaChannel="True" AvailableColorsSortingMode="Alphabetical" ShowDropDownButton="False" Background="Transparent" BorderThickness="0" ShowRecentColors="True" SelectedColor="{Binding PrimaryColor, Mode=TwoWay}"></xctk:ColorPicker>
-            <Rectangle Height="70" Width="70" HorizontalAlignment="Right" VerticalAlignment="Bottom" Stroke="Black" StrokeThickness="1" Margin="0,0,4,5">
-                <Rectangle.Fill>
-                    <SolidColorBrush Color="{Binding SecondaryColor, Mode=OneWay}"/>
-                </Rectangle.Fill>
-            </Rectangle>
-            <xctk:ColorPicker Width="70" Height="70" HorizontalAlignment="Right" VerticalAlignment="Bottom" UsingAlphaChannel="True" AvailableColorsSortingMode="Alphabetical" ShowDropDownButton="False" Background="Transparent" BorderThickness="0" ShowRecentColors="True" Margin="0,0,4,5" SelectedColor="{Binding SecondaryColor, Mode=TwoWay}"/>
-        </Grid>
+                <Rectangle Height="70" Width="70" HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="Black" StrokeThickness="1" Panel.ZIndex="1">
+                    <Rectangle.Fill>
+                        <SolidColorBrush Color="{Binding PrimaryColor, Mode=OneWay}"/>
+                    </Rectangle.Fill>
+                </Rectangle>
+                <xctk:ColorPicker Width="70" Panel.ZIndex="2" Height="70" VerticalAlignment="Top" HorizontalAlignment="Left" UsingAlphaChannel="True" AvailableColorsSortingMode="Alphabetical" ShowDropDownButton="False" Background="Transparent" BorderThickness="0" ShowRecentColors="True" SelectedColor="{Binding PrimaryColor, Mode=TwoWay}"></xctk:ColorPicker>
+                <Button Opacity="0.3" ToolTip="Swap colors (X)" Command="{Binding SwapColorsCommand}" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 0 0 3" Style="{StaticResource ImageButtonStyle}">
+                    <Button.Background>
+                        <ImageBrush ImageSource="/Images/SwapArrows.png" Stretch="Fill"/>
+                    </Button.Background>
+                </Button>
+                <Rectangle Height="70" Width="70" HorizontalAlignment="Right" VerticalAlignment="Bottom" Stroke="Black" StrokeThickness="1" Margin="0,0,4,5">
+                    <Rectangle.Fill>
+                        <SolidColorBrush Color="{Binding SecondaryColor, Mode=OneWay}"/>
+                    </Rectangle.Fill>
+                </Rectangle>
+                <xctk:ColorPicker Width="70" Height="70" HorizontalAlignment="Right" VerticalAlignment="Bottom" UsingAlphaChannel="True" AvailableColorsSortingMode="Alphabetical" ShowDropDownButton="False" Background="Transparent" BorderThickness="0" ShowRecentColors="True" Margin="0,0,4,5" SelectedColor="{Binding SecondaryColor, Mode=TwoWay}"/>
+            </Grid>
 
             <xcad:DockingManager Grid.Column="2" Grid.Row="1" DockPanel.Dock="Top">
-            <xcad:DockingManager.Style>
-                <Style TargetType="xcad:DockingManager">
-                    <Setter Property="Foreground" Value="Snow"/>
-                </Style>
-            </xcad:DockingManager.Style>
-            <xcad:LayoutRoot x:Name="LayoutRoot">
-                <xcad:LayoutPanel Orientation="Vertical">
-                    <xcad:LayoutAnchorablePane>
-                        <xcad:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False" CanClose="False" CanAutoHide="False" CanDockAsTabbedDocument="False" CanFloat="True">
-                            <StackPanel  Orientation="Vertical">
-                                <Button Command="{Binding NewLayerCommand}" Height="30" Content="New Layer" HorizontalAlignment="Stretch" Margin="5" Style="{StaticResource DarkRoundButton}"/>
-                                    <ItemsControl AllowDrop="True" ItemsSource="{Binding BitmapUtility.Layers}" x:Name="layersItemsControl" AlternationCount="9999">
+                <xcad:DockingManager.Style>
+                    <Style TargetType="xcad:DockingManager">
+                        <Setter Property="Foreground" Value="Snow"/>
+                    </Style>
+                </xcad:DockingManager.Style>
+                <xcad:LayoutRoot x:Name="LayoutRoot">
+                    <xcad:LayoutPanel Orientation="Vertical">
+                        <xcad:LayoutAnchorablePane>
+                            <xcad:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False" CanClose="False" CanAutoHide="False" CanDockAsTabbedDocument="False" CanFloat="True">
+                                <StackPanel  Orientation="Vertical">
+                                    <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.ItemsPanel>
                                             <ItemsPanelTemplate>
                                                 <ui:ReversedOrderStackPanel Orientation="Vertical"/>
@@ -212,6 +204,8 @@
                                                             <Button.ContextMenu>
                                                                 <ContextMenu>
                                                                     <MenuItem Header="Delete" Command="{Binding DeleteLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                            Path=(ItemsControl.AlternationIndex)}"/>
+                                                                    <MenuItem Header="Rename" Command="{Binding RenameLayerCommand, 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)}"/>
@@ -219,20 +213,20 @@
                             Path=(ItemsControl.AlternationIndex)}"/>
                                                                 </ContextMenu>
                                                             </Button.ContextMenu>
-                                                            <vws:EditableTextBlock x:Name="layerNameTB" Text="{Binding Name, Mode=TwoWay}">
+                                                            <vws:EditableTextBlock IsEditing="{Binding IsRenaming, Mode=TwoWay}" Text="{Binding Name, Mode=TwoWay}">
                                                             </vws:EditableTextBlock>
                                                         </Button>
                                                     </DockPanel>
                                                 </Border>
                                             </DataTemplate>
-                                    </ItemsControl.ItemTemplate>
-                                </ItemsControl>
-                            </StackPanel>
-                        </xcad:LayoutAnchorable>
-                    </xcad:LayoutAnchorablePane>
-                </xcad:LayoutPanel>
-            </xcad:LayoutRoot>
-        </xcad:DockingManager>
+                                        </ItemsControl.ItemTemplate>
+                                    </ItemsControl>
+                                </StackPanel>
+                            </xcad:LayoutAnchorable>
+                        </xcad:LayoutAnchorablePane>
+                    </xcad:LayoutPanel>
+                </xcad:LayoutRoot>
+            </xcad:DockingManager>
         </DockPanel>
 
     </Grid>

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

@@ -1,8 +1,13 @@
-using PixiEditor.ViewModels;
+using PixiEditor.Models.Controllers;
+using PixiEditor.Models.Layers;
+using PixiEditor.ViewModels;
+using PixiEditor.Views;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;

+ 2 - 0
PixiEditor/Views/SaveFilePopup.xaml

@@ -9,6 +9,7 @@
         xmlns:helpers="clr-namespace:PixiEditor.Helpers.Behaviours"
         mc:Ignorable="d"
         Title="SaveFilePopup" Height="250" Width="400" WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Name="saveFilePopup">
+    <Border BorderBrush="Black" BorderThickness="1">
     <Grid Background="#303030">
         <Grid.RowDefinitions>
             <RowDefinition Height="20*"/>
@@ -44,4 +45,5 @@
         <Button Grid.Row="1" Foreground="Snow" Height="40" Width="160" Margin="0,50,0,0" Content="Path" Background="#303030" BorderBrush="{Binding PathButtonBorder}" Command="{Binding ChoosePathCommand}"/>
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10" Style="{StaticResource DarkRoundButton}" Content="OK" Command="{Binding OkCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
     </Grid>
+    </Border>
 </Window>