Browse Source

Added size picker to all popups and fixed clip canvas undo bug

flabbet 5 years ago
parent
commit
c439ae119b

+ 1 - 5
PixiEditor/Models/DataHolders/Document.cs

@@ -70,7 +70,7 @@ namespace PixiEditor.Models.DataHolders
 
         public void Crop(int x, int y, int width, int height)
         {
-            object[] reverseArgs = new object[] { x, y, 0, 0, Width, Height, width, height};
+            object[] reverseArgs = new object[] { x, y, Width, Height, width, height};
             object[] processArgs = new object[] { x, y, 0, 0, width, height };
             ResizeDocumentCanvas(processArgs);
             UndoManager.AddUndoChange(new Change("BitmapManager.ActiveDocument", ReverseCrop, 
@@ -203,10 +203,6 @@ namespace PixiEditor.Models.DataHolders
             int oldHeight = (int)arguments[3];
             int newWidth = (int)arguments[4]; //newWidth is the width after first crop
             int newHeight = (int)arguments[5];
-            if (offsetX < 0) offsetX = 0;
-            if (offsetX + newWidth > oldWidth) newWidth = oldWidth - offsetX;
-            if (offsetY < 0) offsetY = 0;
-            if (offsetY + newHeight > oldHeight) newHeight = oldHeight - offsetY;
 
             ResizeCanvas(offsetX, offsetY, 0, 0, newWidth, newHeight, oldWidth, oldHeight);
         }

+ 2 - 18
PixiEditor/Views/ImportFilePopup.xaml

@@ -35,24 +35,8 @@
         <StackPanel Grid.Row="1" >
             <Label Height="40" Width="120" VerticalAlignment="Top" Content="Open" Foreground="Snow" HorizontalContentAlignment="Center" FontSize="24" Margin="0,10,0,0"/>
                 <Button Grid.Row="1" BorderThickness="1" Foreground="Snow" Height="40" Width="160" Margin="0,30,0,0" Content="File Path" Background="#303030" BorderBrush="{Binding PathButtonBorder}" Command="{Binding ChoosePathCommand}"/>
-                <StackPanel Background="{StaticResource MainColor}" Height="85" Width="200" Margin="0,30,0,0">
-                <DockPanel Height="20" Margin="0,15,0,0" Width="150">
-                    <TextBlock Width="40" HorizontalAlignment="Left" Text="Width:" Foreground="Snow" FontSize="14"/>
-                    <TextBox IsEnabled="{Binding PathIsCorrect}" Style="{StaticResource DarkTextBoxStyle}" Width="75" Margin="-10,0,0,0" Text="{Binding ImportWidth, Converter={StaticResource ToolSizeToIntConverter}, Mode=TwoWay}">
-                        <i:Interaction.Behaviors>
-                                <behaviors:TextBoxFocusBehavior FillSize="True"/>
-                            </i:Interaction.Behaviors>
-                    </TextBox>
-                </DockPanel>
-         
-                    <DockPanel Height="20" Margin="0,15,0,0" Width="150">
-                        <TextBlock Width="45" HorizontalAlignment="Left" Text="Height:" Foreground="Snow" FontSize="14"/>
-                        <TextBox IsEnabled="{Binding PathIsCorrect}" Style="{StaticResource DarkTextBoxStyle}" Width="75" Margin="-15,0,0,0" Text="{Binding ImportHeight, Converter={StaticResource ToolSizeToIntConverter}, Mode=TwoWay}">
-                            <i:Interaction.Behaviors>
-                                <behaviors:TextBoxFocusBehavior FillSize="True"/>
-                            </i:Interaction.Behaviors>
-                        </TextBox>
-                    </DockPanel>
+                <StackPanel Background="{StaticResource MainColor}" Height="120" Width="225" Margin="0,30,0,0">
+                    <local:SizePicker EditingEnabled="{Binding PathIsCorrect}" ChoosenWidth="{Binding ImportWidth, Mode=TwoWay}" ChoosenHeight="{Binding ImportHeight,Mode=TwoWay}"/>
                 </StackPanel>
         </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}}}"/>

+ 2 - 19
PixiEditor/Views/NewFilePopup.xaml

@@ -35,25 +35,8 @@
             </Grid>
             <Label Content="New File" Grid.Row="1" Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="White" FontSize="24"/>
             <StackPanel HorizontalAlignment="Center" Margin="0,60,0,0" Background="{StaticResource MainColor}" VerticalAlignment="Top" Grid.Row="1" Width="350" Height="150">
