Skip to content

Commit

Permalink
added state graphic
Browse files Browse the repository at this point in the history
  • Loading branch information
fearthecowboy committed Apr 6, 2020
1 parent 557d69f commit c92e0a3
Show file tree
Hide file tree
Showing 14 changed files with 423 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file modified .vs/PushToTalk/v16/.suo
Binary file not shown.
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\Properties"
],
"SelectedNode": "\\SettingsForm.cs",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
20 changes: 20 additions & 0 deletions Properties/Resources.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/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="green" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="mic_off" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>mic_off.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand All @@ -130,4 +133,7 @@
<data name="on" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>on.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="red" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\red.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
15 changes: 15 additions & 0 deletions PushToTalk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="State.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="State.Designer.cs">
<DependentUpon>State.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="SettingsForm.resx">
<DependentUpon>SettingsForm.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -70,6 +76,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="State.resx">
<DependentUpon>State.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -112,6 +121,12 @@
<Version>1.10.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\red.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\green.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>$(ILMergeConsolePath) /out:ptt.exe PushToTalk.exe Gma.System.MouseKeyHook.dll NAudio.dll
Expand Down
Binary file added Resources/green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 49 additions & 1 deletion SettingsForm.Designer.cs

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

98 changes: 90 additions & 8 deletions SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ public partial class SettingsForm : Form, IDisposable
private WaveOut wave = new WaveOut();

private RegistryKey app = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FearTheCowboy").CreateSubKey("PushToTalk");
private MicState micState;
private bool loading = false;

public SettingsForm()
{
InitializeComponent();
micState = new MicState();

CreateTrayIcon();

Expand All @@ -71,18 +74,36 @@ public SettingsForm()
loop = Task.Run(worker);
keyText.Text = None;
mouseText.Text = None;
micState.LocationChanged += MicState_LocationChanged;
this.Load += SettingsForm_Load;
}

Task.Delay(1).ContinueWith((p) => Invoke(new Action(load)));

private void SettingsForm_Load(object sender, EventArgs e)
{
load();
}

private void MicState_LocationChanged(object sender, EventArgs e)
{
save();
}

private void save()
{
if( loading )
{
return;
}
app.SetValue("Key",keyText.Text, RegistryValueKind.String);
app.SetValue("Buttons",mouseText.Text, RegistryValueKind.String);
app.SetValue("Delay", (int)delay.Value, RegistryValueKind.DWord);
app.SetValue("CancelMouseEvents", cancelMouse.Checked ? 1 : 0, RegistryValueKind.DWord);
app.SetValue("ShowMicState", showMicState.Checked ? 1: 0, RegistryValueKind.DWord);
app.SetValue("Opacity", (int)opacity.Value, RegistryValueKind.DWord);
app.SetValue("MicStateX", (int)micState.Location.X, RegistryValueKind.DWord);
app.SetValue("MicStateY", (int)micState.Location.Y, RegistryValueKind.DWord);
app.SetValue("SettingsX", (int)Location.X, RegistryValueKind.DWord);
app.SetValue("SettingsY", (int)Location.Y, RegistryValueKind.DWord);
}

private T[] parse<T>( string value )
Expand All @@ -97,6 +118,7 @@ private T[] parse<T>( string value )

private void load()
{
loading = true;
keys.Clear();
foreach ( var each in parse<Keys>(app.GetValue("Key")?.ToString() ?? None) ) {
keys.Add(each);
Expand All @@ -114,15 +136,33 @@ private void load()
delay.Value = Convert.ToInt32(app.GetValue("Delay", 250));
cancelMouse.Checked = app.GetValue("CancelMouseEvents", 1) == (object)1;

if( keyText.Text == None && mouseText.Text == None)

SetDesktopLocation(Convert.ToInt32(app.GetValue("SettingsX", 250)), Convert.ToInt32(app.GetValue("SettingsY", 250)));


micState.SetDesktopLocation(Convert.ToInt32(app.GetValue("MicStateX", Screen.PrimaryScreen.WorkingArea.Width - 300)), Convert.ToInt32(app.GetValue("MicStateY", 25)));

var o = Convert.ToInt32(app.GetValue("Opacity", 50));
micState.Opacity = ((float)o) / 100;
int sms = Convert.ToInt32(app.GetValue("ShowMicState", 1));

showMicState.Checked = sms != 0;
opacity.Value = o;
update();

if (keyText.Text == None && mouseText.Text == None)
{
Show();
} else
}
else
{
Task.Delay(2).ContinueWith((p) => Invoke(new Action(() => Hide())));
Hide();
mouse = mouseText.Text == None ? State.None : State.Active;
key= keyText.Text == None ? State.None : State.Active;
key = keyText.Text == None ? State.None : State.Active;
}
loading = false;

}

private IAudioEndpointVolume volumeControl
Expand Down Expand Up @@ -221,13 +261,22 @@ private void CreateTrayIcon()
};
trayContext.Items.Add(exit);

notifier.Click += Notifier_Click;
notifier.MouseClick += Notifier_Click;
notifier.ContextMenuStrip = trayContext;
}

private void Notifier_Click(object sender, EventArgs e)
private void Notifier_Click(object sender, MouseEventArgs e)
{
this.Show();
if (e.Button == MouseButtons.Left)
{
if( this.Visible)
{
this.Hide();
} else
{
this.Show();
}
}
}

private void worker()
Expand Down Expand Up @@ -274,6 +323,7 @@ private void activate()
active = true;
notifier.Icon = Resources.mic_on;
MicrophoneMuted = false;
micState.on();
}
}

Expand All @@ -283,6 +333,7 @@ private void deactivate()
notifier.Icon = Resources.mic_off;
PlaySound(Properties.Resources.off);
MicrophoneMuted = true;
micState.off();
}

private void keyDown(object sender, KeyEventArgs e)
Expand Down Expand Up @@ -427,5 +478,36 @@ private void cancelMouse_CheckedChanged(object sender, EventArgs e)
{
save();
}

private void update()
{
if (showMicState.Checked)
{
micState.Show();
micState.SetDesktopLocation(Convert.ToInt32(app.GetValue("MicStateX", Screen.PrimaryScreen.WorkingArea.Width - 300)), Convert.ToInt32(app.GetValue("MicStateY", 25)));
}
else
{
micState.Hide();
}
micState.Opacity = ((double)opacity.Value) / 100;
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
update();
save();
}

private void opacity_ValueChanged(object sender, EventArgs e)
{
update();
save();
}

private void button1_Click(object sender, EventArgs e)
{
load();
}
}
}
Loading

0 comments on commit c92e0a3

Please sign in to comment.