Skip to content

Commit

Permalink
Add ability to add a custom border or rainbow border to the surroundi…
Browse files Browse the repository at this point in the history
…ng touch sensor input area
  • Loading branch information
Leapward-Koex committed Nov 9, 2024
1 parent a01cdd6 commit 3a8d0e5
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 64 deletions.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<setting name="IsRingButtonEmulationEnabled" serializeAs="String">
<value>True</value>
</setting>
<setting name="BorderSetting" serializeAs="String">
<value>0</value>
</setting>
<setting name="BorderColour" serializeAs="String">
<value />
</setting>
</WpfMaiTouchEmulator.Properties.Settings>
</userSettings>
</configuration>
Binary file added Assets/conicalGradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 24 additions & 16 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Closing="MainWindow_Closing"
Title="MainWindow" Height="384" Width="500" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
<StackPanel VerticalAlignment="Top">
Title="MainWindow" Height="400" Width="587" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
<StackPanel Margin="0,0,0,0">
<Menu Width="Auto" Height="20">
<MenuItem Header="{Binding LbMenuCategoryHelp}" d:Header="_Help">
<MenuItem x:Name="instructionsLabel" Header="{Binding LbMenuItemSetup}" HorizontalAlignment="Left" Width="220" Click="instructionsLabel_Click"/>
</MenuItem>
</Menu>
<Grid Background="Transparent" Height="317" VerticalAlignment="Top" >
<Grid Background="Transparent" >
<Button x:Name="ConnectToPortButton" Content="{Binding LbConnectToPort}" d:Content="Connect to port" HorizontalAlignment="Left" Margin="10,95,0,0" VerticalAlignment="Top" Click="ConnectToPortButton_Click" Width="130" />
<TextBox x:Name="RecievedLogBox"
IsReadOnly="True"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
AcceptsTab="True"
TextWrapping="Wrap" Margin="376,34,0,219" HorizontalAlignment="Left" Width="88" />
IsReadOnly="True"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
AcceptsTab="True"
TextWrapping="Wrap" Margin="376,34,0,0" HorizontalAlignment="Left" Width="88" Height="80" VerticalAlignment="Top" />
<TextBox x:Name="SentLogBox"
IsReadOnly="True"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
AcceptsTab="True"
TextWrapping="Wrap" Margin="376,121,0,129" HorizontalAlignment="Left" Width="88" />
IsReadOnly="True"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
AcceptsReturn="True"
AcceptsTab="True"
TextWrapping="Wrap" Margin="480,34,0,0" HorizontalAlignment="Left" Width="88" Height="80" VerticalAlignment="Top" />
<Label x:Name="label" Content="{Binding LbRecievedData}" d:Content="Recieved Data" HorizontalAlignment="Left" Margin="376,8,0,0" VerticalAlignment="Top" Width="88"/>
<Label x:Name="label_Copy" Content="{Binding LbSentData}" d:Content="Sent Data" HorizontalAlignment="Left" Margin="376,95,0,0" VerticalAlignment="Top" Width="88"/>
<Label x:Name="label_Copy" Content="{Binding LbSentData}" d:Content="Sent Data" HorizontalAlignment="Left" Margin="480,8,0,0" VerticalAlignment="Top" Width="88"/>
<Label x:Name="label_Copy1" Content="{Binding LbButtonState}" d:Content="Button state" HorizontalAlignment="Left" Margin="238,56,0,0" VerticalAlignment="Top" Width="88"/>
<Label x:Name="buttonStateValue" Content="0" HorizontalAlignment="Left" Margin="238,82,0,0" VerticalAlignment="Top" RenderTransformOrigin="3.566,1.468" FontSize="10"/>
<CheckBox x:Name="debugMode" Content="{Binding LbDebugMode}" d:Content="Debug mode" HorizontalAlignment="Left" Margin="10,213,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=IsDebugEnabled}" Click="debugMode_Click" Cursor="" Focusable="False" ToolTip="Show the touchpad with translucency and show inputs highlighted" Width="224"/>
Expand All @@ -47,6 +47,14 @@
DisplayMemberPath="NativeName"
SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"/>
<Label x:Name="languageLabel" Content="{Binding LbLanguageDropdown}" d:Content="Language" HorizontalAlignment="Left" Margin="10,155,0,0" VerticalAlignment="Top" Width="126"/>
<Label x:Name="borderSettingLabel" Content="{Binding LbBorderSettings}" d:Content="Border Settings" HorizontalAlignment="Left" Margin="238,155,0,0" VerticalAlignment="Top" Width="126"/>
<StackPanel Margin="238,185,0,0" HorizontalAlignment="Left" Width="200" Height="91" VerticalAlignment="Top">
<RadioButton x:Name="rbBorderDisabled" Content="{Binding LbBorderDisabled}" d:Content="Disabled" GroupName="ColorOptions" Checked="RadioButton1_Checked"/>
<RadioButton x:Name="rbBorderSolidColour" Content="{Binding LbBorderSolid}" d:Content="Solid Colour (#AARRGGBB)" GroupName="ColorOptions" Checked="RadioButton2_Checked"/>
<TextBox x:Name="txtBorderHexColor" Text="{Binding Path=BorderColour}" IsEnabled="False" Margin="10,10,0,10" Width="127" Height="25" TextChanged="txtBorderHexColor_TextChanged"/>

