Browse Source

Changed icon resolution, wrote some tests and added current pos in UI

flabbet 5 years ago
parent
commit
3a717ac6a3

+ 27 - 0
PixiEditor/Helpers/Converters/DoubleToIntConverter.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class DoubleToIntConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value is double || value is float)
+            {
+                double val = (double) value;
+                return (int) val;
+            }
+
+            return value;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 0 - 36
PixiEditor/Models/Position/CoordinatesCalculator.cs

@@ -144,41 +144,5 @@ namespace PixiEditor.Models.Position
             bitmap.Unlock();
             return -1;
         }
-
-        /// <summary>
-        ///     Finds most top-left pixel on each layer.
-        /// </summary>
-        /// <param name="document"></param>
-        /// <returns>Most top-left pixel in each layer</returns>
-        public static Coordinates[] GetSmallestPixels(Document document)
-        {
-            Coordinates[] smallestPixels = new Coordinates[document.Layers.Count];
-            for (int i = 0; i < smallestPixels.Length; i++)
-            {
-                Coordinates point = FindMinEdgeNonTransparentPixel(document.Layers[i].LayerBitmap);
-                if (point.X >= 0 && point.Y >= 0)
-                    smallestPixels[i] = point;
-            }
-
-            return smallestPixels;
-        }
-
-        /// <summary>
-        ///     Finds most bottom-right pixel on each layer.
-        /// </summary>
-        /// <param name="document"></param>
-        /// <returns>Most bottom-right pixel in each layer</returns>
-        public static Coordinates[] GetBiggestPixels(Document document)
-        {
-            Coordinates[] biggestPixels = new Coordinates[document.Layers.Count];
-            for (int i = 0; i < biggestPixels.Length; i++)
-            {
-                Coordinates point = FindMostEdgeNonTransparentPixel(document.Layers[i].LayerBitmap);
-                if (point.X >= 0 && point.Y >= 0)
-                    biggestPixels[i] = point;
-            }
-
-            return biggestPixels;
-        }
     }
 }

+ 1 - 7
PixiEditor/Models/Position/MousePositionConverter.cs

@@ -1,5 +1,6 @@
 using System.Runtime.InteropServices;
 using System.Windows;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 
 namespace PixiEditor.Models.Position
@@ -8,13 +9,6 @@ namespace PixiEditor.Models.Position
     {
         public static Coordinates CurrentCoordinates { get; set; }
 
-        public static Coordinates MousePositionToCoordinates(Layer baseLayer, Point mousePosition)
-        {
-            int xCoord = (int) (mousePosition.X / baseLayer.Width);
-            int yCoord = (int) (mousePosition.Y / baseLayer.Height);
-            return new Coordinates(xCoord, yCoord);
-        }
-
         [DllImport("user32.dll")]
         private static extern bool GetCursorPos(out System.Drawing.Point point);
 

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

@@ -22,7 +22,9 @@ namespace PixiEditor.Models.Tools
         }
 
         public Cursor Cursor { get; set; } = Cursors.Arrow;
+
         public Toolbar Toolbar { get; set; } = new EmptyToolbar();
+
         private bool _isActive;
 
         public virtual void OnMouseDown()

+ 6 - 1
PixiEditor/Models/Tools/ToolSettings/Settings/SizeSetting.cs

@@ -20,12 +20,17 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
         {
             TextBox tb = new TextBox
             {
-                Style = Application.Current.FindResource("DarkTextBoxStyle") as Style,
                 TextAlignment = TextAlignment.Center,
                 MaxLength = 4,
                 Width = 40,
                 Height = 20
             };
+
+            if (Application.Current != null)
+            {
+                tb.Style = (Style)Application.Current.TryFindResource("DarkTextBoxStyle"); ;
+            }
+
             Binding binding = new Binding("Value")
             {
                 Converter = new ToolSizeToIntConverter(),

+ 1 - 1
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -51,7 +51,7 @@ namespace PixiEditor.Models.Tools.Tools
             return layersChanges;
         }
 
-        private BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
+        public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
             float correctionFactor)
         {
             DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);

+ 1 - 0
PixiEditor/PixiEditor.csproj

@@ -13,6 +13,7 @@
     <PackageLicenseFile>LICENSE</PackageLicenseFile>
     <PackageIcon>icon.ico</PackageIcon>
     <ApplicationIcon>..\icon.ico</ApplicationIcon>
+    <Authors>Krzysztof Krysiński</Authors>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

