Browse Source

Resize document popup wip

flabbet 5 years ago
parent
commit
7be29877d9

+ 17 - 0
PixiEditor/Models/Dialogs/ResizeDocumentDialog.cs

@@ -0,0 +1,17 @@
+using PixiEditor.Views;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace PixiEditor.Models.Dialogs
+{
+    public class ResizeDocumentDialog : CustomDialog
+    {
+        public override bool ShowDialog()
+        {
+            ResizeDocumentPopup popup = new ResizeDocumentPopup();
+            popup.ShowDialog();
+            return (bool)popup.DialogResult;
+        }
+    }
+}

+ 9 - 0
PixiEditor/ViewModels/ViewModelMain.cs

@@ -50,6 +50,7 @@ namespace PixiEditor.ViewModels
         public RelayCommand PasteCommand { get; set; }
         public RelayCommand PasteCommand { get; set; }
         public RelayCommand ClipCanvasCommand { get; set; }
         public RelayCommand ClipCanvasCommand { get; set; }
         public RelayCommand DeletePixelsCommand { get; set; }
         public RelayCommand DeletePixelsCommand { get; set; }
+        public RelayCommand OpenResizePopupCommand { get; set; }
 
 
 
 
         private double _mouseXonCanvas;
         private double _mouseXonCanvas;
@@ -190,6 +191,7 @@ namespace PixiEditor.ViewModels
             PasteCommand = new RelayCommand(Paste, CanPaste);
             PasteCommand = new RelayCommand(Paste, CanPaste);
             ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
             ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
             DeletePixelsCommand = new RelayCommand(DeletePixels, SelectionIsNotEmpty);
             DeletePixelsCommand = new RelayCommand(DeletePixels, SelectionIsNotEmpty);
+            OpenResizePopupCommand = new RelayCommand(OpenResizePopup, DocumentIsNotNull);
             ToolSet = new ObservableCollection<Tool> {new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
             ToolSet = new ObservableCollection<Tool> {new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
             new CircleTool(), new RectangleTool(), new EarserTool(), new ColorPickerTool(), new BrightnessTool()};
             new CircleTool(), new RectangleTool(), new EarserTool(), new ColorPickerTool(), new BrightnessTool()};
             ShortcutController = new ShortcutController
             ShortcutController = new ShortcutController
@@ -228,6 +230,13 @@ namespace PixiEditor.ViewModels
             Current = this;
             Current = this;
         }
         }
 
 
