Browse Source

Update ColorPicker to 2.0.0, fix a small crash

Equbuxu 4 years ago
parent
commit
146bde0ac2

+ 43 - 43
PixiEditor/Models/Tools/Tool.cs

@@ -1,21 +1,21 @@
-using System.Windows.Input;
-using PixiEditor.Helpers;
+using System.Windows.Input;
+using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
-using PixiEditor.Models.Tools.ToolSettings;
-using PixiEditor.Models.Tools.ToolSettings.Toolbars;
-
-namespace PixiEditor.Models.Tools
-{
-    public abstract class Tool : NotifyableObject
-    {
-        private bool isActive;
-        private string actionDisplay = "";
-
-        public abstract ToolType ToolType { get; }
-
-        public string ImagePath => $"/Images/{ToolType}Image.png";
-
-        public bool HideHighlight { get; set; } = false;
+using PixiEditor.Models.Tools.ToolSettings;
+using PixiEditor.Models.Tools.ToolSettings.Toolbars;
+
+namespace PixiEditor.Models.Tools
+{
+    public abstract class Tool : NotifyableObject
+    {
+        private bool isActive;
+        private string actionDisplay = "";
+
+        public abstract ToolType ToolType { get; }
+
+        public string ImagePath => $"/Images/{ToolType}Image.png";
+
+        public bool HideHighlight { get; set; } = false;
 
         public string Tooltip { get; set; }
 
@@ -28,23 +28,23 @@ namespace PixiEditor.Models.Tools
                 RaisePropertyChanged("ActionDisplay");
             }
         }
-
-        public bool IsActive
-        {
-            get => isActive;
-            set
-            {
-                isActive = value;
-                RaisePropertyChanged("IsActive");
-            }
-        }
-
-        public Cursor Cursor { get; set; } = Cursors.Arrow;
-
-        public Toolbar Toolbar { get; set; } = new EmptyToolbar();
-
-        public bool CanStartOutsideCanvas { get; set; } = false;
-
+
+        public bool IsActive
+        {
+            get => isActive;
+            set
+            {
+                isActive = value;
+                RaisePropertyChanged("IsActive");
+            }
+        }
+
+        public Cursor Cursor { get; set; } = Cursors.Arrow;
+
+        public Toolbar Toolbar { get; set; } = new EmptyToolbar();
+
+        public bool CanStartOutsideCanvas { get; set; } = false;
+
         public virtual void OnMouseDown(MouseEventArgs e)
         {
         }
@@ -52,29 +52,29 @@ namespace PixiEditor.Models.Tools
         public virtual void OnMouseUp(MouseEventArgs e)
         {
         }
-
+
         public virtual void OnKeyDown(KeyEventArgs e)
         {
-        }
-
+        }
+
         public virtual void OnKeyUp(KeyEventArgs e)
         {
-        }
-
+        }
+
         public virtual void OnRecordingLeftMouseDown(MouseEventArgs e)
         {
         }
-
+
         public virtual void OnStoppedRecordingMouseUp(MouseEventArgs e)
         {
         }
-
+
         public virtual void OnMouseMove(MouseEventArgs e)
         {
         }
-
+
         public virtual void AfterAddedUndo(UndoManager undoManager)
         {
         }
-    }
+    }
 }

+ 1 - 1
PixiEditor/PixiEditor.csproj

@@ -52,7 +52,7 @@
     <PackageReference Include="Extended.Wpf.Toolkit" Version="3.8.2" />
     <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
-    <PackageReference Include="PixiEditor.ColorPicker" Version="1.0.1" />
+    <PackageReference Include="PixiEditor.ColorPicker" Version="2.0.0" />
     <PackageReference Include="PixiEditor.Parser" Version="1.0.1.1" />
     <PackageReference Include="WriteableBitmapEx">
       <Version>1.6.7</Version>

+ 1 - 1
PixiEditor/ViewModels/SubViewModels/Main/SelectionViewModel.cs

@@ -33,7 +33,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public bool SelectionIsNotEmpty(object property)
         {
-            var selectedPoints = Owner.BitmapManager.ActiveDocument.ActiveSelection.SelectedPoints;
+            var selectedPoints = Owner.BitmapManager.ActiveDocument?.ActiveSelection.SelectedPoints;
             return selectedPoints != null && selectedPoints.Count > 0;
         }
 

+ 2 - 2
PixiEditor/ViewModels/SubViewModels/Main/UndoViewModel.cs

@@ -78,7 +78,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         /// <returns>True if can undo.</returns>
         private bool CanUndo(object property)
         {
-            return Owner.BitmapManager.ActiveDocument.UndoManager.CanUndo;
+            return Owner.BitmapManager.ActiveDocument?.UndoManager.CanUndo ?? false;
         }
 
         /// <summary>
