Browse Source

Added ability to change layer name

Frytek 5 years ago
parent
commit
95f6783edc

+ 0 - 1
PixiEditor/App.xaml

@@ -1,7 +1,6 @@
 <Application x:Class="PixiEditor.App"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:local="clr-namespace:PixiEditor"
              StartupUri="Views/MainWindow.xaml">
     <Application.Resources>
         <ResourceDictionary>

+ 37 - 0
PixiEditor/Helpers/Converters/OppositeVisibilityConverter.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class OppositeVisibilityConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if(value.ToString().ToLower() == "visible")
+            {
+                return Visibility.Hidden;
+            }
+            return Visibility.Visible;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if(value is Visibility)
+            {
+                if((Visibility)value == Visibility.Visible)
+                {
+                    return "Hidden";
+                }
+                else
+                {
+                    return "Visible";
+                }
+            }
+            return null;
+        }
+    }
+}

+ 4 - 0
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -148,6 +148,10 @@ namespace PixiEditor.Models.Controllers
             {
                 SetActiveLayer(0);
             }
+            else if(ActiveLayerIndex > Layers.Count - 1)
+            {
+                SetActiveLayer(Layers.Count - 1);
+            }
         }
 
         public void AddNewLayer(string name, int width, int height, bool setAsActive = true)

+ 4 - 4
PixiEditor/PixiEditor.csproj

@@ -15,12 +15,12 @@
       <Version>1.0.2</Version>
     </PackageReference>
     <PackageReference Include="Extended.Wpf.Toolkit">
-      <Version>3.5.0</Version>
+      <Version>3.8.1</Version>
     </PackageReference>
-    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
-    <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
+    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
+    <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
     <PackageReference Include="WriteableBitmapEx">
-      <Version>1.6.2</Version>
+      <Version>1.6.5</Version>
     </PackageReference>
   </ItemGroup>
   <ItemGroup>

+ 2 - 0
PixiEditor/Styles/ThemeStyle.xaml

@@ -80,4 +80,6 @@
         <Setter Property="HorizontalAlignment" Value="Center"/>
         <Setter Property="Margin" Value="0,10,0,0"/>
     </Style>
+
+
 </ResourceDictionary>

+ 25 - 0
PixiEditor/Views/EditableTextBlock.xaml

@@ -0,0 +1,25 @@
+<UserControl x:Class="PixiEditor.Views.EditableTextBlock"
+             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:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             mc:Ignorable="d" 
+             d:DesignHeight="60" d:DesignWidth="100">
+    <UserControl.Resources>
+        <converters:OppositeVisibilityConverter x:Key="OppositeVisibilityConverter"/>
+    </UserControl.Resources>
+    <Grid>
+        <TextBlock Foreground="Snow" MouseDown="TextBlock_MouseDown"
+                   Visibility="{Binding Path=TextBlockVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" 
+                   Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"/>
+        <TextBox Style="{StaticResource DarkTextBoxStyle}" 
+                 LostFocus="TextBox_LostFocus" Text="{Binding Path=Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
+                 KeyDown="TextBox_KeyDown"                 
+                 LostKeyboardFocus="textBox_LostKeyboardFocus"
+                 Visibility="{Binding Path=TextBlockVisibility, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, 
+            Converter={StaticResource OppositeVisibilityConverter}}" Name="textBox"/>
+    </Grid>
+</UserControl>

+ 78 - 0
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PixiEditor.Views
+{
+    /// <summary>
+    /// Interaction logic for EditableTextBlock.xaml
+    /// </summary>
+    public partial class EditableTextBlock : UserControl
+    {
+        public EditableTextBlock()
+        {
+            InitializeComponent();            
+        }
+
+
+        public Visibility TextBlockVisibility
+        {
+            get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
+            set { SetValue(TextBlockVisibilityProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for TextBlockVisibility.  This enables animation, styling, binding, etc...
+        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)));
+
+        public string Text
+        {
+            get { return (string)GetValue(TextProperty); }
+            set { SetValue(TextProperty, value); }
+        }
+
+
+        private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            if(e.ClickCount == 2)
+            {
+                TextBlockVisibility = Visibility.Hidden;
+            }
+        }
+
+        private void TextBox_KeyDown(object sender, KeyEventArgs e)
+        {
+            if(e.Key == Key.Enter)
+            {
+                TextBlockVisibility = Visibility.Visible;
+            }
+        }
+
+        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+             TextBlockVisibility = Visibility.Visible;
+        }
+
+        private void textBox_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
+        {
+               TextBlockVisibility = Visibility.Visible;
+        }
+    }
+}

