Browse Source

Hide Highlight when stylus goes out of range

CPKreuz 3 years ago
parent
commit
95746b193f

+ 9 - 0
PixiEditor/ViewModels/SubViewModels/Main/StylusViewModel.cs

@@ -1,6 +1,7 @@
 using System.Windows;
 using System.Windows.Input;
 using GalaSoft.MvvmLight.CommandWpf;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools.Tools;
 using PixiEditor.Models.UserPreferences;
@@ -42,6 +43,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public RelayCommand<StylusButtonEventArgs> StylusUpCommand { get; }
 
+        public RelayCommand<StylusEventArgs> StylusOutOfRangeCommand { get; }
+
         public RelayCommand<StylusSystemGestureEventArgs> StylusGestureCommand { get; }
 
         public StylusViewModel(ViewModelMain owner)
@@ -49,6 +52,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         {
             StylusDownCommand = new(StylusDown);
             StylusUpCommand = new(StylusUp);
+            StylusOutOfRangeCommand = new(StylusOutOfRange);
             StylusGestureCommand = new(StylusSystemGesture);
 
             isPenModeEnabled = IPreferences.Current.GetLocalPreference<bool>(nameof(IsPenModeEnabled));
@@ -69,6 +73,11 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
         }
 
+        private void StylusOutOfRange(StylusEventArgs e)
+        {
+            Owner.BitmapManager.HighlightPixels(new Coordinates(-1, -1));
+        }
+
         private void StylusSystemGesture(StylusSystemGestureEventArgs e)
         {
             if (e.SystemGesture == SystemGesture.Drag || e.SystemGesture == SystemGesture.Tap)

+ 1 - 0
PixiEditor/Views/MainWindow.xaml

@@ -290,6 +290,7 @@
                                         StylusButtonDownCommand="{Binding XamlAccesibleViewModel.StylusSubViewModel.StylusDownCommand}"
                                         StylusButtonUpCommand="{Binding XamlAccesibleViewModel.StylusSubViewModel.StylusUpCommand}"
                                         StylusGestureCommand="{Binding XamlAccesibleViewModel.StylusSubViewModel.StylusGestureCommand}"
+                                        StylusOutOfRangeCommand="{Binding XamlAccesibleViewModel.StylusSubViewModel.StylusOutOfRangeCommand}"
                                         UseTouchGestures="{Binding XamlAccesibleViewModel.StylusSubViewModel.UseTouchGestures}"
                                         IsUsingZoomTool="{Binding XamlAccesibleViewModel.ToolsSubViewModel.ActiveTool, Converter={converters:IsSpecifiedTypeConverter SpecifiedType={x:Type tools:ZoomTool}}}"
                                         IsUsingMoveViewportTool="{Binding XamlAccesibleViewModel.ToolsSubViewModel.ActiveTool, Converter={converters:IsSpecifiedTypeConverter SpecifiedType={x:Type tools:MoveViewportTool}}}"

+ 4 - 0
PixiEditor/Views/UserControls/DrawingViewPort.xaml

@@ -44,6 +44,10 @@
                 <cmd:EventToCommand Command="{Binding StylusGestureCommand, ElementName=uc}"
                                         PassEventArgsToCommand="True"/>
             </i:EventTrigger>
+            <i:EventTrigger EventName="StylusOutOfRange">
+                <cmd:EventToCommand Command="{Binding StylusOutOfRangeCommand, ElementName=uc}"
+                                        PassEventArgsToCommand="True"/>
+            </i:EventTrigger>
         </i:Interaction.Triggers>
         <i:Interaction.Behaviors>
             <behaviors:MouseBehavior RelativeTo="{Binding ElementName=zoombox, Path=AdditionalContent}"

+ 9 - 0
PixiEditor/Views/UserControls/DrawingViewPort.xaml.cs

@@ -30,6 +30,9 @@ namespace PixiEditor.Views.UserControls
         public static readonly DependencyProperty StylusButtonUpCommandProperty =
             DependencyProperty.Register(nameof(StylusButtonUpCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
 
+        public static readonly DependencyProperty StylusOutOfRangeCommandProperty =
+            DependencyProperty.Register(nameof(StylusOutOfRangeCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
+
         public static readonly DependencyProperty MouseXOnCanvasProperty =
             DependencyProperty.Register(nameof(MouseXOnCanvas), typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
 
@@ -92,6 +95,12 @@ namespace PixiEditor.Views.UserControls
             set => SetValue(StylusGestureCommandProperty, value);
         }
 
+        public ICommand StylusOutOfRangeCommand
+        {
+            get => (ICommand)GetValue(StylusOutOfRangeCommandProperty);
+            set => SetValue(StylusOutOfRangeCommandProperty, value);
+        }
+
         public double MouseXOnCanvas
         {
             get => (double)GetValue(MouseXOnCanvasProperty);