+ 3 - 3
PixiEditor/Properties/AssemblyInfo.cs

@@ -6,7 +6,7 @@ using System.Windows;
 // set of attributes. Change these attribute values to modify the information
 // associated with an assembly.
 [assembly: AssemblyTitle("PixiEditor")]
-[assembly: AssemblyDescription("Lighweighted Pixel Art editor.")]
+[assembly: AssemblyDescription("A lighweighted Pixel Art editor.")]
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("PixiEditor")]
@@ -50,5 +50,5 @@ using System.Windows;
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
 
-[assembly: AssemblyVersion("0.0.4.1")]
-[assembly: AssemblyFileVersion("0.0.4.1")]
+[assembly: AssemblyVersion("0.1.0.0")]
+[assembly: AssemblyFileVersion("0.1.0.0")]

+ 5 - 21
PixiEditor/ViewModels/ViewModelMain.cs

@@ -27,18 +27,12 @@ namespace PixiEditor.ViewModels
     {
         private const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
 
-        private double _mouseXonCanvas;
-
-        private double _mouseYonCanvas;
-
-
         private Color _primaryColor = Colors.Black;
 
         private bool _recenterZoombox;
 
         private Color _secondaryColor = Colors.White;
 
-        private ToolType _selectedTool;
         private Selection _selection;
 
         private Cursor _toolCursor;
@@ -167,6 +161,10 @@ namespace PixiEditor.ViewModels
         public RelayCommand CloseWindowCommand { get; set; }
         public RelayCommand CenterContentCommand { get; set; }
 
+        private double _mouseXonCanvas;
+
+        private double _mouseYonCanvas;
+
         public double MouseXOnCanvas //Mouse X coordinate relative to canvas
         {
             get => _mouseXonCanvas;
@@ -224,20 +222,6 @@ namespace PixiEditor.ViewModels
             }
         }
 
-        public ToolType SelectedTool
-        {
-            get => _selectedTool;
-            set
-            {
-                if (_selectedTool != value)
-                {
-                    _selectedTool = value;
-                    SetActiveTool(value);
-                    RaisePropertyChanged("SelectedTool");
-                }
-            }
-        }
-
         public ObservableCollection<Tool> ToolSet { get; set; }
 
         public LayerChange[] UndoChanges
