|
@@ -1,5 +1,4 @@
|
|
-using System;
|
|
|
|
-using System.Windows;
|
|
|
|
|
|
+using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
|
|
|
|
@@ -11,20 +10,11 @@ namespace PixiEditor.Views
|
|
public partial class SizeInput : UserControl
|
|
public partial class SizeInput : UserControl
|
|
{
|
|
{
|
|
public static readonly DependencyProperty SizeProperty =
|
|
public static readonly DependencyProperty SizeProperty =
|
|
- DependencyProperty.Register(nameof(Size), typeof(int), typeof(SizeInput), new PropertyMetadata(1, InputSizeChanged));
|
|
|
|
|
|
+ DependencyProperty.Register(nameof(Size), typeof(int), typeof(SizeInput), new PropertyMetadata(1));
|
|
|
|
|
|
public static readonly DependencyProperty MaxSizeProperty =
|
|
public static readonly DependencyProperty MaxSizeProperty =
|
|
DependencyProperty.Register(nameof(MaxSize), typeof(int), typeof(SizeInput), new PropertyMetadata(int.MaxValue));
|
|
DependencyProperty.Register(nameof(MaxSize), typeof(int), typeof(SizeInput), new PropertyMetadata(int.MaxValue));
|
|
|
|
|
|
- public static readonly DependencyProperty PreserveAspectRatioProperty =
|
|
|
|
- DependencyProperty.Register(nameof(PreserveAspectRatio), typeof(bool), typeof(SizeInput));
|
|
|
|
-
|
|
|
|
- public static readonly DependencyProperty AspectRatioValueProperty =
|
|
|
|
- DependencyProperty.Register(nameof(AspectRatioValue), typeof(int), typeof(SizeInput), new PropertyMetadata(1));
|
|
|
|
-
|
|
|
|
- public static readonly DependencyProperty AspectRatioControlProperty =
|
|
|
|
- DependencyProperty.Register(nameof(AspectRatioControl), typeof(SizeInput), typeof(SizeInput), new PropertyMetadata(default));
|
|
|
|
-
|
|
|
|
public static readonly DependencyProperty BehaveLikeSmallEmbeddedFieldProperty =
|
|
public static readonly DependencyProperty BehaveLikeSmallEmbeddedFieldProperty =
|
|
DependencyProperty.Register(nameof(BehaveLikeSmallEmbeddedField), typeof(bool), typeof(SizeInput), new PropertyMetadata(true));
|
|
DependencyProperty.Register(nameof(BehaveLikeSmallEmbeddedField), typeof(bool), typeof(SizeInput), new PropertyMetadata(true));
|
|
|
|
|
|
@@ -40,35 +30,12 @@ namespace PixiEditor.Views
|
|
set => SetValue(MaxSizeProperty, value);
|
|
set => SetValue(MaxSizeProperty, value);
|
|
}
|
|
}
|
|
|
|
|
|
- public bool PreserveAspectRatio
|
|
|
|
- {
|
|
|
|
- get => (bool)GetValue(PreserveAspectRatioProperty);
|
|
|
|
- set => SetValue(PreserveAspectRatioProperty, value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int AspectRatioValue
|
|
|
|
- {
|
|
|
|
- get => (int)GetValue(AspectRatioValueProperty);
|
|
|
|
- set => SetValue(AspectRatioValueProperty, value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public SizeInput AspectRatioControl
|
|
|
|
- {
|
|
|
|
- get { return (SizeInput)GetValue(AspectRatioControlProperty); }
|
|
|
|
- set { SetValue(AspectRatioControlProperty, value); }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public bool BehaveLikeSmallEmbeddedField
|
|
public bool BehaveLikeSmallEmbeddedField
|
|
{
|
|
{
|
|
get => (bool)GetValue(BehaveLikeSmallEmbeddedFieldProperty);
|
|
get => (bool)GetValue(BehaveLikeSmallEmbeddedFieldProperty);
|
|
set => SetValue(BehaveLikeSmallEmbeddedFieldProperty, value);
|
|
set => SetValue(BehaveLikeSmallEmbeddedFieldProperty, value);
|
|
}
|
|
}
|
|
|
|
|
|
- private int loadedAspectRatioSize = -1;
|
|
|
|
-
|
|
|
|
- private int loadedSize = -1;
|
|
|
|
- private bool blockUpdate = false;
|
|
|
|
-
|
|
|
|
public SizeInput()
|
|
public SizeInput()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
@@ -80,55 +47,7 @@ namespace PixiEditor.Views
|
|
textBox.SelectAll();
|
|
textBox.SelectAll();
|
|
}
|
|
}
|
|
|
|
|
|
- private static void InputSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
|
|
- {
|
|
|
|
- int newValue = (int)e.NewValue;
|
|
|
|
- int maxSize = (int)d.GetValue(MaxSizeProperty);
|
|
|
|
-
|
|
|
|
- if (newValue > maxSize)
|
|
|
|
- {
|
|
|
|
- d.SetValue(SizeProperty, maxSize);
|
|
|
|
-
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- else if (newValue <= 0)
|
|
|
|
- {
|
|
|
|
- d.SetValue(SizeProperty, 1);
|
|
|
|
-
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- SizeInput input = ((SizeInput)d).AspectRatioControl;
|
|
|
|
- if (input == null)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int newVal = (int)e.NewValue;
|
|
|
|
- if (input.PreserveAspectRatio && !input.IsFocused && !input.blockUpdate)
|
|
|
|
- {
|
|
|
|
- float ratio = newVal / Math.Clamp(input.loadedAspectRatioSize, 1f, float.MaxValue);
|
|
|
|
- int newSize = (int)(input.loadedSize * ratio);
|
|
|
|
- input.AspectRatioControl.blockUpdate = true; // Block update is used to prevent infinite feedback loop.
|
|
|
|
- input.Size = newSize;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (input.blockUpdate)
|
|
|
|
- {
|
|
|
|
- input.blockUpdate = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void UserControlLayoutUpdated(object sender, EventArgs e)
|
|
|
|
- {
|
|
|
|
- if (loadedSize == -1)
|
|
|
|
- {
|
|
|
|
- loadedSize = Size;
|
|
|
|
- loadedAspectRatioSize = AspectRatioValue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void Border_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
|
|
|
|
+ private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
{
|
|
if (!textBox.IsFocused)
|
|
if (!textBox.IsFocused)
|
|
textBox.Focus();
|
|
textBox.Focus();
|
|
@@ -143,7 +62,7 @@ namespace PixiEditor.Views
|
|
e.Handled = true;
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void Border_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
|
|
|
|
|
+ private void Border_MouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
{
|
|
int step = e.Delta / 100;
|
|
int step = e.Delta / 100;
|
|
|
|
|