superstar_v2/PrimaryFormParts/PrimaryForm.ToggleLight.cs

314 lines
15 KiB
C#
Raw Normal View History

2025-08-06 10:47:43 +08:00
using System.Drawing;
2025-04-07 16:54:10 +08:00
using System.IO;
2025-08-06 10:47:43 +08:00
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
2025-04-07 16:54:10 +08:00
namespace DualScreenDemo
{
2025-08-06 10:47:43 +08:00
public partial class PrimaryForm : Form
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
private Button btnTurnOn;
private Button btnTurnOff;
private Button btnBright;
private Button btnRomantic;
private Button btnAuto;
private Button btnColorTuning;
private Button btnSoft;
private Button btnDynamic;
private Button btnDeskLamp;
private Button btnStageLight;
private Button btnShelfLight;
private Button btnWallLight;
private Button btnBrightnessUp1;
private Button btnBrightnessDown1;
private Button btnBrightnessUp2;
private Button btnBrightnessDown2;
2025-08-06 10:47:43 +08:00
private int OnOffState;
2025-04-07 16:54:10 +08:00
private PictureBox pictureBoxToggleLight;
2025-08-06 10:47:43 +08:00
private PictureBox Brightness1;
private PictureBox Brightness2;
2025-04-07 16:54:10 +08:00
private void InitializeButtonsForPictureBoxToggleLight()
{
2025-08-06 10:47:43 +08:00
btnTurnOn = new Button { Text = "" };
ConfigureButton(btnTurnOn, 29, 45, 250, 67,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_ON-OFF.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_ON-OFF.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_ON-OFF.png")),
2025-04-07 16:54:10 +08:00
null);
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnTurnOn.Click += (sender, e) =>
{
2025-08-06 10:47:43 +08:00
if (OnOffState == 1)
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
SendCommandThroughSerialPort("a2 dc a4");
Console.WriteLine("light off");
OnOffState = 0;
}
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen && OnOffState!=1)
{
2025-04-07 16:54:10 +08:00
byte[] commandBytes = new byte[] { 0xA2, 0xDB, 0xA4 };
2025-08-06 10:47:43 +08:00
Console.WriteLine("light on");
2025-04-07 16:54:10 +08:00
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
2025-08-06 10:47:43 +08:00
OnOffState = 1;
2025-04-07 16:54:10 +08:00
}
else
{
MessageBox.Show("Serial port is not open. Cannot send track correction command.");
}
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
};
2025-08-06 10:47:43 +08:00
//btnTurnOff = new Button { Text = "" };
//ConfigureButton(btnTurnOff, 753, 411, 122, 62,
// resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl,
// (sender, e) => SendCommandThroughSerialPort("a2 dc a4"));
2025-04-07 16:54:10 +08:00
btnBright = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnBright, 295, 45, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_明亮.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_明亮.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_明亮.png")),
2025-04-07 16:54:10 +08:00
null);
btnBright.Click += (sender, e) =>
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytes = new byte[] { 0xA2, 0xD5, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
}
else
{
MessageBox.Show("Serial port is not open. Cannot send track correction command.");
}
};
2025-08-06 10:47:43 +08:00
btnRomantic = new Button{ Text = "" };
ConfigureButton(btnRomantic, 430, 45, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_浪漫.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_浪漫.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_浪漫.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d7 a4"));
2025-08-06 10:47:43 +08:00
btnAuto = new Button{ Text = "" };
ConfigureButton(btnAuto, 430, 125, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_自動.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_自動.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_自動.png")),
2025-04-07 16:54:10 +08:00
null);
2025-08-06 10:47:43 +08:00
btnColorTuning = new Button{ Text = "" };
ConfigureButton(btnColorTuning, 430, 203, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_調色.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_調色.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_調色.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 75 a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
2025-08-06 10:47:43 +08:00
btnSoft = new Button{ Text = "" };
ConfigureButton(btnSoft, 295, 125, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_柔和.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_柔和.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_柔和.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d6 a4"));
2025-08-06 10:47:43 +08:00
btnDynamic = new Button{ Text = "" };
ConfigureButton(btnDynamic, 295, 203, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_動感.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_動感.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_動感.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d8 a4"));
2025-08-06 10:47:43 +08:00
btnDeskLamp = new Button{ Text = "" };
ConfigureButton(btnDeskLamp, 430, 283, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_桌燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_桌燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_桌燈.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 fb a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnStageLight = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnStageLight, 295, 283, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_舞台燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_舞台燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_舞台燈.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 fa a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnShelfLight = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnShelfLight, 163, 283, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_層板燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_層板燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_層板燈.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 f9 a4"));
2025-08-06 10:47:43 +08:00
btnWallLight = new Button{ Text = "" };
ConfigureButton(btnWallLight, 29, 283, 118, 65,
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_壁燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_壁燈.png")),
new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_壁燈.png")),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 f8 a4"));
2025-08-06 10:47:43 +08:00
Brightness1 = new PictureBox { };
Brightness1.BackgroundImage = new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_桌燈調光.png"));
Brightness1.BackgroundImageLayout = ImageLayout.Stretch;
Brightness1.Size = new Size(155, 172);
Brightness1.Location = new Point(38, 151);
2025-04-07 16:54:10 +08:00
btnBrightnessUp1 = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureTransButton(btnBrightnessUp1, 1, 1, 116, 40, null);
2025-04-07 16:54:10 +08:00
btnBrightnessUp1.MouseDown += (sender, e) =>
{
lightControlTimer.Tag = "a2 d9 a4";
lightControlTimer.Start();
};
btnBrightnessUp1.MouseUp += (sender, e) =>
{
lightControlTimer.Stop();
};
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessDown1 = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureTransButton(btnBrightnessDown1, 1, 100, 116, 42, null);
2025-04-07 16:54:10 +08:00
btnBrightnessDown1.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 da a4"; lightControlTimer.Start(); };
btnBrightnessDown1.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-06 10:47:43 +08:00
Brightness2 = new PictureBox { };
Brightness2.BackgroundImage = new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_層板調光.png"));
Brightness2.BackgroundImageLayout = ImageLayout.Stretch;
Brightness2.Size = new Size(155, 172);
Brightness2.Location = new Point(216, 151);
2025-04-07 16:54:10 +08:00
btnBrightnessUp2 = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureTransButton(btnBrightnessUp2, 1, 1, 116, 42, null);
2025-04-07 16:54:10 +08:00
btnBrightnessUp2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f6 a4"; lightControlTimer.Start(); };
btnBrightnessUp2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessDown2 = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureTransButton(btnBrightnessDown2, 1, 100, 116, 42, null);
2025-04-07 16:54:10 +08:00
btnBrightnessDown2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f7 a4"; lightControlTimer.Start(); };
btnBrightnessDown2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-06 10:47:43 +08:00
pictureBoxToggleLight.Controls.Add(btnTurnOn);
pictureBoxToggleLight.Controls.Add(btnBright);
pictureBoxToggleLight.Controls.Add(btnRomantic);
pictureBoxToggleLight.Controls.Add(btnAuto);
pictureBoxToggleLight.Controls.Add(btnColorTuning);
pictureBoxToggleLight.Controls.Add(btnSoft);
pictureBoxToggleLight.Controls.Add(btnDynamic);
pictureBoxToggleLight.Controls.Add(btnDeskLamp);
pictureBoxToggleLight.Controls.Add(btnStageLight);
pictureBoxToggleLight.Controls.Add(btnShelfLight);
pictureBoxToggleLight.Controls.Add(btnWallLight);
Brightness1.Controls.Add(btnBrightnessUp1);
Brightness1.Controls.Add(btnBrightnessDown1);
Brightness2.Controls.Add(btnBrightnessUp2);
Brightness2.Controls.Add(btnBrightnessDown2);
pictureBoxToggleLight.Controls.Add(Brightness1);
pictureBoxToggleLight.Controls.Add(Brightness2);
2025-04-07 16:54:10 +08:00
}
private void ToggleLightButton_Click(object sender, EventArgs e)
{
2025-08-06 10:47:43 +08:00
//SetHotSongButtonsVisibility(false);
//SetNewSongButtonsVisibility(false);
//SetSingerSearchButtonsVisibility(false);
//SetSongSearchButtonsVisibility(false);
2025-04-07 16:54:10 +08:00
if (!pictureBoxToggleLight.Visible)
{
2025-08-06 10:47:43 +08:00
pictureBoxToggleLight.Size = new Size(630, 379);
pictureBoxToggleLight.Location = new Point(570, 359);
ResizeAndPositionPictureBox(pictureBoxToggleLight, 570, 359, 570, 359);
pictureBoxToggleLight.BackgroundImage = new Bitmap(Path.Combine(Application.StartupPath, "themes\\superstar\\button\\3.介面\\燈光控制_完整介面.png"));
pictureBoxToggleLight.BackgroundImageLayout = ImageLayout.Stretch;
pictureBoxToggleLight.BringToFront();
SetUIVisible(pictureBoxToggleLight);
2025-04-07 16:54:10 +08:00
}
else
{
2025-08-06 10:47:43 +08:00
CloseUI(pictureBoxToggleLight);
2025-04-07 16:54:10 +08:00
}
2025-08-06 10:47:43 +08:00
if (pictureBoxQRCode != null)
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
pictureBoxQRCode.Visible = false;
//closeQRCodeButton.Visible = false;
2025-04-07 16:54:10 +08:00
}
}
private void SetPictureBoxToggleLightAndButtonsVisibility(bool isVisible)
{
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
pictureBoxToggleLight.Visible = isVisible;
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnTurnOn.Visible = isVisible;
2025-08-06 10:47:43 +08:00
//btnTurnOff.Visible = isVisible;
2025-04-07 16:54:10 +08:00
btnBright.Visible = isVisible;
btnRomantic.Visible = isVisible;
btnAuto.Visible = isVisible;
btnColorTuning.Visible = isVisible;
btnSoft.Visible = isVisible;
btnDynamic.Visible = isVisible;
btnDeskLamp.Visible = isVisible;
btnStageLight.Visible = isVisible;
btnShelfLight.Visible = isVisible;
btnWallLight.Visible = isVisible;
btnBrightnessUp1.Visible = isVisible;
btnBrightnessDown1.Visible = isVisible;
btnBrightnessUp2.Visible = isVisible;
btnBrightnessDown2.Visible = isVisible;
if (isVisible)
{
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
pictureBoxToggleLight.BringToFront();
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnTurnOn.BringToFront();
2025-08-06 10:47:43 +08:00
//btnTurnOff.BringToFront();
2025-04-07 16:54:10 +08:00
btnBright.BringToFront();
btnRomantic.BringToFront();
btnAuto.BringToFront();
btnColorTuning.BringToFront();
btnSoft.BringToFront();
btnDynamic.BringToFront();
btnDeskLamp.BringToFront();
btnStageLight.BringToFront();
btnShelfLight.BringToFront();
btnWallLight.BringToFront();
btnBrightnessUp1.BringToFront();
btnBrightnessDown1.BringToFront();
btnBrightnessUp2.BringToFront();
btnBrightnessDown2.BringToFront();
}
}
}
}