-                <DockPanel Margin="50,35,0,0">
-                    <TextBlock Height="30" Foreground="Snow" Text="Height:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                    <TextBox Height="30" Width="150" Style="{StaticResource DarkTextBoxStyle}" FontSize="16"
-                             HorizontalAlignment="Left" TextAlignment="Center" 
-                             Margin="5,0,0,0" Text="{Binding ElementName=newFilePopup, Converter={StaticResource ToolSizeToIntConverter}, Path=FileHeight, Mode=TwoWay}" MaxLength="4">
-                        <i:Interaction.Behaviors>
-                            <helpers:TextBoxFocusBehavior FillSize="True"/>
-                        </i:Interaction.Behaviors>
-                    </TextBox>
-                </DockPanel>
-                <DockPanel Margin="50,10,0,0">
-                    <TextBlock Height="30" Foreground="Snow" Text="Width:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                    <TextBox Height="30" Width="150" Style="{StaticResource DarkTextBoxStyle}" FontSize="16" HorizontalAlignment="Left" Margin="10,0,0,0" TextAlignment="Center"
-                             Text="{Binding ElementName=newFilePopup, Converter={StaticResource ToolSizeToIntConverter}, Path=FileWidth, Mode=TwoWay}" MaxLength="4">
-                        <i:Interaction.Behaviors>
-                            <helpers:TextBoxFocusBehavior FillSize="True"/>
-                        </i:Interaction.Behaviors>
-                    </TextBox>
-                </DockPanel>
+                <local:SizePicker Margin="0,20" HorizontalAlignment="Center" Height="110" ChoosenHeight="{Binding FileHeight,Mode=TwoWay, ElementName=newFilePopup}"
+                                  ChoosenWidth="{Binding FileWidth,Mode=TwoWay, ElementName=newFilePopup}"/>
             </StackPanel>
             <Button VerticalAlignment="Bottom" HorizontalAlignment="Right" FontSize="20" Height="30" Width="60" 
                     Style="{StaticResource DarkRoundButton}" Content="OK" Margin="0,0,10,10" Grid.Row="1" 

+ 1 - 10
PixiEditor/Views/ResizeCanvasPopup.xaml

@@ -34,16 +34,7 @@
         </DockPanel>
         <Label Grid.Row="1" VerticalAlignment="Top" Foreground="White" FontSize="24" HorizontalAlignment="Center" Content="Resize Canvas"/>
         <StackPanel HorizontalAlignment="Center" Margin="0,50,0,0" Background="{StaticResource MainColor}" VerticalAlignment="Top" Grid.Row="1" Width="300" Height="250">
-            <DockPanel Margin="50,35,0,0">
-                <TextBlock Height="30" Foreground="Snow" Text="Height:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                <local:SizeInput Margin="5,0,0,0" PreserveAspectRatio="{Binding Path=IsChecked, ElementName=aspectRatio}" AspectRatioValue="{Binding Path=NewWidth, ElementName=window}" HorizontalAlignment="Left" Width="150" Height="30" Size="{Binding NewHeight, ElementName=window, Mode=TwoWay}"/>
-            </DockPanel>
-            <DockPanel Margin="50,10,0,0">
-                <TextBlock Height="30" Foreground="Snow" Text="Width:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                <local:SizeInput Width="150" Height="30" PreserveAspectRatio="{Binding Path=IsChecked, ElementName=aspectRatio}" AspectRatioValue="{Binding Path=NewHeight, ElementName=window}"
-                                 HorizontalAlignment="Left" Margin="10,0,0,0" Size="{Binding Path=NewWidth, ElementName=window, Mode=TwoWay}"/>
-            </DockPanel>
-            <CheckBox Name="aspectRatio" Content="Preserve aspect ratio" Foreground="White" HorizontalAlignment="Left" IsChecked="True" Margin="50,10,0,0"/>
+            <local:SizePicker Margin="0,10,0,0" Width="300" Height="110" ChoosenHeight="{Binding NewHeight, Mode=TwoWay, ElementName=window}" ChoosenWidth="{Binding NewWidth, Mode=TwoWay, ElementName=window}"/>
             <Separator Margin="10,20,10,0" Background="{StaticResource AccentColor}" Height="1"/>
             <Label Content="Anchor point:" Foreground="White" Margin="10,5,0,0" HorizontalAlignment="Left" FontSize="16"/>
             <local:AnchorPointPicker AnchorPoint="{Binding Path=SelectedAnchorPoint, Mode=TwoWay, ElementName=window}" Width="78" Margin="45,-25,0,0" Height="78"/>

+ 2 - 19
PixiEditor/Views/ResizeDocumentPopup.xaml

@@ -32,25 +32,8 @@
         </DockPanel>
         <Label Grid.Row="1" VerticalAlignment="Top" Foreground="White" FontSize="24" HorizontalAlignment="Center" Content="Resize document"/>
         <StackPanel HorizontalAlignment="Center" Margin="0,50,0,0" Background="{StaticResource MainColor}" VerticalAlignment="Top" Grid.Row="1" Width="350" Height="150">
