Browse Source

Implemented paintables to all shape operations

Krzysztof Krysiński 5 months ago
parent
commit
8098079ef6

+ 14 - 3
src/ChunkyImageLib/Operations/BresenhamLineOperation.cs

@@ -7,6 +7,7 @@ using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Numerics;
 using Drawie.Numerics;
 
 
 namespace ChunkyImageLib.Operations;
 namespace ChunkyImageLib.Operations;
+
 internal class BresenhamLineOperation : IMirroredDrawOperation
 internal class BresenhamLineOperation : IMirroredDrawOperation
 {
 {
     public bool IgnoreEmptyChunks => false;
     public bool IgnoreEmptyChunks => false;
@@ -21,17 +22,24 @@ internal class BresenhamLineOperation : IMirroredDrawOperation
     {
     {
         this.from = from;
         this.from = from;
         this.to = to;
         this.to = to;
-        this.paintable = paintable;
+        this.paintable = paintable.Clone();
+        if (this.paintable is IStartEndPaintable startEndPaintable)
+        {
+            startEndPaintable.Start = from;
+            startEndPaintable.End = to;
+            this.paintable.AbsoluteValues = true;
+        }
+
         this.blendMode = blendMode;
         this.blendMode = blendMode;
-        paint = new Paint() { BlendMode = blendMode };
+        paint = new Paint() { BlendMode = blendMode, Paintable = paintable };
         points = BresenhamLineHelper.GetBresenhamLine(from, to).Select(v => new VecF(v)).ToArray();
         points = BresenhamLineHelper.GetBresenhamLine(from, to).Select(v => new VecF(v)).ToArray();
     }
     }
 
 
     public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     public void DrawOnChunk(Chunk targetChunk, VecI chunkPos)
     {
     {
-        // a hacky way to make the lines look slightly better on non full res chunks
         if (paintable is ColorPaintable colorPaintable)
         if (paintable is ColorPaintable colorPaintable)
         {
         {
+            // a hacky way to make the lines look slightly better on non full res chunks
             paint.Color = new Color(colorPaintable.Color.R, colorPaintable.Color.G, colorPaintable.Color.B,
             paint.Color = new Color(colorPaintable.Color.R, colorPaintable.Color.G, colorPaintable.Color.B,
                 (byte)(colorPaintable.Color.A * targetChunk.Resolution.Multiplier()));
                 (byte)(colorPaintable.Color.A * targetChunk.Resolution.Multiplier()));
         }
         }
@@ -63,16 +71,19 @@ internal class BresenhamLineOperation : IMirroredDrawOperation
             newFrom = (RectI)newFrom.ReflectX((double)verAxisX).Round();
             newFrom = (RectI)newFrom.ReflectX((double)verAxisX).Round();
             newTo = (RectI)newTo.ReflectX((double)verAxisX).Round();
             newTo = (RectI)newTo.ReflectX((double)verAxisX).Round();
         }
         }
+
         if (horAxisY is not null)
         if (horAxisY is not null)
         {
         {
             newFrom = (RectI)newFrom.ReflectY((double)horAxisY).Round();
             newFrom = (RectI)newFrom.ReflectY((double)horAxisY).Round();
             newTo = (RectI)newTo.ReflectY((double)horAxisY).Round();
             newTo = (RectI)newTo.ReflectY((double)horAxisY).Round();
         }
         }
+
         return new BresenhamLineOperation(newFrom.Pos, newTo.Pos, paintable, blendMode);
         return new BresenhamLineOperation(newFrom.Pos, newTo.Pos, paintable, blendMode);
     }
     }
 
 
     public void Dispose()
     public void Dispose()
     {
     {
         paint.Dispose();
         paint.Dispose();
+        this.paintable.Dispose();
     }
     }
 }
 }

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 7d575197477b6803d50e27b0ee0aec7327cc7bd6
+Subproject commit d7395e76746a549d8aa6132aee598fa1b973db9a

+ 1 - 0
src/PixiEditor/Views/Dock/ColorPickerDockView.axaml

@@ -20,6 +20,7 @@
         SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
         SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
         SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
         SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay, Converter={converters:GenericColorToMediaColorConverter}}"
         ColorState="{Binding ColorsSubViewModel.PrimaryColorState, Mode=TwoWay}"
         ColorState="{Binding ColorsSubViewModel.PrimaryColorState, Mode=TwoWay}"
+        EnableGradientsTab="False"
         UseHintColor="False">
         UseHintColor="False">
     </input:SmallColorPicker>
     </input:SmallColorPicker>
 </UserControl>
 </UserControl>

+ 3 - 0
src/PixiEditor/Views/Input/SmallColorPicker.axaml