+ 0 - 1
PixiEditor/Views/MainDrawingPanel.xaml.cs

@@ -92,7 +92,6 @@ namespace PixiEditor.Views
         {
             if(CenterOnStart == true)
             {
-                var dragKeys = new Xceed.Wpf.Toolkit.Core.Input.KeyModifierCollection();
                 ((Zoombox)sender).CenterContent();
             }
         }

+ 4 - 33
PixiEditor/Views/MainWindow.xaml

@@ -11,7 +11,7 @@
         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"      
         mc:Ignorable="d"
         Title="PixiEditor" Height="1000" Width="1600" Background="#FF252424" WindowStartupLocation="CenterScreen"  WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
     <Window.Resources>
@@ -23,7 +23,7 @@
     <Window.InputBindings>
         <KeyBinding 
             Modifiers="Ctrl" 
-            Key="N"
+            Key="N"                  
             Command="{Binding GenerateDrawAreaCommand}"/>
         <KeyBinding
             Modifiers="Ctrl"
@@ -37,36 +37,6 @@
             Modifiers="Ctrl"
             Key="Y"
             Command="{Binding RedoCommand}"/>
-        <KeyBinding            
-            Key="B"
-            Command="{Binding SelectToolCommand}"
-            CommandParameter="Pen"/>
-        <KeyBinding
-            Key="G"
-            Command="{Binding SelectToolCommand}"
-            CommandParameter="Bucket"/>
-        <KeyBinding
-            Key="L"
-            Command="{Binding SelectToolCommand}"
-            CommandParameter="Line"/>
-        <KeyBinding
-            Key="C"
-            Command="{Binding SelectToolCommand}"
-            CommandParameter="Circle"/>
-        <KeyBinding Key="R"
-                    Command="{Binding SelectToolCommand}"
-                    CommandParameter="Rectangle"/>
-        <KeyBinding Key="O"
-                    Command="{Binding SelectToolCommand}"
-                    CommandParameter="ColorPicker"/>
-        <KeyBinding Key="E"
-                    Command="{Binding SelectToolCommand}"
-                    CommandParameter="Earser"/>
-        <KeyBinding Key="U"
-                    Command="{Binding SelectToolCommand}"
-                    CommandParameter="Lighten"/>
-        <KeyBinding Key="O" Modifiers="Ctrl"
-                    Command="{Binding OpenFileCommand}"/>
 
 
     </Window.InputBindings>
@@ -236,7 +206,7 @@
                                                 <Border BorderThickness="1" BorderBrush="Gray" MinWidth="60" Background="{Binding IsActive, Mode=TwoWay, Converter={StaticResource BoolToColorConverter}}">
                                                     <DockPanel>
                                                         <CheckBox VerticalAlignment="Center" Command="{Binding Path=DataContext.ReloadImageCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" IsThreeState="False" IsChecked="{Binding Path=IsVisible}"/>
-                                                        <Button Background="Transparent" Style="{StaticResource BaseDarkButton}" FontSize="16" DockPanel.Dock="Left" Content="{Binding Name}" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, 
+                                                        <Button Background="Transparent" Style="{StaticResource BaseDarkButton}" FontSize="16" DockPanel.Dock="Left" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, 
                             Path=DataContext.SetActiveLayerCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                             Path=(ItemsControl.AlternationIndex)}">
                                                             <Button.ContextMenu>
@@ -245,6 +215,7 @@
                             Path=(ItemsControl.AlternationIndex)}"/>
                                                                 </ContextMenu>
                                                             </Button.ContextMenu>
+                                                            <vws:EditableTextBlock Text="{Binding Name}"/>
                                                         </Button>
                                                     </DockPanel>
                                                 </Border>

+ 6 - 3
PixiEditorTests/PixiEditorTests.csproj

@@ -7,13 +7,16 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.5">
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="nunit" Version="3.12.0" />
-    <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
+    <PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
   </ItemGroup>
 
   <ItemGroup>