Browse Source

Fixed checker background and some zoombox calculations

Krzysztof Krysiński 2 years ago
parent
commit
72481629c3

+ 5 - 4
src/PixiEditor.AvaloniaUI/Helpers/Converters/ZoomToViewportConverter.cs

@@ -11,10 +11,11 @@ internal class ZoomToViewportConverter
     {
         if (value is double scale && parameter is double factor)
         {
-            double newSize = Math.Clamp((double)factor / scale, 1, 9999);
-            if (newSize > 1 && newSize < 4)
-                newSize = 4;
-            return new Rect(0, 0, newSize, newSize);
+            double newSize = Math.Clamp(factor / scale, 2, 9999);
+
+            //round to power of 2
+            newSize = Math.Pow(2, Math.Round(Math.Log(newSize, 2)));
+            return new RelativeRect(0, 0, newSize, newSize, RelativeUnit.Absolute);
         }
 
         return AvaloniaProperty.UnsetValue;

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/Controllers/InputDevice/MouseInputFilter.cs

@@ -39,7 +39,7 @@ internal class MouseInputFilter
     public void MouseUpInlet(object? sender, Point p, MouseButton button) => MouseUpInlet(button);
     public void MouseUpInlet(MouseButton button)
     {
-        if (button is MouseButton.XButton1 or MouseButton.XButton2)
+        if (button is MouseButton.XButton1 or MouseButton.XButton2 or MouseButton.None)
             return;
         if (!buttonStates[button])
             return;

+ 1 - 2
src/PixiEditor.AvaloniaUI/Views/Main/Viewport.axaml

@@ -130,11 +130,10 @@
                 d:Height="64"
                 HorizontalAlignment="Center"
                 VerticalAlignment="Center"
-                Width="64"
-                Height="64"
                 DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}}"
                 RenderOptions.BitmapInterpolationMode="None">
                 <Border.Background>
+                    <!--TODO: Seems like DestinationRect of anything with size below and equal to 1 is tiling texture wrong-->
                     <ImageBrush Source="/Images/CheckerTile.png" TileMode="Tile">
                         <ImageBrush.DestinationRect>
                             <Binding Path="Scale" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type zoombox:Zoombox}}"

+ 3 - 3
src/PixiEditor.AvaloniaUI/Views/Main/Viewport.axaml.cs

@@ -243,11 +243,11 @@ internal partial class Viewport : UserControl, INotifyPropertyChanged
             realDimensions = value;
             ChunkResolution newRes = CalculateResolution();
 
-            //PropertyChanged?.Invoke(this, new(nameof(RealDimensions)));
+            PropertyChanged?.Invoke(this, new(nameof(RealDimensions)));
             Document?.Operations.AddOrUpdateViewport(GetLocation());
 
-            /*if (oldRes != newRes)
-                PropertyChanged?.Invoke(this, new(nameof(TargetBitmap)));*/
+            if (oldRes != newRes)
+                PropertyChanged?.Invoke(this, new(nameof(TargetBitmap)));
         }
     }
 

+ 2 - 2
src/PixiEditor.Zoombox/Operations/ZoomDragOperation.cs

@@ -24,7 +24,7 @@ internal class ZoomDragOperation : IDragOperation
 
     public void Start(PointerEventArgs e)
     {
-        screenScaleOrigin = Zoombox.ToVecD(e.GetPosition(parent.mainCanvas));
+        screenScaleOrigin = Zoombox.ToVecD(e.GetPosition(parent.mainGrid));
         scaleOrigin = parent.ToZoomboxSpace(screenScaleOrigin);
         originalScale = parent.Scale;
         capturedPointer = e.Pointer;
@@ -33,7 +33,7 @@ internal class ZoomDragOperation : IDragOperation
 
     public void Update(PointerEventArgs e)
     {
-        Point curScreenPos = e.GetPosition(parent.mainCanvas);
+        Point curScreenPos = e.GetPosition(parent.mainGrid);
         double deltaX = curScreenPos.X - screenScaleOrigin.X;
         double deltaPower = deltaX / 10.0;
 

+ 5 - 5
src/PixiEditor.Zoombox/Zoombox.axaml.cs

@@ -152,7 +152,7 @@ public partial class Zoombox : UserControl, INotifyPropertyChanged
             delta.X = -delta.X;
         if (FlipY)
             delta.Y = -delta.Y;
-        delta += new VecD(mainCanvas.Bounds.Width / 2, mainCanvas.Bounds.Height / 2);
+        delta += new VecD(mainCanvas.Bounds.Width / 2f, mainCanvas.Bounds.Height / 2f);
         return delta;
     }
 
@@ -351,7 +351,7 @@ public partial class Zoombox : UserControl, INotifyPropertyChanged
         if (but == MouseButton.Right)
             return;
         activeMouseDownEventArgs = e;
-        activeMouseDownPos = ToVecD(e.GetPosition(uc));
+        activeMouseDownPos = ToVecD(e.GetPosition(mainCanvas));
         Focus(NavigationMethod.Unspecified);
     }
 
@@ -386,7 +386,7 @@ public partial class Zoombox : UserControl, INotifyPropertyChanged
         else
         {
             if (ZoomMode == ZoomboxMode.Zoom && e.InitialPressMouseButton == MouseButton.Left)
-                ZoomInto(ToVecD(e.GetPosition(uc)), ZoomOutOnClick ? -1 : 1);
+                ZoomInto(ToVecD(e.GetPosition(mainCanvas)), ZoomOutOnClick ? -1 : 1);
         }
         activeMouseDownEventArgs = null;
     }
@@ -395,7 +395,7 @@ public partial class Zoombox : UserControl, INotifyPropertyChanged
     {
         if (activeDragOperation is null && activeMouseDownEventArgs is not null)
         {
-            VecD cur = ToVecD(e.GetPosition(uc));
+            VecD cur = ToVecD(e.GetPosition(mainCanvas));
 
             if ((cur - activeMouseDownPos).TaxicabLength > 3)
                 InitiateDrag(activeMouseDownEventArgs);
@@ -408,7 +408,7 @@ public partial class Zoombox : UserControl, INotifyPropertyChanged
         double abs = Math.Abs(e.Delta.Y / 100.0);
         for (int i = 0; i < abs; i++)
         {
-            ZoomInto(ToVecD(e.GetPosition(uc)), e.Delta.Y / 100.0);
+            ZoomInto(ToVecD(e.GetPosition(mainCanvas)), e.Delta.Y / 100.0);
         }
     }