@@ -611,7 +595,7 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         private void MouseMove(object parameter)
         {
-            Coordinates cords = new Coordinates((int) MouseXOnCanvas, (int) MouseYOnCanvas);
+            Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
             MousePositionConverter.CurrentCoordinates = cords;
 
 

+ 10 - 4
PixiEditor/Views/MainWindow.xaml

@@ -10,7 +10,7 @@
         xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
-        xmlns:cmd="http://www.galasoft.ch/mvvmlight" xmlns:avalondock="https://github.com/Dirkster99/AvalonDock"
+        xmlns:cmd="http://www.galasoft.ch/mvvmlight" xmlns:avalondock="https://github.com/Dirkster99/AvalonDock" xmlns:position="clr-namespace:PixiEditor.Models.Position"
         mc:Ignorable="d" WindowStyle="None"
         Title="PixiEditor" Name="mainWindow" Height="1000" Width="1600" Background="{StaticResource MainColor}"
         WindowStartupLocation="CenterScreen" WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
@@ -22,10 +22,9 @@
     <Window.Resources>
         <vm:ViewModelMain x:Key="ViewModelMain" />
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
-        <helpers:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter" />
-        <converters:BoolToColorConverter x:Key="BoolToColorConverter" />
         <converters:BoolToIntConverter x:Key="BoolToIntConverter" />
         <converters:FloatNormalizeConverter x:Key="FloatNormalizeConverter" />
+        <converters:DoubleToIntConverter x:Key="DoubleToIntConverter"/>
     </Window.Resources>
 
     <Window.CommandBindings>
@@ -366,6 +365,13 @@
                 </avalondock:DockingManager.Theme>
             </avalondock:DockingManager>
         </Grid>
-
+        <DockPanel Grid.Row="3" Grid.Column="1">
+            <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
+                <TextBlock Text="X:" Foreground="White" FontSize="16"/>
+                <TextBlock Margin="4,0,10,0" Text="{Binding MouseXOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
+                <TextBlock Text="Y:" Foreground="White" FontSize="16"/>
+                <TextBlock Margin="4,0,10,0" Text="{Binding MouseYOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
+            </StackPanel>
+        </DockPanel>
     </Grid>
 </Window>

+ 23 - 0
PixiEditorTests/HelpersTests/ConvertersTests/DoubleToIntConverterTest.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using PixiEditor.Helpers.Converters;
+using Xunit;
+
+namespace PixiEditorTests.HelpersTests.ConvertersTests
+{
+    public class DoubleToIntConverterTest
+    {
+        [Fact]
+        public void TestThatConvertConvertsDoubleToInt()
+        {
+            DoubleToIntConverter converter = new DoubleToIntConverter();
+
+            var value = converter.Convert(5.123, typeof(int), null, CultureInfo.CurrentCulture);
+
+            Assert.IsType<int>(value);
+            Assert.Equal(5, (int)value);
+        }
+    }
+}

+ 1 - 1
PixiEditorTests/ModelsTests/ControllersTests/ShortcutControllerTests.cs

@@ -13,7 +13,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
     public class ShortcutControllerTests
     {
 
-        private ShortcutController GenerateStandardShortcutController(Key shortcutKey, ModifierKeys modifiers,RelayCommand shortcutCommand)
+        private static ShortcutController GenerateStandardShortcutController(Key shortcutKey, ModifierKeys modifiers,RelayCommand shortcutCommand)
         {
             ShortcutController controller = new ShortcutController();
             controller.Shortcuts.Add(new Shortcut(shortcutKey, shortcutCommand, 0, modifiers));

+ 1 - 1
PixiEditorTests/ModelsTests/PositionTests/CoordinatesCalculatorTests.cs

@@ -8,7 +8,7 @@ namespace PixiEditorTests.ModelsTests.PositionTests
         [Theory]
         [InlineData(0, 0, 2, 2, 9)]
         [InlineData(0, 0, 10, 10, 121)]
-        public void RectangleToCoordinatesAmountTest(int x1, int y1, int x2, int y2, int expectedResult)
+        public void TestThatRectangleToCoordinatesReturnsSameAmount(int x1, int y1, int x2, int y2, int expectedResult)
         {
             Assert.Equal(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2).Length, expectedResult);
         }

+ 30 - 0
PixiEditorTests/ModelsTests/PositionTests/CoordinatesTests.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using PixiEditor.Models.Position;
+using Xunit;
+
+namespace PixiEditorTests.ModelsTests.PositionTests
+{
+    public class CoordinatesTests
+    {
+
+        [Fact]
+        public void TestThatToStringReturnsCorrectFormat()
+        {
+            Coordinates cords = new Coordinates(5,5);
+
+            Assert.Equal("5, 5",cords.ToString());
+        }
+
+        [Fact]
+        public void TestThatNotEqualOperatorWorks()
+        {
+            Coordinates cords = new Coordinates(5,5);
+            Coordinates cords2 = new Coordinates(6,4);
+
+            Assert.True(cords != cords2);
+        }
+
+    }
+}

+ 47 - 0
PixiEditorTests/ModelsTests/ToolsTests/BrightnessToolTests.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows;
+using System.Windows.Media;
+using PixiEditor;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
+using PixiEditor.Models.Tools.Tools;
+using Xunit;
+
+namespace PixiEditorTests.ModelsTests.ToolsTests
+{
+    public class BrightnessToolTests
+    {
+
+        public BrightnessToolTests()
+        {
+            if (Application.Current == null)
+            {
+                var app = new App();
+
+                app.InitializeComponent();
+            }
+
+        }
+
+        [StaTheory]
+        [InlineData(5, 12, 12, 12)]
+        [InlineData(-5, 242, 242, 242)]
+        // If correction factor is negative, testing color will be white, otherwise black
+        public void TestThatBrightnessToolChangesPixelBrightness(float correctionFactor, byte expectedR, byte expectedG, byte expectedB)
+        {
+            Color expectedColor = Color.FromRgb(expectedR, expectedG, expectedB);
+
+            BrightnessTool tool = new BrightnessTool();
+
+            Layer layer = new Layer("test", 1, 1);
+            layer.SetPixel(new Coordinates(0,0), correctionFactor < 0 ? Colors.White : Colors.Black);
+
+            var changes = tool.ChangeBrightness(layer, new Coordinates(0, 0),1,correctionFactor);
+            layer.SetPixels(changes);
+
+            Assert.Equal(expectedColor,layer.GetPixel(0,0));
+        }
+    }
+}

BIN
icon.ico