<RadioButton Name="rbBorderRainbow" Content="{Binding LbBorderRainbow}" d:Content="Rainbow" GroupName="ColorOptions" Checked="RadioButton3_Checked"/>
</StackPanel>

</Grid>
</StackPanel>
Expand Down
75 changes: 68 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace WpfMaiTouchEmulator;

public enum BorderSetting
{
Disabled,
Solid,
Rainbow
}

public partial class MainWindow : Window
{
private readonly MaiTouchSensorButtonStateManager buttonState;
private readonly MaiTouchComConnector connector;
private readonly VirtualComPortManager comPortManager;
private TouchPanel _touchPanel;
private TouchPanel? _touchPanel;

public MainWindow()
{
Expand All @@ -20,9 +27,12 @@ public MainWindow()
IsAutomaticPortConnectingEnabled = Properties.Settings.Default.IsAutomaticPortConnectingEnabled,
IsAutomaticPositioningEnabled = Properties.Settings.Default.IsAutomaticPositioningEnabled,
IsExitWithSinmaiEnabled = Properties.Settings.Default.IsExitWithSinmaiEnabled,
IsRingButtonEmulationEnabled = Properties.Settings.Default.IsRingButtonEmulationEnabled
IsRingButtonEmulationEnabled = Properties.Settings.Default.IsRingButtonEmulationEnabled,
BorderColour = Properties.Settings.Default.BorderColour,
};

LoadBorderRadioButtonSetting();

Title = "Mai Touch Emulator";
buttonState = new MaiTouchSensorButtonStateManager(buttonStateValue);
connector = new MaiTouchComConnector(buttonState, (MainWindowViewModel)DataContext);
Expand Down Expand Up @@ -65,14 +75,16 @@ public MainWindow()


Loaded += (s, e) => {
var dataContext = (MainWindowViewModel)DataContext;

Logger.Info("Main window loaded, creating touch panel");
_touchPanel = new TouchPanel();
_touchPanel.onTouch = (value) => { buttonState.PressButton(value); };
_touchPanel.onRelease = (value) => { buttonState.ReleaseButton(value); };
_touchPanel.onInitialReposition = () => { WindowState = WindowState.Minimized; };
_touchPanel.SetBorderMode((BorderSetting)Properties.Settings.Default.BorderSetting, dataContext.BorderColour);
_touchPanel.Show();

var dataContext = (MainWindowViewModel)DataContext;
_touchPanel.DataContext = dataContext;

_touchPanel.SetDebugMode(dataContext.IsDebugEnabled);
Expand All @@ -91,7 +103,7 @@ private async void MainWindow_Closing(object? sender, System.ComponentModel.Canc
{
e.Cancel = true;
await connector.Disconnect();
_touchPanel.Close();
_touchPanel?.Close();
Closing -= MainWindow_Closing;
e.Cancel = false;
Application.Current.Shutdown();
Expand Down Expand Up @@ -153,7 +165,7 @@ private async void AutomaticTouchPanelPositioningLoop()
{
if (dataContext.IsAutomaticPositioningEnabled)
{
_touchPanel.PositionTouchPanel();
_touchPanel?.PositionTouchPanel();
}

await Task.Delay(1000);
Expand Down Expand Up @@ -186,7 +198,7 @@ private void debugMode_Click(object sender, RoutedEventArgs e)
dataContext.IsDebugEnabled = !enabled;
Properties.Settings.Default.IsDebugEnabled = dataContext.IsDebugEnabled;
Properties.Settings.Default.Save();
_touchPanel.SetDebugMode(dataContext.IsDebugEnabled);
_touchPanel?.SetDebugMode(dataContext.IsDebugEnabled);
}

private void automaticTouchPanelPositioning_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -249,6 +261,55 @@ private void emulateRingButtons_Click(object sender, RoutedEventArgs e)
dataContext.IsRingButtonEmulationEnabled = !enabled;
Properties.Settings.Default.IsRingButtonEmulationEnabled = dataContext.IsRingButtonEmulationEnabled;
Properties.Settings.Default.Save();
_touchPanel.SetEmulateRingButton(dataContext.IsRingButtonEmulationEnabled);
_touchPanel?.SetEmulateRingButton(dataContext.IsRingButtonEmulationEnabled);
}

private void LoadBorderRadioButtonSetting()
{
rbBorderDisabled.IsChecked = Properties.Settings.Default.BorderSetting == (int)BorderSetting.Disabled;
txtBorderHexColor.IsEnabled = Properties.Settings.Default.BorderSetting == (int)BorderSetting.Solid;
rbBorderSolidColour.IsChecked = Properties.Settings.Default.BorderSetting == (int)BorderSetting.Solid;
rbBorderRainbow.IsChecked = Properties.Settings.Default.BorderSetting == (int)BorderSetting.Rainbow;
}

private void RadioButton1_Checked(object sender, RoutedEventArgs e)
{
txtBorderHexColor.IsEnabled = false;
Properties.Settings.Default.BorderSetting = (int)BorderSetting.Disabled;
Properties.Settings.Default.Save();

_touchPanel?.SetBorderMode(BorderSetting.Disabled, "");
}

private void RadioButton2_Checked(object sender, RoutedEventArgs e)
{
txtBorderHexColor.IsEnabled = true;
Properties.Settings.Default.BorderSetting = (int)BorderSetting.Solid;

Properties.Settings.Default.Save();

_touchPanel?.SetBorderMode(BorderSetting.Solid, Properties.Settings.Default.BorderColour);
}

private void RadioButton3_Checked(object sender, RoutedEventArgs e)
{
txtBorderHexColor.IsEnabled = false;
Properties.Settings.Default.BorderSetting = (int)BorderSetting.Rainbow;

Properties.Settings.Default.Save();

_touchPanel?.SetBorderMode(BorderSetting.Rainbow, "");
}

private void txtBorderHexColor_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
var textWithoutHash = txtBorderHexColor.Text.TrimStart('#') ?? "";
if (textWithoutHash.Length == 6 || textWithoutHash.Length == 8)
{
var textWithHash = "#" + textWithoutHash;
Properties.Settings.Default.BorderColour = textWithHash;
Properties.Settings.Default.Save();
_touchPanel?.SetBorderMode(BorderSetting.Solid, textWithHash);
}
}
}
35 changes: 34 additions & 1 deletion MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ public string LbLanguageDropdown
{
get; set;
}
public string LbBorderSettings
{
get; set;
}
public string LbBorderDisabled
{
get; set;
}
public string LbBorderSolid
{
get; set;
}
public string LbBorderRainbow
{
get; set;
}
public string LbListComPorts
{
get; set;
Expand Down Expand Up @@ -190,6 +206,7 @@ public string? LbEmulateRingButtonsTT
private bool _isExitWithSinmaiEnabled;
private CultureInfo _selectedLanguage;
private bool _isRingButtonEmulationEnabled;
private string _borderColour;
private readonly ResourceManager resourceManager;
private readonly CultureInfo cultureInfo;

Expand Down Expand Up @@ -267,7 +284,17 @@ public bool IsRingButtonEmulationEnabled
OnPropertyChanged();
}
}