@@ -88,7 +88,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         /// <returns>True if can redo.</returns>
         private bool CanRedo(object property)
         {
-            return Owner.BitmapManager.ActiveDocument.UndoManager.CanRedo;
+            return Owner.BitmapManager.ActiveDocument?.UndoManager.CanRedo ?? false;
         }
     }
 }

+ 69 - 75
PixiEditor/Views/MainWindow.xaml

@@ -20,11 +20,16 @@
     </WindowChrome.WindowChrome>
 
     <Window.Resources>
-        <vm:ViewModelMain x:Key="ViewModelMain" />
-        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
-        <converters:BoolToIntConverter x:Key="BoolToIntConverter" />
-        <converters:FloatNormalizeConverter x:Key="FloatNormalizeConverter" />
-        <converters:DoubleToIntConverter x:Key="DoubleToIntConverter"/>
+        <ResourceDictionary>
+            <vm:ViewModelMain x:Key="ViewModelMain" />
+            <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
+            <converters:BoolToIntConverter x:Key="BoolToIntConverter" />
+            <converters:FloatNormalizeConverter x:Key="FloatNormalizeConverter" />
+            <converters:DoubleToIntConverter x:Key="DoubleToIntConverter"/>
+            <ResourceDictionary.MergedDictionaries>
+                <ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
+            </ResourceDictionary.MergedDictionaries>
+        </ResourceDictionary>
     </Window.Resources>
 
     <Window.CommandBindings>
@@ -219,26 +224,68 @@
         </StackPanel>
 
         <Grid Grid.Column="2" Background="{StaticResource AccentColor}" Grid.Row="2" Grid.RowSpan="1">
-            <Grid.RowDefinitions>
-                <RowDefinition Height="330" />
-                <RowDefinition Height="250*" />
-                <RowDefinition Height="209*" />
-            </Grid.RowDefinitions>
-            <StackPanel Grid.Row="2" Orientation="Vertical" ZIndex="15">
-            </StackPanel>
-            <avalondock:DockingManager Foreground="White" Background="{StaticResource AccentColor}" BorderThickness="0"
-                                       Grid.Row="0" Grid.RowSpan="3">
+            <avalondock:DockingManager Foreground="White" Background="{StaticResource AccentColor}" BorderThickness="0">
                 <avalondock:LayoutRoot x:Name="LayoutRoot">
                     <avalondock:LayoutPanel Orientation="Vertical">
-                        <LayoutAnchorablePane>
+                        <LayoutAnchorablePane DockHeight="1.3*" DockWidth="*">
                             <LayoutAnchorable ContentId="colorPicker" Title="Color Picker" CanHide="False"
-                                                         CanClose="False" CanAutoHide="False"
-                                                         CanDockAsTabbedDocument="True" CanFloat="True">
-                                <Grid Grid.Row="0">
-                                    <colorpicker:StandardColorPicker Grid.Row="0" SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay}"
-                                 SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay}" />
-                                </Grid>
+                                                             CanClose="False" CanAutoHide="False"
+                                                             CanDockAsTabbedDocument="True" CanFloat="True">
+                                <colorpicker:StandardColorPicker Grid.Row="0" SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay}"
+                                     SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay}" Style="{StaticResource DefaultColorPickerStyle}" />
                             </LayoutAnchorable>
