2
0
Эх сурвалжийг харах

Added toggle high res preview to preview window

Krzysztof Krysiński 3 сар өмнө
parent
commit
66ec9e2345

+ 2 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -1075,5 +1075,6 @@
   "NEW_MIN": "New Min",
   "NEW_MAX": "New Max",
   "REMAP_NODE": "Remap",
-  "TEXT_TOOL_ACTION_DISPLAY": "Click on the canvas to add a new text (drag while clicking to set the size). Click on existing text to edit it."
+  "TEXT_TOOL_ACTION_DISPLAY": "Click on the canvas to add a new text (drag while clicking to set the size). Click on existing text to edit it.",
+  "PASTE_CELS": "Paste cels"
 }

+ 17 - 2
src/PixiEditor/Views/Main/DocumentPreview.axaml

@@ -7,6 +7,7 @@
              xmlns:input="clr-namespace:PixiEditor.Views.Input"
              xmlns:ui1="clr-namespace:PixiEditor.Helpers.UI"
              xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
+             xmlns:localization="clr-namespace:PixiEditor.UI.Common.Localization;assembly=PixiEditor.UI.Common"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              Name="uc"
              x:Class="PixiEditor.Views.Main.DocumentPreview">
@@ -21,9 +22,11 @@
               IsVisible="{Binding !!Document, ElementName=uc}"
               Margin="10" Background="Transparent"
               d:Width="8" d:Height="8">
+
             <viewportControls:FixedViewport
                 Delayed="True"
                 x:Name="viewport"
+                RenderInDocSize="{Binding ElementName=highDpiButton, Path=IsChecked}"
                 Document="{Binding Document, ElementName=uc}"
                 Background="{Binding ActiveItem.Value, ElementName=backgroundButton}"/>
         </Grid>
@@ -54,8 +57,20 @@
             </TextBlock>
         </StackPanel>
         <Grid Grid.Row="2" HorizontalAlignment="Right" Margin="0,0,5,0" ui:RenderOptionsBindable.BitmapInterpolationMode="{Binding ElementName=backgroundButton, Path=ActiveItem.ScalingMode}">
-            <StackPanel Orientation="Horizontal">
-                <input:ListSwitchButton x:Name="formatButton" Margin="0,0,5,0" Height="20">
+            <StackPanel Spacing="5" Orientation="Horizontal">
+                <StackPanel.Styles>
+                    <Style Selector="ToggleButton#highDpiButton">
+                        <Setter Property="Content" Value="{DynamicResource icon-circle}"/>
+                    </Style>
+                    <Style Selector="ToggleButton#highDpiButton:checked">
+                        <Setter Property="Content" Value="{DynamicResource icon-lowres-circle}"/>
+                        <Setter Property="Background" Value="Transparent"/>
+                        <Setter Property="BorderThickness" Value="0"/>
+                    </Style>
+                </StackPanel.Styles>
+
+                <ToggleButton x:Name="highDpiButton" Classes="pixi-icon" localization:Translator.TooltipKey="TOGGLE_HIGH_RES_PREVIEW"/>
+                <input:ListSwitchButton x:Name="formatButton" Height="20">
                     <input:ListSwitchButton.Items>
                         <input:SwitchItemObservableCollection>
                             <input:SwitchItem Content="RGBA" Background="{DynamicResource ThemeControlMidBrush}" Value="RGBA"/>

+ 1 - 0
src/PixiEditor/Views/Main/ViewportControls/FixedViewport.axaml

@@ -18,6 +18,7 @@
             x:Name="mainImage"
             Focusable="True"
             PreviewPainter="{Binding Document.PreviewPainter, ElementName=uc}"
+            CustomRenderSize="{Binding CustomRenderSize, ElementName=uc}"
             FrameToRender="{Binding Document.AnimationDataViewModel.ActiveFrameBindable, ElementName=uc}"
             SizeChanged="OnImageSizeChanged">
             <ui1:RenderOptionsBindable.BitmapInterpolationMode>

+ 27 - 0
src/PixiEditor/Views/Main/ViewportControls/FixedViewport.axaml.cs

@@ -23,6 +23,24 @@ internal partial class FixedViewport : UserControl, INotifyPropertyChanged
     public static readonly StyledProperty<bool> DelayedProperty =
         AvaloniaProperty.Register<FixedViewport, bool>(nameof(Delayed), false);
 
+    public static readonly StyledProperty<bool> RenderInDocSizeProperty = AvaloniaProperty.Register<FixedViewport, bool>(
+        nameof(RenderInDocSize));
+
+    public static readonly StyledProperty<VecI> CustomRenderSizeProperty = AvaloniaProperty.Register<FixedViewport, VecI>(
+        nameof(CustomRenderSize));
+
+    public VecI CustomRenderSize
+    {
+        get => GetValue(CustomRenderSizeProperty);
+        set => SetValue(CustomRenderSizeProperty, value);
+    }
+
+    public bool RenderInDocSize
+    {
+        get => GetValue(RenderInDocSizeProperty);
+        set => SetValue(RenderInDocSizeProperty, value);
+    }
+
     public event PropertyChangedEventHandler? PropertyChanged;
 
     public bool Delayed
@@ -42,6 +60,7 @@ internal partial class FixedViewport : UserControl, INotifyPropertyChanged
     static FixedViewport()
     {
         DocumentProperty.Changed.Subscribe(OnDocumentChange);
+        RenderInDocSizeProperty.Changed.Subscribe(OnRenderInDocSizeChanged);
     }
 
     public FixedViewport()
@@ -132,6 +151,14 @@ internal partial class FixedViewport : UserControl, INotifyPropertyChanged
         viewport.ForceRefreshFinalImage();
     }
 
