Skip to content

Commit

Permalink
suport mouse gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
TransposonY committed Jan 21, 2017
1 parent fcb42e0 commit d97d70e
Show file tree
Hide file tree
Showing 25 changed files with 1,305 additions and 20 deletions.
2 changes: 1 addition & 1 deletion GestureSign.Common/Applications/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected void PointCapture_CaptureStarted(object sender, PointsCapturedEventArg
}
}
}
e.Cancel = limitNumberFlag ?? e.Points.Count == 1;
e.Cancel = !pointCapture.MouseCaptured && (limitNumberFlag ?? e.Points.Count == 1);
e.BlockTouchInputThreshold = maxThreshold;
}

Expand Down
17 changes: 13 additions & 4 deletions GestureSign.Common/Configuration/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.IO;
using GestureSign.Common.InterProcessCommunication;
using ManagedWinapi.Hooks;

namespace GestureSign.Common.Configuration
{
Expand Down Expand Up @@ -151,6 +148,18 @@ public static int GestureTimeout
}
}

public static MouseActions DrawingButton
{
get
{
return (MouseActions)GetValue(nameof(DrawingButton), 0x200000);
}
set
{
SetValue(nameof(DrawingButton), (int)value);
}
}

static AppConfig()
{
#if uiAccess
Expand Down
4 changes: 4 additions & 0 deletions GestureSign.Common/Gestures/Gesture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.Serialization;
using ManagedWinapi;
using ManagedWinapi.Hooks;

namespace GestureSign.Common.Gestures
{
Expand Down Expand Up @@ -31,6 +32,9 @@ public Gesture(string name, PointPattern[] pointPatterns)
[DataMember]
public Hotkey Hotkey { get; set; }

[DataMember]
public MouseActions MouseAction { get; set; }

public bool Equals(Gesture other)
{
if (other == null) return false;
Expand Down
1 change: 1 addition & 0 deletions GestureSign.Common/Input/IPointCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IPointCapture
event PointsCapturedEventHandler PointCaptured;
bool StackUpGesture { get; set; }
bool TemporarilyDisableCapture { get; set; }
bool MouseCaptured { get; set; }
CaptureState State { get; set; }
CaptureMode Mode { get; set; }
}
Expand Down
1 change: 1 addition & 0 deletions GestureSign.ControlPanel/Common/GestureItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class GestureItem
public string Name { get; set; }
public System.Windows.Media.ImageSource Image { get; set; }
public string HotKey { get; set; }
public string MouseAction { get; set; }
}
}
7 changes: 7 additions & 0 deletions GestureSign.ControlPanel/Dialogs/GestureDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using GestureSign.Common.Configuration;
using GestureSign.ControlPanel.ViewModel;
using ManagedWinapi;
using ManagedWinapi.Hooks;