+        private void OpenResizePopup(object parameter)
+        {
+            ResizeDocumentDialog dialog = new ResizeDocumentDialog();
+            dialog.ShowDialog();
+            Console.WriteLine();
+        }
+
         private void DeletePixels(object parameter)
         private void DeletePixels(object parameter)
         {
         {
             BitmapManager.BitmapOperations.DeletePixels(new Layer[] { BitmapManager.ActiveLayer }, 
             BitmapManager.BitmapOperations.DeletePixels(new Layer[] { BitmapManager.ActiveLayer }, 

+ 2 - 2
PixiEditor/Views/ImportFilePopup.xaml

@@ -15,7 +15,7 @@
         <helpers:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
         <helpers:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
     </Window.Resources>
     </Window.Resources>
     <Border BorderBrush="Black" BorderThickness="1">
     <Border BorderBrush="Black" BorderThickness="1">
-    <Grid Background="#404040">
+    <Grid Background="{StaticResource AccentColor}">
         <Grid.RowDefinitions>
         <Grid.RowDefinitions>
             <RowDefinition Height="4*"/>
             <RowDefinition Height="4*"/>
             <RowDefinition Height="67*"/>
             <RowDefinition Height="67*"/>
@@ -34,7 +34,7 @@
         </Grid>
         </Grid>
         <StackPanel Grid.Row="1" >
         <StackPanel Grid.Row="1" >
             <Label Height="40" Width="120" VerticalAlignment="Top" Content="Import" Foreground="Snow" HorizontalContentAlignment="Center" FontSize="24" Margin="0,10,0,0"/>
             <Label Height="40" Width="120" VerticalAlignment="Top" Content="Import" Foreground="Snow" HorizontalContentAlignment="Center" FontSize="24" Margin="0,10,0,0"/>
-        <StackPanel Background="#2D2D2D" Height="85" Width="200" Margin="0,10,0,0">
+        <StackPanel Background="{StaticResource MainColor}" Height="85" Width="200" Margin="0,10,0,0">
                 <DockPanel Height="20" Margin="0,15,0,0" Width="150">
                 <DockPanel Height="20" Margin="0,15,0,0" Width="150">
                     <TextBlock Width="40" HorizontalAlignment="Left" Text="Width:" Foreground="Snow" FontSize="14"/>
                     <TextBlock Width="40" HorizontalAlignment="Left" Text="Width:" Foreground="Snow" FontSize="14"/>
                     <TextBox Style="{StaticResource DarkTextBoxStyle}" Width="75" Margin="-10,0,0,0" Text="{Binding ImportWidth, Converter={StaticResource ToolSizeToIntConverter}, Mode=TwoWay}">
                     <TextBox Style="{StaticResource DarkTextBoxStyle}" Width="75" Margin="-10,0,0,0" Text="{Binding ImportWidth, Converter={StaticResource ToolSizeToIntConverter}, Mode=TwoWay}">

+ 1 - 0
PixiEditor/Views/MainWindow.xaml

@@ -82,6 +82,7 @@
                     <MenuItem Header="_Deselect" Command="{Binding DeselectCommand}" InputGestureText="Ctrl+D"/>
                     <MenuItem Header="_Deselect" Command="{Binding DeselectCommand}" InputGestureText="Ctrl+D"/>
                 </MenuItem>
                 </MenuItem>
                 <MenuItem Header="_Document">
                 <MenuItem Header="_Document">
+                    <MenuItem Header="Resize document" Command="{Binding OpenResizePopupCommand}"/>
                     <MenuItem Header="Clip canvas" Command="{Binding ClipCanvasCommand}"/>
                     <MenuItem Header="Clip canvas" Command="{Binding ClipCanvasCommand}"/>
                 </MenuItem>
                 </MenuItem>
             </Menu>
             </Menu>

+ 31 - 0
PixiEditor/Views/PopupTemplate.xaml

@@ -0,0 +1,31 @@
+<Window x:Class="PixiEditor.Views.PopupTemplate"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:PixiEditor.Views"
+        mc:Ignorable="d"
+        Title="ResizeDocumentPopup" WindowStartupLocation="CenterScreen" Height="200" Width="400" WindowStyle="None">
+
+    <WindowChrome.WindowChrome>
+        <WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
+    </WindowChrome.WindowChrome>
+
+    <Window.CommandBindings>
+        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Close" />
+    </Window.CommandBindings>
+
+    <Grid Background="{StaticResource AccentColor}">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="35"/>
+            <RowDefinition/>
+        </Grid.RowDefinitions>
+
+        <DockPanel Grid.Row="0" Background="{StaticResource MainColor}">
+            <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
+                            Command="{x:Static SystemCommands.CloseWindowCommand}"/>
+        </DockPanel>
+        <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>
+</Window>

+ 35 - 0
PixiEditor/Views/PopupTemplate.xaml.cs

@@ -0,0 +1,35 @@
+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.Shapes;
+
+namespace PixiEditor.Views
+{
+    /// <summary>
+    /// Interaction logic for PopupTemplate.xaml
+    /// </summary>
+    public partial class PopupTemplate : Window
+    {
+        public PopupTemplate()
+        {
+            InitializeComponent();
+        }
+
+        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            e.CanExecute = true;
+        }
+
+        private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
+        {
+            SystemCommands.CloseWindow(this);
+        }
+    }
+}

+ 58 - 0
PixiEditor/Views/ResizeDocumentPopup.xaml

@@ -0,0 +1,58 @@
+<Window x:Class="PixiEditor.Views.ResizeDocumentPopup"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
+        xmlns:local="clr-namespace:PixiEditor.Views" xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours" xmlns:converters="clr-namespace:PixiEditor.Helpers"
+        mc:Ignorable="d" Name="window"
+        Title="ResizeDocumentPopup"  WindowStartupLocation="CenterScreen" Height="300" Width="400" WindowStyle="None">
+
+    <Window.Resources>
+        <converters:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter"/>
+    </Window.Resources>
+
+    <WindowChrome.WindowChrome>
+        <WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
+    </WindowChrome.WindowChrome>
+
+    <Window.CommandBindings>
+        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Close" />
+    </Window.CommandBindings>
+
+    <Grid Background="{StaticResource AccentColor}">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="35"/>
+            <RowDefinition/>
+        </Grid.RowDefinitions>
+        
+        <DockPanel Grid.Row="0" Background="{StaticResource MainColor}">
+            <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
+                            Command="{x:Static SystemCommands.CloseWindowCommand}"/>
+        </DockPanel>
+        <Label Grid.Row="1" Foreground="White" FontSize="20" 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>
+        </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>
+</Window>

+ 55 - 0
PixiEditor/Views/ResizeDocumentPopup.xaml.cs

@@ -0,0 +1,55 @@
+using System.Windows;
+using System.Windows.Input;
+
+namespace PixiEditor.Views
+{
+    /// <summary>
+    /// Interaction logic for ResizeDocumentPopup.xaml
+    /// </summary>
+    public partial class ResizeDocumentPopup : Window
+    {
+        
+        public ResizeDocumentPopup()
+        {
+            InitializeComponent();
+        }
+
+
+
+        public int NewHeight
+        {
+            get { return (int)GetValue(NewHeightProperty); }
+            set { SetValue(NewHeightProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for NewHeight.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty NewHeightProperty =
+            DependencyProperty.Register("NewHeight", typeof(int), typeof(ResizeDocumentPopup), new PropertyMetadata(0));
+
+
+
+        public int NewWidth
+        {
+            get { return (int)GetValue(NewWidthProperty); }
+            set { SetValue(NewWidthProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for NewWidth.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty NewWidthProperty =
+            DependencyProperty.Register("NewWidth", typeof(int), typeof(ResizeDocumentPopup), new PropertyMetadata(0));
+
+
+
+
+
+        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            e.CanExecute = true;
+        }
+
+        private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
+        {
+            SystemCommands.CloseWindow(this);
+        }
+    }
+}