+    private static void OnRenderInDocSizeChanged(AvaloniaPropertyChangedEventArgs<bool> args)
+    {
+        FixedViewport? viewport = (FixedViewport)args.Sender;
+        viewport.CustomRenderSize = args.NewValue.Value ? viewport.Document?.SizeBindable ?? VecI.Zero : VecI.Zero;
+        viewport.InvalidateMeasure();
+        viewport.ForceRefreshFinalImage();
+    }
+
     private void DocSizeChanged(object? sender, DocumentSizeChangedEventArgs e)
     {
         Document?.Operations.AddOrUpdateViewport(GetLocation());

+ 47 - 11
src/PixiEditor/Views/Visuals/PreviewPainterControl.cs

@@ -17,6 +17,15 @@ public class PreviewPainterControl : DrawieControl
         AvaloniaProperty.Register<PreviewPainterControl, PreviewPainter>(
             nameof(PreviewPainter));
 
+    public static readonly StyledProperty<VecI> CustomRenderSizeProperty = AvaloniaProperty.Register<PreviewPainterControl, VecI>(
+        nameof(CustomRenderSize));
+
+    public VecI CustomRenderSize
+    {
+        get => GetValue(CustomRenderSizeProperty);
+        set => SetValue(CustomRenderSizeProperty, value);
+    }
+
     public PreviewPainter PreviewPainter
     {
         get => GetValue(PreviewPainterProperty);
@@ -35,6 +44,7 @@ public class PreviewPainterControl : DrawieControl
     {
         PreviewPainterProperty.Changed.Subscribe(PainterChanged);
         BoundsProperty.Changed.Subscribe(UpdatePainterBounds);
+        CustomRenderSizeProperty.Changed.Subscribe(UpdatePainterBounds);
     }
 
     public PreviewPainterControl()
@@ -64,10 +74,10 @@ public class PreviewPainterControl : DrawieControl
         if (args.NewValue.Value != null)
         {
             sender.painterInstance = args.NewValue.Value.AttachPainterInstance();
-            if (sender.Bounds is { Width: > 0, Height: > 0 })
+            VecI finalSize = sender.GetFinalSize();
+            if (finalSize is { X: > 0, Y: > 0 })
             {
-                sender.PreviewPainter.ChangeRenderTextureSize(sender.painterInstance.RequestId,
-                    new VecI((int)sender.Bounds.Width, (int)sender.Bounds.Height));
+                sender.PreviewPainter.ChangeRenderTextureSize(sender.painterInstance.RequestId, finalSize);
             }
 
             sender.painterInstance.RequestMatrix = sender.OnPainterRequestMatrix;
@@ -93,23 +103,49 @@ public class PreviewPainterControl : DrawieControl
             return;
         }
 
+        if (CustomRenderSize.ShortestAxis > 0)
+        {
+            surface.Canvas.Save();
+            VecI finalSize = GetFinalSize();
+            surface.Canvas.Scale(
+                (float)Bounds.Width / finalSize.X,
+                (float)Bounds.Height / finalSize.Y);
+        }
+
         PreviewPainter.Paint(surface, painterInstance.RequestId);
+
+        if (CustomRenderSize.ShortestAxis > 0)
+        {
+            surface.Canvas.Restore();
+        }
     }
 
     private Matrix3X3 UniformScale(float x, float y, RectD previewBounds)
     {
-        float scaleX = (float)Bounds.Width / x;
-        float scaleY = (float)Bounds.Height / y;
+        VecI finalSize = GetFinalSize();
+        float scaleX = finalSize.X / x;
+        float scaleY = finalSize.Y / y;
         var scale = Math.Min(scaleX, scaleY);
-        float dX = (float)Bounds.Width / 2 / scale - x / 2;
+        float dX = (float)finalSize.X / 2 / scale - x / 2;
         dX -= (float)previewBounds.X;
-        float dY = (float)Bounds.Height / 2 / scale - y / 2;
+        float dY = (float)finalSize.Y / 2 / scale - y / 2;
         dY -= (float)previewBounds.Y;
         Matrix3X3 matrix = Matrix3X3.CreateScale(scale, scale);
         return matrix.Concat(Matrix3X3.CreateTranslation(dX, dY));
     }
 
-    private static void UpdatePainterBounds(AvaloniaPropertyChangedEventArgs<Rect> args)
+    private VecI GetFinalSize()
+    {
+        VecI finalSize = CustomRenderSize.ShortestAxis > 0 ? CustomRenderSize : new VecI((int)Bounds.Width, (int)Bounds.Height);
+        if(Bounds.Width < finalSize.X && Bounds.Height < finalSize.Y)
+        {
+            finalSize = new VecI((int)Bounds.Width, (int)Bounds.Height);
+        }
+
+        return finalSize;
+    }
+
+    private static void UpdatePainterBounds(AvaloniaPropertyChangedEventArgs args)
     {
         var sender = args.Sender as PreviewPainterControl;
 
@@ -120,10 +156,10 @@ public class PreviewPainterControl : DrawieControl
 
         if (sender.painterInstance != null)
         {
-            if (args.NewValue.Value is { Width: > 0, Height: > 0 })
+            VecI finalSize = sender.GetFinalSize();
+            if (finalSize is { X: > 0, Y: > 0 })
             {
-                sender.PreviewPainter.ChangeRenderTextureSize(sender.painterInstance.RequestId,
-                    new VecI((int)args.NewValue.Value.Width, (int)args.NewValue.Value.Height));
+                sender.PreviewPainter.ChangeRenderTextureSize(sender.painterInstance.RequestId, finalSize);
                 sender.PreviewPainter.RepaintFor(sender.painterInstance.RequestId);
             }
         }