@@ -16,6 +16,9 @@
             <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
             <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                 <colorPicker:StandardColorPicker ColorState="{Binding Path=ColorState, Mode=TwoWay}"
                 <colorPicker:StandardColorPicker ColorState="{Binding Path=ColorState, Mode=TwoWay}"
                                                  SecondColorState="{Binding  Path=SecondColorState, Mode=TwoWay}"
                                                  SecondColorState="{Binding  Path=SecondColorState, Mode=TwoWay}"
+                                                 EnableGradientsTab="{Binding  Path=EnableGradientsTab}"
+                                                 GradientState="{Binding  Path=GradientState, Mode=TwoWay}"
+                                                 SelectedBrush="{Binding  Path=SelectedBrush, Mode=TwoWay}"
                                                  IsVisible="{Binding  Path=Bounds.Height, Converter={converters:ThresholdVisibilityConverter CheckIfLess=False, Threshold=380}}"
                                                  IsVisible="{Binding  Path=Bounds.Height, Converter={converters:ThresholdVisibilityConverter CheckIfLess=False, Threshold=380}}"
                                                  x:Name="mainColorPicker" />
                                                  x:Name="mainColorPicker" />
                 <Grid
                 <Grid

+ 30 - 1
src/PixiEditor/Views/Input/SmallColorPicker.axaml.cs

@@ -1,12 +1,41 @@
 using Avalonia;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
 using Avalonia.Markup.Xaml;
+using Avalonia.Media;
 using ColorPicker;
 using ColorPicker;
+using ColorPicker.Models;
 
 
 namespace PixiEditor.Views.Input;
 namespace PixiEditor.Views.Input;
 
 
-internal partial class SmallColorPicker : DualPickerControlBase
+internal partial class SmallColorPicker : DualPickerControlBase, IGradientStorage
 {
 {
+    public static readonly StyledProperty<GradientState> GradientStateProperty = AvaloniaProperty.Register<SmallColorPicker, GradientState>(
+        nameof(GradientState));
+
+    public static readonly StyledProperty<bool> EnableGradientsTabProperty = AvaloniaProperty.Register<SmallColorPicker, bool>(
+        nameof(EnableGradientsTab));
+
+    public bool EnableGradientsTab
+    {
+        get => GetValue(EnableGradientsTabProperty);
+        set => SetValue(EnableGradientsTabProperty, value);
+    }
+
+    public GradientState GradientState
+    {
+        get => GetValue(GradientStateProperty);
+        set => SetValue(GradientStateProperty, value);
+    }
+
+    public static readonly StyledProperty<IBrush> SelectedBrushProperty = AvaloniaProperty.Register<SmallColorPicker, IBrush>(
+        nameof(SelectedBrush));
+
+    public IBrush SelectedBrush
+    {
+        get => GetValue(SelectedBrushProperty);
+        set => SetValue(SelectedBrushProperty, value);
+    }
+
     public SmallColorPicker()
     public SmallColorPicker()
     {
     {
         InitializeComponent();
         InitializeComponent();

+ 1 - 0
src/PixiEditor/Views/Input/ToolSettingColorPicker.axaml.cs

@@ -23,6 +23,7 @@ internal partial class ToolSettingColorPicker : UserControl
     public ToolSettingColorPicker()
     public ToolSettingColorPicker()
     {
     {
         InitializeComponent();
         InitializeComponent();
+        ColorPicker.SelectedColor = Colors.White;
         ColorPicker.SecondaryColor = Colors.Black;
         ColorPicker.SecondaryColor = Colors.Black;
         ColorPicker.TemplateApplied += ColorPickerOnTemplateApplied;
         ColorPicker.TemplateApplied += ColorPickerOnTemplateApplied;
     }
     }

+ 2 - 1
src/PixiEditor/Views/Visuals/PixiFilePreviewImage.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia;
 using Avalonia.Threading;
 using Avalonia.Threading;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Surfaces;
 using PixiEditor.Extensions.Exceptions;
 using PixiEditor.Extensions.Exceptions;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 using PixiEditor.Models;
 using PixiEditor.Models;
@@ -135,7 +136,7 @@ internal class PixiFilePreviewImage : TextureControl
 
 
         var newSize = new VecI((int)(surface.Size.X * factor), (int)(surface.Size.Y * factor));
         var newSize = new VecI((int)(surface.Size.X * factor), (int)(surface.Size.Y * factor));
 
 
-        var scaledBitmap = surface.Resize(newSize, ResizeMethod.HighQuality);
+        var scaledBitmap = surface.Resize(newSize, FilterQuality.High);
 
 
         surface.Dispose();
         surface.Dispose();
         return scaledBitmap;
         return scaledBitmap;