Skip to content

Commit

Permalink
Hide Highlight when stylus goes out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
CPKreu committed Dec 6, 2021
1 parent fdab417 commit 95746b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PixiEditor/ViewModels/SubViewModels/Main/StylusViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,13 +43,16 @@ public bool UseTouchGestures

public RelayCommand<StylusButtonEventArgs> StylusUpCommand { get; }

public RelayCommand<StylusEventArgs> StylusOutOfRangeCommand { get; }

public RelayCommand<StylusSystemGestureEventArgs> StylusGestureCommand { get; }

public StylusViewModel(ViewModelMain owner)
: base(owner)
{
StylusDownCommand = new(StylusDown);
StylusUpCommand = new(StylusUp);
StylusOutOfRangeCommand = new(StylusOutOfRange);
StylusGestureCommand = new(StylusSystemGesture);

isPenModeEnabled = IPreferences.Current.GetLocalPreference<bool>(nameof(IsPenModeEnabled));
Expand All @@ -69,6 +73,11 @@ private void UpdateUseTouchGesture()
}
}

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)
Expand Down
1 change: 1 addition & 0 deletions PixiEditor/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}"
Expand Down
4 changes: 4 additions & 0 deletions PixiEditor/Views/UserControls/DrawingViewPort.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 9 additions & 0 deletions PixiEditor/Views/UserControls/DrawingViewPort.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public partial class DrawingViewPort : UserControl
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));

Expand Down Expand Up @@ -92,6 +95,12 @@ public ICommand StylusGestureCommand
set => SetValue(StylusGestureCommandProperty, value);
}

public ICommand StylusOutOfRangeCommand
{
get => (ICommand)GetValue(StylusOutOfRangeCommandProperty);
set => SetValue(StylusOutOfRangeCommandProperty, value);
}

public double MouseXOnCanvas
{
get => (double)GetValue(MouseXOnCanvasProperty);
Expand Down

0 comments on commit 95746b1

Please sign in to comment.