Browse Source

Merge remote-tracking branch 'origin/master' into quickfill

flabbet 3 years ago
parent
commit
ccf404c27a

+ 25 - 0
PixiEditor/App.xaml.cs

@@ -0,0 +1,25 @@
+using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.Enums;
+using PixiEditor.ViewModels;
+using System.Linq;
+using System.Windows;
+
+namespace PixiEditor
+{
+    /// <summary>
+    ///     Interaction logic for App.xaml.
+    /// </summary>
+    public partial class App : Application
+    {
+        protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
+        {
+            base.OnSessionEnding(e);
+
+            if (ViewModelMain.Current.BitmapManager.Documents.Any(x => !x.ChangesSaved))
+            {
+                ConfirmationType confirmation = ConfirmationDialog.Show($"{e.ReasonSessionEnding} with unsaved data. Are you sure?", $"{e.ReasonSessionEnding}");
+                e.Cancel = confirmation != ConfirmationType.Yes;
+            }
+        }
+    }
+}

+ 142 - 142
PixiEditor/Helpers/Extensions/ParserHelpers.cs

@@ -1,158 +1,158 @@
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.Layers;
-using PixiEditor.Parser;
-using PixiEditor.Parser.Skia;
-using SkiaSharp;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-
-namespace PixiEditor.Helpers.Extensions
-{
-    public static class ParserHelpers
-    {
-        public static Document ToDocument(this SerializableDocument serializableDocument)
-        {
-            Document document = new Document(serializableDocument.Width, serializableDocument.Height)
-            {
-                Layers = serializableDocument.ToLayers(),
-                Swatches = new ObservableCollection<SKColor>(serializableDocument.Swatches.ToSKColors())
-            };
-
-            document.LayerStructure.Groups = serializableDocument.ToGroups(document);
-
-            if (document.Layers.Count > 0)
-            {
-                document.SetMainActiveLayer(0);
-            }
-
-            return document;
-        }
-
-        public static ObservableCollection<Layer> ToLayers(this SerializableDocument document)
-        {
-            ObservableCollection<Layer> layers = new();
-
-            foreach (SerializableLayer slayer in document)
-            {
-                layers.Add(slayer.ToLayer());
-            }
-
-            return layers;
-        }
-
-        public static Layer ToLayer(this SerializableLayer layer)
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
+using PixiEditor.Parser;

+using PixiEditor.Parser.Skia;

+using SkiaSharp;

+using System;

+using System.Collections.Generic;

+using System.Collections.ObjectModel;
+

+namespace PixiEditor.Helpers.Extensions
+{
+    public static class ParserHelpers
+    {
+        public static Document ToDocument(this SerializableDocument serializableDocument)
         {
-            return new Layer(layer.Name, new Surface(layer.ToSKImage()))
+            Document document = new Document(serializableDocument.Width, serializableDocument.Height)
             {
-                Opacity = layer.Opacity,
-                IsVisible = layer.IsVisible,
-                Offset = new(layer.OffsetX, layer.OffsetY, 0, 0)
+                Layers = serializableDocument.ToLayers(),
+                Swatches = new ObservableCollection<SKColor>(serializableDocument.Swatches.ToSKColors())
             };
-        }
-
-        public static ObservableCollection<GuidStructureItem> ToGroups(this SerializableDocument sdocument, Document document)
-        {
-            ObservableCollection<GuidStructureItem> groups = new();
 
-            if (sdocument.Groups == null)
-            {
-                return groups;
-            }
+            document.LayerStructure.Groups = serializableDocument.ToGroups(document);
 
-            foreach (SerializableGroup sgroup in sdocument.Groups)
+            if (document.Layers.Count > 0)
             {
-                groups.Add(sgroup.ToGroup(null, document));
+                document.SetMainActiveLayer(0);
             }
 
-            return groups;
-        }
-
-        public static GuidStructureItem ToGroup(this SerializableGroup sgroup, GuidStructureItem parent, Document document)
-        {
-            GuidStructureItem group = new GuidStructureItem(sgroup.Name, Guid.Empty)
-            {
-                Opacity = sgroup.Opacity,
-                IsVisible = sgroup.IsVisible,
-                Parent = parent,
-                StartLayerGuid = document.Layers[sgroup.StartLayer].LayerGuid,
-                EndLayerGuid = document.Layers[sgroup.EndLayer].LayerGuid
-            };
+            return document;
+        }
 
-            group.Subgroups = new(sgroup.Subgroups.ToGroups(document, group));
+        public static ObservableCollection<Layer> ToLayers(this SerializableDocument document)

+        {

+            ObservableCollection<Layer> layers = new();

+

+            foreach (SerializableLayer slayer in document)

+            {

+                layers.Add(slayer.ToLayer());

+            }

+

+            return layers;

+        }
 
-            return group;
+        public static Layer ToLayer(this SerializableLayer layer)

+        {

+            return new Layer(layer.Name, new Surface(layer.ToSKImage()))

+            {

+                Opacity = layer.Opacity,

+                IsVisible = layer.IsVisible,

+                Offset = new(layer.OffsetX, layer.OffsetY, 0, 0)

+            };

         }
-
-        public static SerializableDocument ToSerializable(this Document document)
-        {
-            return new SerializableDocument(document.Width, document.Height,
-                                            document.LayerStructure.Groups.ToSerializable(document),
-                                            document.Layers.ToSerializable()).AddSwatches(document.Swatches);
-        }
-
-        public static IEnumerable<SerializableLayer> ToSerializable(this IEnumerable<Layer> layers)
-        {
-            foreach (Layer layer in layers)
-            {
-                yield return layer.ToSerializable();
-            }
-        }
-
-        public static SerializableLayer ToSerializable(this Layer layer)
-        {
-            return new SerializableLayer(layer.Width, layer.Height, layer.OffsetX, layer.OffsetY)
-            {
-                IsVisible = layer.IsVisible,
-                Opacity = layer.Opacity,
-                Name = layer.Name
-            }.FromSKImage(layer.LayerBitmap.SkiaSurface.Snapshot());
-        }
-
-        public static IEnumerable<SerializableGroup> ToSerializable(this IEnumerable<GuidStructureItem> groups, Document document)
-        {
-            foreach (GuidStructureItem group in groups)
-            {
-                yield return group.ToSerializable(document);
-            }
-        }
-
-        public static SerializableGroup ToSerializable(this GuidStructureItem group, Document document)
-        {
-            SerializableGroup serializable = new SerializableGroup(group.Name, group.Subgroups.ToSerializable(document))
-            {
-                Opacity = group.Opacity,
-                IsVisible = group.IsVisible
-            };
 
-            for (int i = 0; i < document.Layers.Count; i++)
-            {
-                if (group.StartLayerGuid == document.Layers[i].LayerGuid)
-                {
-                    serializable.StartLayer = i;
-                }
+        public static ObservableCollection<GuidStructureItem> ToGroups(this SerializableDocument sdocument, Document document)

+        {

+            ObservableCollection<GuidStructureItem> groups = new();

+

+            if (sdocument.Groups == null)

+            {

+                return groups;

+            }

+

+            foreach (SerializableGroup sgroup in sdocument.Groups)

+            {

+                groups.Add(sgroup.ToGroup(null, document));

+            }

+

+            return groups;

+        }
 
-                if (group.EndLayerGuid == document.Layers[i].LayerGuid)
-                {
-                    serializable.EndLayer = i;
-                }
-            }
+        public static GuidStructureItem ToGroup(this SerializableGroup sgroup, GuidStructureItem parent, Document document)

+        {

+            GuidStructureItem group = new GuidStructureItem(sgroup.Name, Guid.Empty)

+            {

+                Opacity = sgroup.Opacity,

+                IsVisible = sgroup.IsVisible,

+                Parent = parent,

+                StartLayerGuid = document.Layers[sgroup.StartLayer].LayerGuid,

+                EndLayerGuid = document.Layers[sgroup.EndLayer].LayerGuid

+            };

+

+            group.Subgroups = new(sgroup.Subgroups.ToGroups(document, group));

+

+            return group;

+        }

 
-            return serializable;
+        public static SerializableDocument ToSerializable(this Document document)

+        {

+            return new SerializableDocument(document.Width, document.Height,

+                                            document.LayerStructure.Groups.ToSerializable(document),

+                                            document.Layers.ToSerializable()).AddSwatches(document.Swatches);

         }
 
-        private static IEnumerable<GuidStructureItem> ToGroups(this IEnumerable<SerializableGroup> groups, Document document, GuidStructureItem parent)
-        {
-            foreach (SerializableGroup sgroup in groups)
-            {
-                yield return sgroup.ToGroup(parent, document);
-            }
-        }
-
-        private static SerializableDocument AddSwatches(this SerializableDocument document, IEnumerable<SKColor> colors)
-        {
-            document.Swatches.AddRange(colors);
-            return document;
-        }
-    }
-}
+        public static IEnumerable<SerializableLayer> ToSerializable(this IEnumerable<Layer> layers)

+        {

+            foreach (Layer layer in layers)

+            {

+                yield return layer.ToSerializable();

+            }

+        }
+
+        public static SerializableLayer ToSerializable(this Layer layer)

+        {

+            return new SerializableLayer(layer.Width, layer.Height, layer.OffsetX, layer.OffsetY)

+            {

+                IsVisible = layer.IsVisible,

+                Opacity = layer.Opacity,

+                Name = layer.Name

+            }.FromSKImage(layer.LayerBitmap.SkiaSurface.Snapshot());

+        }
+
+        public static IEnumerable<SerializableGroup> ToSerializable(this IEnumerable<GuidStructureItem> groups, Document document)

+        {

+            foreach (GuidStructureItem group in groups)

+            {

+                yield return group.ToSerializable(document);

+            }

+        }
+
+        public static SerializableGroup ToSerializable(this GuidStructureItem group, Document document)

+        {

+            SerializableGroup serializable = new SerializableGroup(group.Name, group.Subgroups.ToSerializable(document))

+            {

+                Opacity = group.Opacity,

+                IsVisible = group.IsVisible

+            };

+

+            for (int i = 0; i < document.Layers.Count; i++)

+            {

+                if (group.StartLayerGuid == document.Layers[i].LayerGuid)

+                {

+                    serializable.StartLayer = i;

+                }

+

+                if (group.EndLayerGuid == document.Layers[i].LayerGuid)

+                {

+                    serializable.EndLayer = i;

+                }

+            }

+

+            return serializable;

+        }

+

+        private static IEnumerable<GuidStructureItem> ToGroups(this IEnumerable<SerializableGroup> groups, Document document, GuidStructureItem parent)

+        {

+            foreach (SerializableGroup sgroup in groups)

+            {

+                yield return sgroup.ToGroup(parent, document);

+            }

+        }
+
+        private static SerializableDocument AddSwatches(this SerializableDocument document, IEnumerable<SKColor> colors)

+        {

+            document.Swatches.AddRange(colors);

+            return document;

+        }
+    }
+}

BIN
PixiEditor/Images/Placeholder.png


BIN
PixiEditor/Images/SocialMedia/DiscordIcon.png


BIN
PixiEditor/Images/SocialMedia/DonateIcon.png


BIN
PixiEditor/Images/SocialMedia/GitHubIcon.png


BIN
PixiEditor/Images/SocialMedia/RedditIcon.png


BIN
PixiEditor/Images/SocialMedia/WebsiteIcon.png


BIN
PixiEditor/Images/SocialMedia/YouTubeIcon.png


+ 20 - 2
PixiEditor/Models/Dialogs/ConfirmationDialog.cs

@@ -1,10 +1,12 @@
 using PixiEditor.Models.Enums;
 using PixiEditor.Views;
-
+using System;
+
 namespace PixiEditor.Models.Dialogs
 {
     public static class ConfirmationDialog
     {
+        [Obsolete(message: "Use Show(message, title) instead.")]
         public static ConfirmationType Show(string message)
         {
             ConfirmationPopup popup = new ConfirmationPopup
@@ -12,7 +14,23 @@ namespace PixiEditor.Models.Dialogs
                 Body = message,
                 Topmost = true
             };
-            if ((bool)popup.ShowDialog())
+            if (popup.ShowDialog().GetValueOrDefault())
+            {
+                return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
+            }
+
+            return ConfirmationType.Canceled;
+        }
+
+        public static ConfirmationType Show(string message, string title)
+        {
+            ConfirmationPopup popup = new ConfirmationPopup
+            {
+                Title = title,
+                Body = message,
+                ShowInTaskbar = false
+            };
+            if (popup.ShowDialog().GetValueOrDefault())
             {
                 return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
             }

+ 15 - 1
PixiEditor/PixiEditor.csproj

@@ -128,7 +128,14 @@
     <None Remove="Images\PixiBotLogo.png" />
     <None Remove="Images\PixiEditorLogo.png" />
     <None Remove="Images\PixiParserLogo.png" />
+    <None Remove="Images\Placeholder.png" />
     <None Remove="Images\SelectImage.png" />
+    <None Remove="Images\SocialMedia\DiscordIcon.png" />
+    <None Remove="Images\SocialMedia\DonateIcon.png" />
+    <None Remove="Images\SocialMedia\GitHubIcon.png" />
+    <None Remove="Images\SocialMedia\RedditIcon.png" />
+    <None Remove="Images\SocialMedia\WebsiteIcon.png" />
+    <None Remove="Images\SocialMedia\YouTubeIcon.png" />
     <None Remove="Images\Tools\BrightnessImage.png" />
     <None Remove="Images\Tools\CircleImage.png" />
     <None Remove="Images\Tools\ColorPickerImage.png" />
@@ -168,7 +175,7 @@
     </PackageReference>
     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
     <PackageReference Include="PixiEditor.ColorPicker" Version="3.1.0" />
-    <PackageReference Include="PixiEditor.Parser" Version="2.0.0" />
+    <PackageReference Include="PixiEditor.Parser" Version="1.2.0.1" />
     <PackageReference Include="PixiEditor.Parser.Skia" Version="2.0.0" />
     <PackageReference Include="SkiaSharp" Version="2.80.3" />
     <PackageReference Include="System.Drawing.Common" Version="5.0.2" />
@@ -190,6 +197,13 @@
     <Resource Include="Images\PixiBotLogo.png" />
     <Resource Include="Images\PixiEditorLogo.png" />
     <Resource Include="Images\PixiParserLogo.png" />
+    <Resource Include="Images\Placeholder.png" />
+    <Resource Include="Images\SocialMedia\DiscordIcon.png" />
+    <Resource Include="Images\SocialMedia\DonateIcon.png" />
+    <Resource Include="Images\SocialMedia\GitHubIcon.png" />
+    <Resource Include="Images\SocialMedia\RedditIcon.png" />
+    <Resource Include="Images\SocialMedia\WebsiteIcon.png" />
+    <Resource Include="Images\SocialMedia\YouTubeIcon.png" />
     <Resource Include="Images\Tools\BrightnessImage.png" />
     <Resource Include="Images\Tools\CircleImage.png" />
     <Resource Include="Images\Tools\ColorPickerImage.png" />

+ 4 - 1
PixiEditor/ViewModels/SubViewModels/Main/ViewportViewModel.cs

@@ -35,7 +35,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         private void ZoomViewport(object parameter)
         {
             double zoom = (int)parameter;
-            Owner.BitmapManager.ActiveDocument.ZoomViewportTrigger.Execute(this, zoom);
+            if (Owner.BitmapManager.ActiveDocument is not null)
+            {
+                Owner.BitmapManager.ActiveDocument.ZoomViewportTrigger.Execute(this, zoom);
+            }
         }
     }
 }

+ 39 - 58
PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -17,10 +17,34 @@
         </Style>
 
         <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}" x:Key="SocialMediaButton">