public string BorderColour
{
get => _borderColour;
set
{
_borderColour = value;
OnPropertyChanged();
}
}


public CultureInfo SelectedLanguage
{
Expand Down Expand Up @@ -306,6 +333,12 @@ private void UpdateLocalizedResources(ResourceManager resourceManager)
LbEmulateRingButtons = resourceManager.GetString("lbEmulateRingButtons");
LbInstallComPort = resourceManager.GetString("lbInstallComPort");
LbLanguageDropdown = resourceManager.GetString("lbLanguageDropdown");

LbBorderSettings = resourceManager.GetString("LbBorderSettings");
LbBorderDisabled = resourceManager.GetString("LbBorderDisabled");
LbBorderSolid = resourceManager.GetString("LbBorderSolid");
LbBorderRainbow = resourceManager.GetString("LbBorderRainbow");

LbListComPorts = resourceManager.GetString("lbListComPorts");
LbReceivedData = resourceManager.GetString("lbReceivedData");
LbRecievedData = resourceManager.GetString("lbRecievedData");
Expand Down
24 changes: 24 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@
<Setting Name="IsRingButtonEmulationEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="BorderSetting" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="BorderColour" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
36 changes: 36 additions & 0 deletions Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Resources/Strings.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@
<data name="lbAutoSensorPositioningTT" xml:space="preserve">
<value>Sinmai.exeの上に正しい位置にタッチセンサーウィンドウを自動的に移動しようとする</value>
</data>
<data name="LbBorderDisabled" xml:space="preserve">
<value>無効</value>
</data>
<data name="LbBorderRainbow" xml:space="preserve">
<value>レインボー</value>
</data>
<data name="LbBorderSettings" xml:space="preserve">
<value>境界線設定</value>
</data>
<data name="LbBorderSolid" xml:space="preserve">
<value>単色(#AARRGGBB)</value>
</data>
<data name="lbButtonState" xml:space="preserve">
<value>ボタン状態</value>
</data>
Expand Down
Loading

0 comments on commit 3a8d0e5

Please sign in to comment.