Browse Source

Maybe fix zoombox touch

Equbuxu 3 years ago
parent
commit
3384f9d1ff

+ 1 - 1
src/ChunkyImageLib/DataHolders/Vector2d.cs

@@ -145,7 +145,7 @@ namespace ChunkyImageLib.DataHolders
 
         public override string ToString()
         {
-            return $"({X},{Y})";
+            return $"({X}; {Y})";
         }
 
         public override bool Equals(object? obj)

+ 1 - 1
src/ChunkyImageLib/DataHolders/Vector2i.cs

@@ -93,7 +93,7 @@ namespace ChunkyImageLib.DataHolders
 
         public override string ToString()
         {
-            return $"({X},{Y})";
+            return $"({X}; {Y})";
         }
 
         public override bool Equals(object? obj)

+ 0 - 21
src/PixiEditor.Zoombox/BoolToIntConverter.cs

@@ -1,21 +0,0 @@
-using System;
-using System.Globalization;
-using System.Windows.Data;
-
-namespace PixiEditor.Zoombox
-{
-    internal class BoolToIntConverter : IValueConverter
-    {
-        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
-        {
-            if (value == null || value is not bool converted)
-                return 1;
-            return converted ? -1 : 1;
-        }
-
-        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
-        {
-            throw new NotImplementedException();
-        }
-    }
-}

+ 0 - 5
src/PixiEditor.Zoombox/Zoombox.xaml

@@ -7,11 +7,6 @@
              mc:Ignorable="d"
              x:Name="uc"
              d:DesignHeight="450" d:DesignWidth="800">
-    <ContentControl.Resources>
-        <ResourceDictionary>
-            <local:BoolToIntConverter x:Key="BoolToIntConverter"/>
-        </ResourceDictionary>
-    </ContentControl.Resources>
     <Canvas MouseDown="OnMouseDown" MouseUp="OnMouseUp" MouseMove="OnMouseMove" MouseWheel="OnScroll" ClipToBounds="True"
             IsManipulationEnabled="{Binding UseTouchGestures, ElementName=uc}" ManipulationDelta="OnManipulationDelta"
             x:Name="mainCanvas" Background="Transparent" SizeChanged="OnMainCanvasSizeChanged">

+ 23 - 18
src/PixiEditor.Zoombox/Zoombox.xaml.cs

@@ -176,6 +176,7 @@ namespace PixiEditor.Zoombox
         public Zoombox()
         {
             InitializeComponent();
+            Loaded += (_, _) => OnPropertyChange(this, new DependencyPropertyChangedEventArgs());
         }
 
         private void RaiseViewportEvent()
@@ -314,24 +315,28 @@ namespace PixiEditor.Zoombox
 
         private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
         {
-            if (UseTouchGestures)
-            {
-                e.Handled = true;
-                double newScale = Math.Clamp(Scale * e.DeltaManipulation.Scale.X, MinScale, MaxScale);
-                double newAngle = Angle + e.DeltaManipulation.Rotation;
-                Vector2d screenTranslation = new(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
-                Vector2d screenOrigin = new(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
-
-                Vector2d originalPos = ToZoomboxSpace(screenOrigin);
-                Angle = newAngle;
-                Scale = newScale;
-                Vector2d newPos = ToZoomboxSpace(screenOrigin);
-                Vector2d centerTranslation = originalPos - newPos;
-                Center += centerTranslation;
-
-                Vector2d translatedZoomboxPos = ToZoomboxSpace(screenOrigin + screenTranslation);
-                Center -= translatedZoomboxPos - originalPos;
-            }
+            if (!UseTouchGestures)
+                return;
+            e.Handled = true;
+            Vector2d screenTranslation = new(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
+            Vector2d screenOrigin = new(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
+            Manipulate(e.DeltaManipulation.Scale.X, screenTranslation, screenOrigin, e.DeltaManipulation.Rotation / 180 * Math.PI);
+        }
+
+        private void Manipulate(double deltaScale, Vector2d screenTranslation, Vector2d screenOrigin, double rotation)
+        {
+            double newScale = Math.Clamp(Scale * deltaScale, MinScale, MaxScale);
+            double newAngle = Angle + rotation;
+
+            Vector2d originalPos = ToZoomboxSpace(screenOrigin);
+            Angle = newAngle;
+            Scale = newScale;
+            Vector2d newPos = ToZoomboxSpace(screenOrigin);
+            Vector2d centerTranslation = originalPos - newPos;
+            Center += centerTranslation;
+
+            Vector2d translatedZoomboxPos = ToZoomboxSpace(screenOrigin + screenTranslation);
+            Center -= translatedZoomboxPos - originalPos;
         }
 
         internal static Vector2d ToVector2d(Point point) => new Vector2d(point.X, point.Y);