-            <Setter Property="Width" Value="150"/>
+            <Setter Property="Width" Value="50"/>
             <Setter Property="Margin" Value="5,8,5,0"/>
             <Setter Property="FontSize" Value="18"/>
-            <Setter Property="Height" Value="28"/>
+            <Setter Property="Height" Value="50"/>
+            <Setter Property="Cursor" Value="Hand"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="Button">
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="IsMouseOver" Value="True">
+                                <Setter Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}}"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                        <Border
+                            x:Name="Border"
+                            Background="{TemplateBinding Background}"
+                            Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
+                            BorderThickness="{TemplateBinding BorderThickness}"
+                            BorderBrush="{TemplateBinding BorderBrush}"
+                            CornerRadius="5">
+                            <ContentControl>
+                                <Image Margin="8" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"
+                                       RenderOptions.BitmapScalingMode="Fant"/>
+                            </ContentControl>
+                        </Border>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
         </Style>
     </Window.Resources>
 
@@ -217,67 +241,24 @@
                 </StackPanel>
 
                 <uc:AlignableWrapPanel Grid.Row="3" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Margin="0,5,0,15">
+                    <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://pixieditor.net"
+                            Style="{StaticResource SocialMediaButton}" Tag="#e3002d" ToolTip="Website"
+                            Content="../../Images/SocialMedia/WebsiteIcon.png"/>
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://discord.gg/tzkQFDkqQS"
-                            Content="Discord">
-                        <Button.Style>
-                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
-                                <Style.Triggers>
-                                    <Trigger Property="IsMouseOver" Value="True">
-                                        <Setter Property="Background" Value="#7289DA"/>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </Button.Style>
-                    </Button>
+                            Style="{StaticResource SocialMediaButton}" Tag="#7289DA" ToolTip="Discord"
+                            Content="../../Images/SocialMedia/DiscordIcon.png"/>
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://reddit.com/r/PixiEditor"
-                            Content="r/PixiEditor">
-                        <Button.Style>
-                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
-                                <Style.Triggers>
-                                    <Trigger Property="IsMouseOver" Value="True">
-                                        <Setter Property="Background" Value="#FF4500"/>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </Button.Style>
-                    </Button>
+                            Style="{StaticResource SocialMediaButton}" Tag="#FF4500" ToolTip="Reddit"
+                            Content="../../Images/SocialMedia/RedditIcon.png"/>
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://github.com/PixiEditor/PixiEditor"
-                            Content="GitHub">
-                        <Button.Style>
-                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
-                                <Style.Triggers>
-                                    <Trigger Property="IsMouseOver" Value="True">
-                                        <Setter Property="Background" Value="White"/>
-                                        <Setter Property="Foreground" Value="Black"/>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </Button.Style>
-                    </Button>
+                            Style="{StaticResource SocialMediaButton}" Tag="Black" ToolTip="GitHub"
+                            Content="../../Images/SocialMedia/GithubIcon.png"/>
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://www.youtube.com/channel/UCT5XvyvX1q5PAIaXfWmpsMQ"
-                            Content="YouTube">
-                        <Button.Style>
-                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
-                                <Style.Triggers>
-                                    <Trigger Property="IsMouseOver" Value="True">
-                                        <Setter Property="Background" Value="#FF0000"/>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </Button.Style>
-                    </Button>
+                            Style="{StaticResource SocialMediaButton}" Tag="#FF0000" ToolTip="YouTube"
+                            Content="../../Images/SocialMedia/YouTubeIcon.png"/>
                     <Button Command="{Binding OpenHyperlinkCommand}" CommandParameter="https://opencollective.com/pixieditor"