namespace GestureSign.ControlPanel.Dialogs
{
Expand Down Expand Up @@ -68,6 +71,8 @@ public string SimilarGestureName

private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (MouseActionDescription.DescriptionDict.ContainsKey(AppConfig.DrawingButton))
DrawingButtonTextBlock.Text = MouseActionDescription.DescriptionDict[AppConfig.DrawingButton] + " + ";
_color = (Color)Application.Current.Resources["HighlightColor"];

if (_currentPointPatterns != null)
Expand All @@ -80,6 +85,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
}
else
{
MouseActionComboBox.SelectedValue = _oldGesture.MouseAction;
Title = LocalizationProvider.Instance.GetTextValue("GestureDefinition.Rename");
txtGestureName.Text = _oldGesture.Name; //this.txtGestureName.Text
var hotkey = ((Gesture)_oldGesture).Hotkey;
Expand Down Expand Up @@ -187,6 +193,7 @@ private bool SaveGesture()
{
Name = newGestureName,
PointPatterns = _currentPointPatterns,
MouseAction = (MouseActions)MouseActionComboBox.SelectedValue,
Hotkey = HotKeyTextBox.HotKey != null ?
new Hotkey()
{
Expand Down
21 changes: 21 additions & 0 deletions GestureSign.ControlPanel/Dialogs/GestureDefinition.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:localization="clr-namespace:GestureSign.Common.Localization;assembly=GestureSign.Common"
xmlns:validationRules="clr-namespace:GestureSign.ControlPanel.ValidationRules"
xmlns:viewModel="clr-namespace:GestureSign.ControlPanel.ViewModel"
BorderBrush="{StaticResource AccentColorBrush}"
BorderThickness="1"
Height="325.145"
Expand All @@ -19,6 +20,8 @@
Icon="/GestureSign;component/Resources/normal.ico"
WindowStartupLocation="CenterScreen">
<controls:MetroWindow.Resources>
<ObjectDataProvider x:Key="MouseActionDescription"
ObjectType="{x:Type viewModel:MouseActionDescription}" />
</controls:MetroWindow.Resources>
<StackPanel>
<TabControl>
Expand Down Expand Up @@ -85,6 +88,24 @@
</controls:HotKeyBox>
</Canvas>
</TabItem>
<TabItem Header="{localization:LocalisedText GestureDefinition.Mouse}"
controls:ControlsHelper.HeaderFontSize="18">
<StackPanel Height="50"
Orientation="Horizontal">
<TextBlock x:Name="DrawingButtonTextBlock"
FontSize="14"
Margin="20,0,0,0"
VerticalAlignment="Center" />
<ComboBox x:Name="MouseActionComboBox"
ItemsSource="{Binding Source={StaticResource MouseActionDescription},Path=DescriptionDict}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
FontSize="14"
MaxWidth="150"
Margin="10,0"
VerticalAlignment="Center" />
</StackPanel>
</TabItem>
</TabControl>
<TextBox x:Name="txtGestureName"
controls:TextBoxHelper.Watermark="{localization:LocalisedText GestureDefinition.GestureNameWatermark}"
Expand Down
1 change: 1 addition & 0 deletions GestureSign.ControlPanel/GestureSign.ControlPanel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ViewModel\MouseActionDescription.cs" />
<Compile Include="Common\ErrorReport.cs" />
<Compile Include="Converters\Application2VisibilityConverter.cs" />
<Compile Include="Converters\MatchUsing2VisibilityConverter.cs" />
Expand Down
13 changes: 13 additions & 0 deletions GestureSign.ControlPanel/Languages/ControlPanel/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ Or click the button below to select the running applications.</GetMatchStringTip
<Details>Details</Details>
<ImportGesture>Import Gestures...</ImportGesture>
<ExportGestures>Export Gestures...</ExportGestures>
<MouseActions>
<None>None</None>
<WheelForward>Wheel Forward</WheelForward>
<WheelBackward>Wheel Backward</WheelBackward>
<Left>Left Button</Left>
<Right>Right Button</Right>
<Middle>Middle Button</Middle>
<XButton1>XButton1</XButton1>
<XButton2>XButton2</XButton2>
</MouseActions>
<Messages>
<DeleteConfirmTitle>Delete Confirm</DeleteConfirmTitle>
<DeleteGestureConfirm>Are you sure?</DeleteGestureConfirm>
Expand All @@ -167,6 +177,7 @@ Or click the button below to select the running applications.</GetMatchStringTip
<Reset>Reset</Reset>
<HotKey>HotKey</HotKey>
<HotKeyWatermark>Enter hot key</HotKeyWatermark>
<Mouse>Mouse</Mouse>
<Messages>
<GestureExists>The Gesture Name "{0}" already exists, please provide a different Gesture Name</GestureExists>
</Messages>
Expand Down Expand Up @@ -208,6 +219,8 @@ Or click the button below to select the running applications.</GetMatchStringTip
<OffLabel>Off</OffLabel>
<Mail>You can also send mail to [email protected]</Mail>
<Timeout>Gesture Timeout (ms)</Timeout>
<MouseGesture>Mouse Gesture</MouseGesture>
<DrawingButton>Draw gesture by holding: </DrawingButton>
<WindowsStartup>
<Header>Start GestureSign on Windows Startup</Header>
</WindowsStartup>
Expand Down
13 changes: 13 additions & 0 deletions GestureSign.ControlPanel/Languages/ControlPanel/zh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ http://transposony.coding.me/GestureSign/
<Details>详细信息</Details>
<ImportGesture>导入手势文件</ImportGesture>
<ExportGestures>导出手势数据</ExportGestures>
<MouseActions>
<None>未设置</None>
<WheelForward>向前滚动</WheelForward>
<WheelBackward>向后滚动</WheelBackward>
<Left>左键</Left>
<Right>右键</Right>
<Middle>中键</Middle>
<XButton1>X1键</XButton1>
<XButton2>X2键</XButton2>
</MouseActions>
<Messages>
<DeleteConfirmTitle>删除手势</DeleteConfirmTitle>
<DeleteGestureConfirm>确定删除这手势吗?</DeleteGestureConfirm>
Expand All @@ -173,6 +183,7 @@ http://transposony.coding.me/GestureSign/
<Reset>重置</Reset>
<HotKey>快捷键</HotKey>
<HotKeyWatermark>可为该手势指定一个快捷键</HotKeyWatermark>
<Mouse>鼠标键</Mouse>
<Messages>
<GestureExists>输入的手势名称{0}已存在,请重新输入一个手势名称</GestureExists>
</Messages>
Expand Down Expand Up @@ -214,6 +225,8 @@ http://transposony.coding.me/GestureSign/
<OffLabel>关</OffLabel>
<Mail>您也可以直接将信息反馈到 [email protected]</Mail>
<Timeout>手势超时 (毫秒)</Timeout>
<MouseGesture>鼠标手势</MouseGesture>
<DrawingButton>鼠标手势键:</DrawingButton>
<WindowsStartup>
<Header>开机启动</Header>
</WindowsStartup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Header="{localization:LocalisedText GestureDefinition.HotKey}"
DisplayMemberBinding="{Binding Path=HotKey}" />
<GridViewColumn Header="{localization:LocalisedText GestureDefinition.Mouse}"
DisplayMemberBinding="{Binding Path=MouseAction}" />
</GridView>
</UserControl.Resources>
<Grid>
Expand Down
23 changes: 20 additions & 3 deletions GestureSign.ControlPanel/MainWindowControls/Options.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Security.Principal;
using System.Text;
Expand All @@ -10,15 +9,14 @@
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using GestureSign.Common;
using GestureSign.Common.Configuration;
using GestureSign.Common.InterProcessCommunication;
using GestureSign.Common.Localization;
using GestureSign.ControlPanel.Common;
using IWshRuntimeLibrary;
using ManagedWinapi.Windows;
using Microsoft.Win32.TaskScheduler;
using MahApps.Metro.Controls.Dialogs;
using ManagedWinapi.Hooks;
using Application = System.Windows.Application;
using Color = System.Drawing.Color;
using File = System.IO.File;
Expand Down Expand Up @@ -58,6 +56,11 @@ private void LoadSettings()
ShowBalloonTipSwitch.IsChecked = AppConfig.ShowBalloonTip;
ShowTrayIconSwitch.IsChecked = AppConfig.ShowTrayIcon;
SendLogToggleSwitch.IsChecked = AppConfig.SendErrorReport;
if (AppConfig.DrawingButton != MouseActions.None)
{
MouseSwitch.IsChecked = true;
DrawingButtonComboBox.SelectedValue = AppConfig.DrawingButton;
}

LanguageComboBox.ItemsSource = LocalizationProvider.Instance.GetLanguageList("ControlPanel");
LanguageComboBox.SelectedValue = AppConfig.CultureName;
Expand Down Expand Up @@ -341,6 +344,20 @@ private void LanguageComboBox_DropDownClosed(object sender, EventArgs e)
AppConfig.Save();
}

private void MouseSwitch_Click(object sender, RoutedEventArgs e)
{
if (MouseSwitch.IsChecked != null && MouseSwitch.IsChecked.Value)
DrawingButtonComboBox.SelectedValue = AppConfig.DrawingButton = MouseActions.Right;
else AppConfig.DrawingButton = MouseActions.None;
AppConfig.Save();
}

private void DrawingButtonComboBox_DropDownClosed(object sender, EventArgs e)
{
AppConfig.DrawingButton = (MouseActions)DrawingButtonComboBox.SelectedValue;
AppConfig.Save();
}

private async void ExportLogButton_Click(object sender, RoutedEventArgs e)
{
string logPath = Path.Combine(Path.GetTempPath(), "GestureSign" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".log");
Expand Down
57 changes: 57 additions & 0 deletions GestureSign.ControlPanel/MainWindowControls/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:localization="clr-namespace:GestureSign.Common.Localization;assembly=GestureSign.Common"
xmlns:common="clr-namespace:GestureSign.ControlPanel.Common"
xmlns:viewModel="clr-namespace:GestureSign.ControlPanel.ViewModel"
mc:Ignorable="d"
Height="381"
Width="380"
Expand All @@ -19,6 +20,8 @@
<Setter Property="FontFamily"
Value="{StaticResource DefaultFont}" />
</Style>
<ObjectDataProvider x:Key="MouseActionDescription"
ObjectType="{x:Type viewModel:MouseActionDescription}" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatSlider.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -143,6 +146,60 @@
FontWeight="Bold"
Click="ExportLogButton_Click" />

<controls:ToggleSwitch x:Name="MouseSwitch"
Header="{localization:LocalisedText Options.MouseGesture}"
OnLabel="{localization:LocalisedText Options.OnLabel}"
OffLabel="{localization:LocalisedText Options.OffLabel}"
Margin="0,10"
FontSize="14"
Width="300"
FontWeight="Bold"
Click="MouseSwitch_Click">
</controls:ToggleSwitch>
<TextBlock x:Name="DrawingButtonTextBlock"
Text="{localization:LocalisedText Options.DrawingButton}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="14"
Margin="0,0,0,5">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility"
Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MouseSwitch,Path=IsChecked}"
Value="True">
<Setter Property="Visibility"
Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<ComboBox x:Name="DrawingButtonComboBox"
ItemsSource="{Binding Source={StaticResource MouseActionDescription},Path=DrawingDescription}"
HorizontalAlignment="Center"
Width="300"
FontSize="14"
Margin="0,5,0,15"
DisplayMemberPath="Value"
SelectedValuePath="Key"
DropDownClosed="DrawingButtonComboBox_DropDownClosed">
<ComboBox.Style>
<Style TargetType="ComboBox"
BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter Property="Visibility"
Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MouseSwitch,Path=IsChecked}"
Value="True">
<Setter Property="Visibility"
Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
<controls:ToggleSwitch x:Name="chkWindowsStartup"
Header="{localization:LocalisedText Options.WindowsStartup.Header}"
OnLabel="{localization:LocalisedText Options.OnLabel}"
Expand Down
2 changes: 2 additions & 0 deletions GestureSign.ControlPanel/ViewModel/GestureItemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GestureSign.Common.Gestures;
using GestureSign.ControlPanel.Common;
using MahApps.Metro.Controls;
using ManagedWinapi.Hooks;

namespace GestureSign.ControlPanel.ViewModel
{
Expand Down Expand Up @@ -47,6 +48,7 @@ private static void Update()
var gesture = (Gesture)g;
GestureItem newItem = new GestureItem()
{
MouseAction = gesture.MouseAction == MouseActions.None ? string.Empty : MouseActionDescription.DescriptionDict[gesture.MouseAction],
Image = GestureImage.CreateImage(gesture.PointPatterns, new Size(65, 65), color),
Name = gesture.Name,
HotKey = gesture.Hotkey != null ? new HotKey(KeyInterop.KeyFromVirtualKey(gesture.Hotkey.KeyCode), (ModifierKeys)gesture.Hotkey.ModifierKeys).ToString() : string.Empty
Expand Down
Loading

0 comments on commit d97d70e

Please sign in to comment.