-            <DockPanel Margin="50,35,0,0">
-                <TextBlock Height="30" Foreground="Snow" Text="Height:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                <TextBox Height="30" Width="150" Style="{StaticResource DarkTextBoxStyle}" FontSize="16"
-                             HorizontalAlignment="Left" TextAlignment="Center" 
-                             Margin="5,0,0,0" Text="{Binding ElementName=window, Converter={StaticResource ToolSizeToIntConverter}, Path=NewHeight, Mode=TwoWay}" MaxLength="4">
-                    <i:Interaction.Behaviors>
-                        <behaviors:TextBoxFocusBehavior FillSize="True"/>
-                    </i:Interaction.Behaviors>
-                </TextBox>
-            </DockPanel>
-            <DockPanel Margin="50,10,0,0">
-                <TextBlock Height="30" Foreground="Snow" Text="Width:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                <TextBox Height="30" Width="150" Style="{StaticResource DarkTextBoxStyle}" FontSize="16" HorizontalAlignment="Left" Margin="10,0,0,0" TextAlignment="Center"
-                             Text="{Binding ElementName=window, Converter={StaticResource ToolSizeToIntConverter}, Path=NewWidth, Mode=TwoWay}" MaxLength="4">
-                    <i:Interaction.Behaviors>
-                        <behaviors:TextBoxFocusBehavior FillSize="True"/>
-                    </i:Interaction.Behaviors>
-                </TextBox>
-            </DockPanel>
+            <local:SizePicker Margin="0,20" ChoosenHeight="{Binding Path=NewHeight, Mode=TwoWay, ElementName=window}"
+                              ChoosenWidth="{Binding Path=NewWidth, Mode=TwoWay, ElementName=window}"/>
         </StackPanel>
         <Button Grid.Row="1" Height="30" Width="60" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10" Style="{StaticResource DarkRoundButton}" Content="OK" Click="Button_Click"/>
     </Grid>

+ 9 - 21
PixiEditor/Views/SaveFilePopup.xaml

@@ -13,12 +13,12 @@
         <helpers1:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
     </Window.Resources>
     <Border BorderBrush="Black" BorderThickness="1">
-        <Grid Background="#404040">
+        <Grid Background="{StaticResource AccentColor}">
         <Grid.RowDefinitions>
             <RowDefinition Height="20*"/>
             <RowDefinition Height="229*"/>
         </Grid.RowDefinitions>
-        <Grid Grid.Row="0" Background="#FF2C2C2C">
+        <Grid Grid.Row="0" Background="{StaticResource MainColor}">
             <i:Interaction.Triggers>
                 <i:EventTrigger EventName="MouseDown">
                     <i:InvokeCommandAction Command="{Binding DragMoveCommand}"/>
@@ -31,25 +31,13 @@
                 </Button.Background>
             </Button>
         </Grid>
-        <TextBlock Grid.Row="1" Height="30" Width="120" Foreground="Snow" VerticalAlignment="Top" HorizontalAlignment="Center" Text="File settings" TextAlignment="Center" FontSize="20"/>
-        <DockPanel Grid.Row="1" Height="70" Width="320" Margin="0,10,0,100" Background="#303030">
-            <TextBlock Foreground="Snow" Width="40" Height="40" HorizontalAlignment="Left" Margin="50,0,0,0" Text="Width:" TextAlignment="Center" Padding="0,11.5,0,0"/>
-            <TextBox Style="{StaticResource DarkTextBoxStyle}" Width="70" Height="20" HorizontalAlignment="Left" Margin="5,0,0,0" 
-                     Text="{Binding ElementName=saveFilePopup, Converter={StaticResource ToolSizeToIntConverter}, Path=SaveWidth, Mode=TwoWay}">
-                <i:Interaction.Behaviors>
-                        <helpers:TextBoxFocusBehavior FillSize="True"/>
-                    </i:Interaction.Behaviors>
-            </TextBox>
-            <TextBlock Foreground="Snow" Width="40" Height="40"  HorizontalAlignment="Left" Margin="5,0,0,0" Text="Height:" TextAlignment="Center" Padding="0,11.5,0,0"/>
-            <TextBox Style="{StaticResource DarkTextBoxStyle}" Width="70" Height="20" HorizontalAlignment="Left" 
-                     Margin="5,0,0,0" Text="{Binding ElementName=saveFilePopup, Converter={StaticResource ToolSizeToIntConverter}, Path=SaveHeight,Mode=TwoWay}">
-                <i:Interaction.Behaviors>
-                        <helpers:TextBoxFocusBehavior FillSize="True"/>
-                    </i:Interaction.Behaviors>
-            </TextBox>
-        </DockPanel>
-        <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}}}"/>
+        <TextBlock Grid.Row="1"  Foreground="Snow" VerticalAlignment="Top" HorizontalAlignment="Center" Text="File settings" TextAlignment="Center" Margin="0,10,0,0" FontSize="24"/>
+            <StackPanel Orientation="Vertical" Grid.Row="1" Margin="0,50,0,0">
+            <local:SizePicker  Width="250" Height="120" ChoosenHeight="{Binding Path=SaveHeight, Mode=TwoWay, ElementName=saveFilePopup}"
+                               ChoosenWidth="{Binding Path=SaveWidth, Mode=TwoWay, ElementName=saveFilePopup}"/>
+            <Button Foreground="Snow" Height="40" Width="160" Margin="0,10,0,0" Content="Path" Background="{StaticResource MainColor}" BorderBrush="{Binding PathButtonBorder}" Command="{Binding ChoosePathCommand}"/>
+            </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>