-                            Content="Donate" ToolTip="And subscribe to PixiEditor's OnlyFans please">
-                        <Button.Style>
-                            <Style TargetType="Button" BasedOn="{StaticResource SocialMediaButton}">
-                                <Style.Triggers>
-                                    <Trigger Property="IsMouseOver" Value="True">
-                                        <Setter Property="Background" Value="#DB61A2"/>
-                                    </Trigger>
-                                </Style.Triggers>
-                            </Style>
-                        </Button.Style>
-                    </Button>
+                            Style="{StaticResource SocialMediaButton}" Tag="#d4af37" ToolTip="Donate"
+                            Content="../../Images/SocialMedia/DonateIcon.png"/>
                 </uc:AlignableWrapPanel>
             </Grid>
         </ScrollViewer>

+ 8 - 3
PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -60,13 +60,18 @@ namespace PixiEditor.Views.Dialogs
 
             if (RecentlyOpenedEmpty)
             {
+                Width = 400;
+                Height = 500;
+            }
+            else if (RecentlyOpened.Count < 4)
+            {
+                Width = 445;
                 Height = 500;
-                Width = 520;
             }
             else if (RecentlyOpened.Count < 7)
             {
-                Height = 676;
-                Width = 545;
+                Width = 475;
+                Height = 670;
             }
         }
 

+ 4 - 2
PixiEditor/Views/MainWindow.xaml

@@ -145,7 +145,9 @@
                 </MenuItem>
                 <MenuItem Header="_Help">
                     <MenuItem Header="_Documentation" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
-                              CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki"/>
+                              CommandParameter="https://pixieditor.net/docs/introduction"/>
+                    <MenuItem Header="_Website" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
+                              CommandParameter="https://pixieditor.net"/>
                     <MenuItem Header="_Repository" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor"/>
                     <MenuItem Header="_Shortcuts" Command="{Binding MiscSubViewModel.OpenShortcutWindowCommand}"/>
@@ -153,7 +155,7 @@
                     <MenuItem Header="_License" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/blob/master/LICENSE"/>
                     <MenuItem Header="_Third Party Licenses" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
-                              CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Third-party-licenses"/>
+                              CommandParameter="https://pixieditor.net/docs/Third-party-licenses"/>
                 </MenuItem>
                 <MenuItem Header="_Debug" Visibility="{Binding IsDebug, Converter={StaticResource BoolToVisibilityConverter}}">
                     <MenuItem Header="_Open Local App Data" Command="{Binding DebugSubViewModel.OpenFolderCommand}"