Added Peripherals Panel to main window (buttons have no function yet... coming soon)

This commit is contained in:
IceStormNG
2023-07-23 11:57:44 +02:00
parent c1900e75ec
commit 18384bbddc
4 changed files with 441 additions and 213 deletions

View File

@@ -6,6 +6,8 @@ using GHelper.Gpu;
using GHelper.Helpers;
using GHelper.Input;
using GHelper.Mode;
using GHelper.Peripherals;
using GHelper.Peripherals.Mouse;
using GHelper.UI;
using System.Diagnostics;
using System.Timers;
@@ -71,6 +73,7 @@ namespace GHelper
labelKeyboard.Text = Properties.Strings.LaptopKeyboard;
labelMatrix.Text = Properties.Strings.AnimeMatrix;
labelBatteryTitle.Text = Properties.Strings.BatteryChargeLimit;
labelPeripherals.Text = Properties.Strings.Peripherals;
checkMatrix.Text = Properties.Strings.TurnOffOnBattery;
checkStartup.Text = Properties.Strings.RunOnStartup;
@@ -182,6 +185,10 @@ namespace GHelper
labelBattery.MouseLeave += PanelBattery_MouseLeave;
labelBatteryTitle.MouseLeave += PanelBattery_MouseLeave;
buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
buttonPeripheral3.Click += ButtonPeripheral_Click;
labelModel.Text = AppConfig.GetModelShort() + (ProcessHelper.IsUserAdministrator() ? "." : "");
TopMost = AppConfig.Is("topmost");
@@ -816,6 +823,7 @@ namespace GHelper
gpuTemp = $": {HardwareControl.gpuTemp}°C";
}
PeripheralsProvider.RefreshBatteryForAllDevices();
Program.settingsForm.BeginInvoke(delegate
{
@@ -825,6 +833,7 @@ namespace GHelper
labelMidFan.Text = "Mid " + HardwareControl.midFan;
if (!batteryMouseOver) labelBattery.Text = battery;
VisualizePeripherals();
});
string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
@@ -1056,6 +1065,66 @@ namespace GHelper
}
public void VisualizePeripherals()
{
if (!PeripheralsProvider.IsAnyPeripheralConnect())
{
panelPeripherals.Visible = false;
return;
}
Button[] buttons = new Button[] { buttonPeripheral1, buttonPeripheral2, buttonPeripheral3 };
//we only support 4 devces for now. Who has more than 4 mice connected to the same PC anyways....
List<IPeripheral> lp = PeripheralsProvider.AllPeripherals();
for (int i = 0; i < lp.Count && i < buttons.Length; ++i)
{
IPeripheral m = lp.ElementAt(i);
Button b = buttons[i];
if (m.IsDeviceReady)
{
b.Text = m.GetDisplayName() + "\n" + m.Battery + "%"
+ (m.Charging ? "(" + Properties.Strings.Charging + ")" : "");
}
else
{
//Mouse is either not connected or in standby
b.Text = m.GetDisplayName() + "\n(" + Properties.Strings.NotConnected + ")";
}
switch (m.DeviceType())
{
case PeripheralType.Mouse:
b.Image = ControlHelper.TintImage(Properties.Resources.icons8_maus_32, b.ForeColor);
break;
case PeripheralType.Keyboard:
b.Image = ControlHelper.TintImage(Properties.Resources.icons8_keyboard_32, b.ForeColor);
break;
}
b.Visible = true;
}
for (int i = lp.Count; i < buttons.Length; ++i)
{
buttons[i].Visible = false;
}
panelPeripherals.Visible = true;
}
private void ButtonPeripheral_Click(object? sender, EventArgs e)
{
int index = 0;
if (sender == buttonPeripheral2) index = 1;
if (sender == buttonPeripheral3) index = 2;
//TODO: Open Configuration Panel
}
}