Skip to content

Commit

Permalink
Add delay when dragging finger across multiple buttons
Browse files Browse the repository at this point in the history
Include com0com 2.2.2.0 for easy virtual com port installation
  • Loading branch information
Leapward-Koex committed Feb 9, 2024
1 parent e4fade6 commit b9315a5
Show file tree
Hide file tree
Showing 12 changed files with 511 additions and 10 deletions.
2 changes: 1 addition & 1 deletion TouchPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Border Background="#01000000">
<StackPanel>
<Viewbox Stretch="Uniform" Opacity="1">
<Canvas Width="502" Height="502">
<Canvas x:Name="TouchCanvas" Width="502" Height="502">
<Border HorizontalAlignment="Left" VerticalAlignment="Center"
Height="30" Background="White" MouseLeftButtonDown="DragBar_MouseLeftButtonDown"
Cursor="SizeAll" Width="38">
Expand Down
26 changes: 21 additions & 5 deletions TouchPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

Expand All @@ -14,6 +15,7 @@ public partial class TouchPanel : Window

private readonly Dictionary<int, System.Windows.Controls.Image> activeTouches = [];
private readonly TouchPanelPositionManager _positionManager;
private List<Image> buttons = [];

private enum ResizeDirection
{
Expand All @@ -32,7 +34,12 @@ public TouchPanel()
InitializeComponent();
Topmost = true;
_positionManager = new TouchPanelPositionManager();
Loaded += Window_Loaded;
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
buttons = VisualTreeHelperExtensions.FindVisualChildren<System.Windows.Controls.Image>(this);
}

public void PositionTouchPanel()
Expand Down Expand Up @@ -93,8 +100,16 @@ private void Element_TouchMove(object sender, TouchEventArgs e)
// If this touch point is already tracking another element, unhighlight the previous one.
if (activeTouches.TryGetValue(e.TouchDevice.Id, out var previousElement) && previousElement != newElement)
{
HighlightElement(previousElement, false);
onRelease((TouchValue)previousElement.Tag);
Task.Delay(50)
.ContinueWith(t =>
{
HighlightElement(previousElement, false);
Application.Current.Dispatcher.Invoke(() =>
{
onRelease((TouchValue)previousElement.Tag);
});
});

}

// Highlight the new element and update the tracking.
Expand Down Expand Up @@ -146,7 +161,6 @@ private void DeselectAllItems()

public void SetDebugMode(bool enabled)
{
var buttons = VisualTreeHelperExtensions.FindVisualChildren<System.Windows.Controls.Image>(this);
buttons.ForEach(button =>
{
button.Opacity = enabled ? 0.3 : 0;
Expand All @@ -157,8 +171,10 @@ private void HighlightElement(System.Windows.Controls.Image element, bool highli
{
if (Properties.Settings.Default.IsDebugEnabled)
{
element.Opacity = highlight ? 0.8 : 0.3;
Application.Current.Dispatcher.Invoke(() =>
{
element.Opacity = highlight ? 0.8 : 0.3;
});
}
}

}
8 changes: 4 additions & 4 deletions VirtualComPortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ internal class VirtualComPortManager
{
public Task<string> CheckInstalledPortsAsync()
{
return ExecuteCommandAsync("C:\\Program Files (x86)\\com0com\\setupc.exe", $"list");
return ExecuteCommandAsync("thirdparty programs\\com0com\\setupc.exe", $"list");
}

public Task<string> InstallComPort()
{
return ExecuteCommandAsync("C:\\Program Files (x86)\\com0com\\setupc.exe", $"install PortName=COM3 PortName=COM23");
return ExecuteCommandAsync("thirdparty programs\\com0com\\setupc.exe", $"install PortName=COM3 PortName=COM23");
}

public Task<string> UninstallVirtualPorts()
{
return ExecuteCommandAsync("C:\\Program Files (x86)\\com0com\\setupc.exe", $"uninstall");
return ExecuteCommandAsync("thirdparty programs\\com0com\\setupc.exe", $"uninstall");
}

private async Task<string> ExecuteCommandAsync(string command, string arguments)
Expand All @@ -30,7 +30,7 @@ private async Task<string> ExecuteCommandAsync(string command, string arguments)
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
WorkingDirectory = "C:\\Program Files (x86)\\com0com"
WorkingDirectory = "thirdparty programs\\com0com"
};

var outputBuilder = new StringBuilder();
Expand Down
24 changes: 24 additions & 0 deletions WpfMaiTouchEmulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Update="thirdparty programs\com0com\com0com.cat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\com0com.inf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\com0com.sys">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\ReadMe.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\setup.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\setupc.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\setupg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="thirdparty programs\com0com\uninstall.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading

0 comments on commit b9315a5

Please sign in to comment.