Browse Source

Fixed aspect ratio and scroll

flabbet 3 years ago
parent
commit
011fc114ae

+ 13 - 0
PixiEditor/Views/UserControls/SizeInput.xaml.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.Enums;
+using System;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -22,6 +23,16 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty UnitProperty =
             DependencyProperty.Register(nameof(Unit), typeof(SizeUnit), typeof(SizeInput), new PropertyMetadata(SizeUnit.Pixel));
 
+        public Action OnScrollAction
+        {
+            get { return (Action)GetValue(OnScrollActionProperty); }
+            set { SetValue(OnScrollActionProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for OnScrollAction.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty OnScrollActionProperty =
+            DependencyProperty.Register("OnScrollAction", typeof(Action), typeof(SizeInput), new PropertyMetadata(null));
+
         public SizeInput()
         {
             InitializeComponent();
@@ -119,6 +130,8 @@ namespace PixiEditor.Views
             {
                 Size += step;
             }
+
+            OnScrollAction?.Invoke();
         }
     }
 }

+ 13 - 1
PixiEditor/Views/UserControls/SizePicker.xaml.cs

@@ -13,7 +13,7 @@ namespace PixiEditor.Views
             DependencyProperty.Register(nameof(EditingEnabled), typeof(bool), typeof(SizePicker), new PropertyMetadata(true));
 
         public static readonly DependencyProperty PreserveAspectRatioProperty =
-            DependencyProperty.Register(nameof(PreserveAspectRatio), typeof(bool), typeof(SizePicker), new PropertyMetadata(true));
+            DependencyProperty.Register(nameof(PreserveAspectRatio), typeof(bool), typeof(SizePicker), new PropertyMetadata(true, OnPreserveAspectRatioChanged));
 
         public static readonly DependencyProperty ChosenWidthProperty =
             DependencyProperty.Register(nameof(ChosenWidth), typeof(int), typeof(SizePicker), new PropertyMetadata(1));
@@ -85,7 +85,12 @@ namespace PixiEditor.Views
             WidthLostFocusCommand = new(WidthLostFocus);
             HeightLostFocusCommand = new(HeightLostFocus);
             PercentageLostFocusCommand = new(PercentageLostFocus);
+
             InitializeComponent();
+
+            WidthPicker.OnScrollAction = () => OnSizeUpdate(true);
+            HeightPicker.OnScrollAction = () => OnSizeUpdate(false);
+            PercentageSizePicker.OnScrollAction = () => PercentageLostFocus(null);
         }
 
         public void FocusWidthPicker()
@@ -93,6 +98,13 @@ namespace PixiEditor.Views
             WidthPicker.FocusAndSelect();
         }
 
+
+        private static void OnPreserveAspectRatioChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            SizePicker picker = (SizePicker)d;
+            picker.initSize = new System.Drawing.Size(picker.ChosenWidth, picker.ChosenHeight);
+        }
+
         private void AfterLoaded(object parameter)
         {
             initSize = new System.Drawing.Size(ChosenWidth, ChosenHeight);