+                            <avalondock:LayoutAnchorable ContentId="swatches" Title="Swatches" CanHide="False"
+                                                         CanClose="False" CanAutoHide="False"
+                                                         CanDockAsTabbedDocument="False" CanFloat="True">
+                                <ScrollViewer HorizontalScrollBarVisibility="Disabled"
+                                              VerticalScrollBarVisibility="Auto">
+                                    <ItemsControl ItemsSource="{Binding BitmapManager.ActiveDocument.Swatches}">
+                                        <ItemsControl.ItemsPanel>
+                                            <ItemsPanelTemplate>
+                                                <WrapPanel Margin="10,0,0,0" Orientation="Horizontal"
+                                                           VerticalAlignment="Top" HorizontalAlignment="Left" />
+                                            </ItemsPanelTemplate>
+                                        </ItemsControl.ItemsPanel>
+                                        <ItemsControl.ItemTemplate>
+                                            <DataTemplate>
+                                                <Grid Width="50" Height="50" Margin="2">
+                                                    <Border Width="48" Height="48">
+                                                        <Border.Background>
+                                                            <ImageBrush ImageSource="../Images/transparentbg.png"
+                                                                        Stretch="UniformToFill">
+                                                                <ImageBrush.RelativeTransform>
+                                                                    <ScaleTransform ScaleX="6" ScaleY="6" CenterX="0.5"
+                                                                                    CenterY="0.5" />
+                                                                </ImageBrush.RelativeTransform>
+                                                            </ImageBrush>
+                                                        </Border.Background>
+                                                    </Border>
+                                                    <Border BorderThickness="0.25" Cursor="Hand" BorderBrush="White">
+                                                        <Border.Background>
+                                                            <SolidColorBrush Color="{Binding}" />
+                                                        </Border.Background>
+                                                    </Border>
+                                                    <i:Interaction.Triggers>
+                                                        <i:EventTrigger EventName="MouseDown">
+                                                            <i:InvokeCommandAction
+                                                                Command="{Binding
+                                                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ColorsSubViewModel.SelectColorCommand}"
+                                                                CommandParameter="{Binding}" />
+                                                        </i:EventTrigger>
+                                                    </i:Interaction.Triggers>
+                                                    <Grid.ContextMenu>
+                                                        <ContextMenu>
+                                                            <MenuItem Header="Remove" Foreground="White"
+                                                                      Command="{Binding ColorsSubViewModel.RemoveSwatchCommand, Source={StaticResource ViewModelMain}}"
+                                                                      CommandParameter="{Binding}" />
+                                                        </ContextMenu>
+                                                    </Grid.ContextMenu>
+                                                </Grid>
+                                            </DataTemplate>
+                                        </ItemsControl.ItemTemplate>
+                                    </ItemsControl>
+                                </ScrollViewer>
+                            </avalondock:LayoutAnchorable>
                         </LayoutAnchorablePane>
                         <avalondock:LayoutAnchorablePane>
                             <avalondock:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False"
@@ -298,60 +345,7 @@
                                 </StackPanel>
                             </avalondock:LayoutAnchorable>
                         </avalondock:LayoutAnchorablePane>
-                        <avalondock:LayoutAnchorablePane>
-                            <avalondock:LayoutAnchorable ContentId="swatches" Title="Swatches" CanHide="False"
-                                                         CanClose="False" CanAutoHide="False"
-                                                         CanDockAsTabbedDocument="False" CanFloat="True">
-                                <ScrollViewer HorizontalScrollBarVisibility="Disabled"
-                                              VerticalScrollBarVisibility="Auto">
-                                    <ItemsControl ItemsSource="{Binding BitmapManager.ActiveDocument.Swatches}">
-                                        <ItemsControl.ItemsPanel>
-                                            <ItemsPanelTemplate>
-                                                <WrapPanel Margin="10,0,0,0" Orientation="Horizontal"
-                                                           VerticalAlignment="Top" HorizontalAlignment="Left" />
-                                            </ItemsPanelTemplate>
-                                        </ItemsControl.ItemsPanel>
-                                        <ItemsControl.ItemTemplate>
-                                            <DataTemplate>
-                                                <Grid Width="50" Height="50" Margin="2">
-                                                    <Border Width="48" Height="48">
-                                                        <Border.Background>
-                                                            <ImageBrush ImageSource="../Images/transparentbg.png"
-                                                                        Stretch="UniformToFill">
-                                                                <ImageBrush.RelativeTransform>
-                                                                    <ScaleTransform ScaleX="6" ScaleY="6" CenterX="0.5"
-                                                                                    CenterY="0.5" />
-                                                                </ImageBrush.RelativeTransform>
-                                                            </ImageBrush>
-                                                        </Border.Background>
-                                                    </Border>
-                                                    <Border BorderThickness="0.25" Cursor="Hand" BorderBrush="White">
-                                                        <Border.Background>
-                                                            <SolidColorBrush Color="{Binding}" />
-                                                        </Border.Background>
-                                                    </Border>
-                                                    <i:Interaction.Triggers>
-                                                        <i:EventTrigger EventName="MouseDown">
-                                                            <i:InvokeCommandAction
-                                                                Command="{Binding
-                                                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ColorsSubViewModel.SelectColorCommand}"
-                                                                CommandParameter="{Binding}" />
-                                                        </i:EventTrigger>
-                                                    </i:Interaction.Triggers>
-                                                    <Grid.ContextMenu>
-                                                        <ContextMenu>
-                                                            <MenuItem Header="Remove" Foreground="White"
-                                                                      Command="{Binding ColorsSubViewModel.RemoveSwatchCommand, Source={StaticResource ViewModelMain}}"
-                                                                      CommandParameter="{Binding}" />
-                                                        </ContextMenu>
-                                                    </Grid.ContextMenu>
-                                                </Grid>
-                                            </DataTemplate>
-                                        </ItemsControl.ItemTemplate>
-                                    </ItemsControl>
-                                </ScrollViewer>
-                            </avalondock:LayoutAnchorable>
-                        </avalondock:LayoutAnchorablePane>
+                        
                     </avalondock:LayoutPanel>
                 </avalondock:LayoutRoot>
                 <avalondock:DockingManager.Theme>