+ 1 - 1
PixiEditor/Views/SizeInput.xaml

@@ -10,7 +10,7 @@
     <UserControl.Resources>
         <converters:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
     </UserControl.Resources>
-    <TextBox HorizontalContentAlignment="Center" Style="{StaticResource DarkTextBoxStyle}" FontSize="16" MaxLength="4">
+    <TextBox IsEnabled="{Binding IsEnabled, ElementName=uc}" HorizontalContentAlignment="Center" Style="{StaticResource DarkTextBoxStyle}" FontSize="16" MaxLength="4">
         <TextBox.Text>
             <Binding ElementName="uc"
                      Path="Size" Mode="TwoWay" 

+ 23 - 0
PixiEditor/Views/SizePicker.xaml

@@ -0,0 +1,23 @@
+<UserControl x:Class="PixiEditor.Views.SizePicker"
+             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"
+             mc:Ignorable="d" 
+             d:DesignHeight="110" d:DesignWidth="215" Name="uc">
+    <StackPanel Background="{StaticResource MainColor}">
+        <DockPanel Margin="5,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <TextBlock Height="30" Foreground="Snow" Text="Height:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+            <local:SizeInput IsEnabled="{Binding EditingEnabled, ElementName=uc}" Margin="5,0,0,0" PreserveAspectRatio="{Binding Path=IsChecked, ElementName=aspectRatio}" AspectRatioValue="{Binding Path=ChoosenWidth, ElementName=uc}" 
+                             HorizontalAlignment="Left" Width="150" Height="30" 
+                             Size="{Binding ChoosenHeight, ElementName=uc, Mode=TwoWay}"/>
+        </DockPanel>
+        <DockPanel Margin="5,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <TextBlock Height="30" Foreground="Snow" Text="Width:" TextAlignment="Center" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+            <local:SizeInput IsEnabled="{Binding EditingEnabled, ElementName=uc}" Width="150" Height="30" PreserveAspectRatio="{Binding Path=IsChecked, ElementName=aspectRatio}" AspectRatioValue="{Binding Path=ChoosenHeight, ElementName=uc}"
+                                 HorizontalAlignment="Left" Margin="10,0,0,0" Size="{Binding Path=ChoosenWidth, ElementName=uc, Mode=TwoWay}"/>
+        </DockPanel>
+        <CheckBox Name="aspectRatio" Content="Preserve aspect ratio" Foreground="White" HorizontalAlignment="Left" IsChecked="True" Margin="50,10,0,0"/>
+    </StackPanel>
+</UserControl>

+ 64 - 0
PixiEditor/Views/SizePicker.xaml.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+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 SizePicker.xaml
+    /// </summary>
+    public partial class SizePicker : UserControl
+    {
+        public SizePicker()
+        {
+            InitializeComponent();
+        }
+
+
+        public bool EditingEnabled
+        {
+            get { return (bool)GetValue(EditingEnabledProperty); }
+            set { SetValue(EditingEnabledProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for EditingEnabled.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty EditingEnabledProperty =
+            DependencyProperty.Register("EditingEnabled", typeof(bool), typeof(SizePicker), new PropertyMetadata(true));
+
+
+
+        public int ChoosenWidth
+        {
+            get { return (int)GetValue(ChoosenWidthProperty); }
+            set { SetValue(ChoosenWidthProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ChoosenWidth.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ChoosenWidthProperty =
+            DependencyProperty.Register("ChoosenWidth", typeof(int), typeof(SizePicker), new PropertyMetadata(1));
+
+
+
+        public int ChoosenHeight
+        {
+            get { return (int)GetValue(ChoosenHeightProperty); }
+            set { SetValue(ChoosenHeightProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ChoosenHeight.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ChoosenHeightProperty =
+            DependencyProperty.Register("ChoosenHeight", typeof(int), typeof(SizePicker), new PropertyMetadata(1));
+
+
+
+    }
+}