superstar_v2/PrimaryFormParts/PrimaryForm.ToggleLight.cs
2025-08-06 10:47:43 +08:00

314 lines
15 KiB
C#

using System.Drawing;
using System.IO;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace DualScreenDemo
{
public partial class PrimaryForm : Form
{
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;
private int OnOffState;
private PictureBox pictureBoxToggleLight;
private PictureBox Brightness1;
private PictureBox Brightness2;
private void InitializeButtonsForPictureBoxToggleLight()
{
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")),
null);
btnTurnOn.Click += (sender, e) =>
{
if (OnOffState == 1)
{
SendCommandThroughSerialPort("a2 dc a4");
Console.WriteLine("light off");
OnOffState = 0;
}
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen && OnOffState!=1)
{
byte[] commandBytes = new byte[] { 0xA2, 0xDB, 0xA4 };
Console.WriteLine("light on");
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
OnOffState = 1;
}
else
{
MessageBox.Show("Serial port is not open. Cannot send track correction command.");
}
};
//btnTurnOff = new Button { Text = "" };
//ConfigureButton(btnTurnOff, 753, 411, 122, 62,
// resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl,
// (sender, e) => SendCommandThroughSerialPort("a2 dc a4"));
btnBright = new Button{ Text = "" };
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")),
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.");
}
};
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")),
(sender, e) => SendCommandThroughSerialPort("a2 d7 a4"));
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")),
null);
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")),
(sender, e) => SendCommandThroughSerialPort("a2 75 a4"));
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")),
(sender, e) => SendCommandThroughSerialPort("a2 d6 a4"));
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")),
(sender, e) => SendCommandThroughSerialPort("a2 d8 a4"));
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")),
(sender, e) => SendCommandThroughSerialPort("a2 fb a4"));
btnStageLight = new Button{ Text = "" };
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")),
(sender, e) => SendCommandThroughSerialPort("a2 fa a4"));
btnShelfLight = new Button{ Text = "" };
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")),
(sender, e) => SendCommandThroughSerialPort("a2 f9 a4"));
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")),
(sender, e) => SendCommandThroughSerialPort("a2 f8 a4"));
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);
btnBrightnessUp1 = new Button{ Text = "" };
ConfigureTransButton(btnBrightnessUp1, 1, 1, 116, 40, null);
btnBrightnessUp1.MouseDown += (sender, e) =>
{
lightControlTimer.Tag = "a2 d9 a4";
lightControlTimer.Start();
};
btnBrightnessUp1.MouseUp += (sender, e) =>
{
lightControlTimer.Stop();
};
btnBrightnessDown1 = new Button{ Text = "" };
ConfigureTransButton(btnBrightnessDown1, 1, 100, 116, 42, null);
btnBrightnessDown1.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 da a4"; lightControlTimer.Start(); };
btnBrightnessDown1.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
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);
btnBrightnessUp2 = new Button{ Text = "" };
ConfigureTransButton(btnBrightnessUp2, 1, 1, 116, 42, null);
btnBrightnessUp2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f6 a4"; lightControlTimer.Start(); };
btnBrightnessUp2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
btnBrightnessDown2 = new Button{ Text = "" };
ConfigureTransButton(btnBrightnessDown2, 1, 100, 116, 42, null);
btnBrightnessDown2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f7 a4"; lightControlTimer.Start(); };
btnBrightnessDown2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
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);
}
private void ToggleLightButton_Click(object sender, EventArgs e)
{
//SetHotSongButtonsVisibility(false);
//SetNewSongButtonsVisibility(false);
//SetSingerSearchButtonsVisibility(false);
//SetSongSearchButtonsVisibility(false);
if (!pictureBoxToggleLight.Visible)
{
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);
}
else
{
CloseUI(pictureBoxToggleLight);
}
if (pictureBoxQRCode != null)
{
pictureBoxQRCode.Visible = false;
//closeQRCodeButton.Visible = false;
}
}
private void SetPictureBoxToggleLightAndButtonsVisibility(bool isVisible)
{
pictureBoxToggleLight.Visible = isVisible;
btnTurnOn.Visible = isVisible;
//btnTurnOff.Visible = isVisible;
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)
{
pictureBoxToggleLight.BringToFront();
btnTurnOn.BringToFront();
//btnTurnOff.BringToFront();
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();
}
}
}
}