Browse Source

Added ability to use mouse wheel for editing number input's

CPKreuz 3 years ago
parent
commit
14f8f5e0c4

+ 1 - 1
PixiEditor/Views/UserControls/NumberInput.xaml

@@ -8,7 +8,7 @@
              mc:Ignorable="d"
              mc:Ignorable="d"
              d:DesignHeight="20" d:DesignWidth="40" x:Name="numberInput">
              d:DesignHeight="20" d:DesignWidth="40" x:Name="numberInput">
     <TextBox TextAlignment="Center" Style="{StaticResource DarkTextBoxStyle}" Focusable="True"
     <TextBox TextAlignment="Center" Style="{StaticResource DarkTextBoxStyle}" Focusable="True"
-             InputScope="Number"
+             InputScope="Number" MouseWheel="TextBox_MouseWheel"
              PreviewTextInput="TextBox_PreviewTextInput" Text="{Binding ElementName=numberInput, Path=Value}">
              PreviewTextInput="TextBox_PreviewTextInput" Text="{Binding ElementName=numberInput, Path=Value}">
         <i:Interaction.Behaviors>
         <i:Interaction.Behaviors>
             <behaviours:TextBoxFocusBehavior/>
             <behaviours:TextBoxFocusBehavior/>

+ 18 - 0
PixiEditor/Views/UserControls/NumberInput.xaml.cs

@@ -71,5 +71,23 @@ namespace PixiEditor.Views
         {
         {
             e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text));
             e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text));
         }
         }
+
+        private void TextBox_MouseWheel(object sender, MouseWheelEventArgs e)
+        {
+            int step = e.Delta / 100;
+
+            if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
+            {
+                Value += step * 2f;
+            }
+            else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
+            {
+                Value += step / 2f;
+            }
+            else
+            {
+                Value += step;
+            }
+        }
     }
     }
 }
 }

+ 5 - 12
PixiEditor/Views/UserControls/SizeInput.xaml

@@ -12,7 +12,8 @@
 
 
     <Border BorderThickness="1" CornerRadius="3.5"
     <Border BorderThickness="1" CornerRadius="3.5"
             x:Name="border"
             x:Name="border"
-            Cursor="IBeam" MouseLeftButtonDown="Border_MouseLeftButtonDown">
+            Cursor="IBeam" MouseLeftButtonDown="Border_MouseLeftButtonDown"
+            MouseWheel="Border_MouseWheel">
         <Border.Style>
         <Border.Style>
             <Style TargetType="Border">
             <Style TargetType="Border">
                 <Style.Triggers>
                 <Style.Triggers>
@@ -37,17 +38,9 @@
                      InputScope="Number" BorderThickness="0" Background="{x:Null}"
                      InputScope="Number" BorderThickness="0" Background="{x:Null}"
                      Foreground="{Binding Foreground, ElementName=uc}" Focusable="True"
                      Foreground="{Binding Foreground, ElementName=uc}" Focusable="True"
                      Margin="0,0,5,0" VerticalAlignment="Center"
                      Margin="0,0,5,0" VerticalAlignment="Center"
-                     x:Name="textBox">
-                <TextBox.Text>
-                    <Binding ElementName="uc"
-                             Path="Size" Mode="TwoWay"
-                             Converter="{converters:ToolSizeToIntConverter}">
-                        <Binding.ValidationRules>
-                            <validators:SizeValidationRule ValidatesOnTargetUpdated="True" />
-                        </Binding.ValidationRules>
-                    </Binding>
-                </TextBox.Text>
-                <d:TextBox.Text>22</d:TextBox.Text>
+                     x:Name="textBox"
+                     Text="{Binding Size, ElementName=uc, Converter={converters:ToolSizeToIntConverter}}"
+                     d:Text="22">
                 <i:Interaction.Behaviors>
                 <i:Interaction.Behaviors>
                     <behaviors:GlobalShortcutFocusBehavior/>
                     <behaviors:GlobalShortcutFocusBehavior/>
                     <behaviors:TextBoxFocusBehavior FillSize="True" />
                     <behaviors:TextBoxFocusBehavior FillSize="True" />

+ 38 - 11
PixiEditor/Views/UserControls/SizeInput.xaml.cs

@@ -1,7 +1,9 @@
-using System;
+using PixiEditor.Helpers;
+using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
+using System.Windows.Input;
 
 
 namespace PixiEditor.Views
 namespace PixiEditor.Views
 {
 {
@@ -75,18 +77,18 @@ namespace PixiEditor.Views
 
 
         private static void InputSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         private static void InputSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
         {
-            if ((int)e.NewValue > (int)d.GetValue(MaxSizeProperty))
+            int newValue = (int)e.NewValue;
+            int maxSize = (int)d.GetValue(MaxSizeProperty);
+
+            if (newValue > maxSize)
             {
             {
-                int? oldValue = e.OldValue as int?;
+                d.SetValue(SizeProperty, maxSize);
 
 
-                if (oldValue is null)
-                {
-                    d.SetValue(SizeProperty, 0);
-                }
-                else
-                {
-                    d.SetValue(SizeProperty, oldValue.Value);
-                }
+                return;
+            }
+            else if (newValue <= 0)
+            {
+                d.SetValue(SizeProperty, 1);
 
 
                 return;
                 return;
             }
             }
@@ -125,5 +127,30 @@ namespace PixiEditor.Views
         {
         {
             textBox.Focus();
             textBox.Focus();
         }
         }
+
+        private void Border_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
+        {
+            int step = e.Delta / 100;
+
+            if (Keyboard.IsKeyDown(Key.LeftShift))
+            {
+                Size += step * 2;
+            }
+            else if (Keyboard.IsKeyDown(Key.LeftCtrl))
+            {
+                if (step < 0)
+                {
+                    Size /= 2;
+                }
+                else
+                {
+                    Size *= 2;
+                }
+            }
+            else
+            {
+                Size += step;
+            }
+        }
     }
     }
 }
 }