优化状态更新和图像处理流程,按照规范实现状态变更和UI更新
This commit is contained in:
@@ -113,9 +113,10 @@ namespace JoyD.Windows.CS.Toprie
|
||||
bool isDisconnected = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Disconnected;
|
||||
bool isReconnecting = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Reconnecting;
|
||||
bool isPaused = _isPaused; // 使用_isPaused标志判断暂停状态
|
||||
bool isPingFailed = !IsDevicePingable;
|
||||
|
||||
// 如果需要显示信息,创建InfoImage
|
||||
if (isDisconnected || isReconnecting || isPaused)
|
||||
if (isDisconnected || isReconnecting || isPaused || isPingFailed)
|
||||
{
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||
@@ -130,11 +131,25 @@ namespace JoyD.Windows.CS.Toprie
|
||||
string text = "";
|
||||
Color textColor = Color.White;
|
||||
|
||||
if (isDisconnected || isReconnecting)
|
||||
// 根据要求的优先级显示信息:先检查Ping状态和连接状态,最后检查暂停状态
|
||||
if (isPingFailed || isDisconnected || isReconnecting)
|
||||
{
|
||||
// 断开或重连状态
|
||||
text = isReconnecting ? "正在重连..." : "连接断开";
|
||||
textColor = isReconnecting ? Color.Yellow : Color.Red;
|
||||
// Ping不通或断开连接状态
|
||||
if (isReconnecting)
|
||||
{
|
||||
text = "正在重连...";
|
||||
textColor = Color.Yellow;
|
||||
}
|
||||
else if (isDisconnected)
|
||||
{
|
||||
text = "连接断开";
|
||||
textColor = Color.Red;
|
||||
}
|
||||
else if (isPingFailed)
|
||||
{
|
||||
text = "Ping不通";
|
||||
textColor = Color.Red;
|
||||
}
|
||||
}
|
||||
else if (isPaused)
|
||||
{
|
||||
@@ -142,10 +157,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
text = "暂停";
|
||||
textColor = Color.Red;
|
||||
}
|
||||
// 添加Ping状态信息
|
||||
string pingStatus = IsDevicePingable ? "Ping通" : "Ping不通";
|
||||
string pingText = $"设备{pingStatus}";
|
||||
Color pingColor = IsDevicePingable ? Color.Green : Color.Red;
|
||||
|
||||
// 绘制文本
|
||||
using (Font font = new Font("Arial", 48, FontStyle.Bold))
|
||||
@@ -154,22 +165,9 @@ namespace JoyD.Windows.CS.Toprie
|
||||
StringFormat format = new StringFormat();
|
||||
format.Alignment = StringAlignment.Center;
|
||||
|
||||
// 将主文本位置调整到上方
|
||||
// 将主文本居中显示
|
||||
g.DrawString(text, font, textBrush,
|
||||
new RectangleF(0, BUFFER_HEIGHT / 4, BUFFER_WIDTH, BUFFER_HEIGHT / 3),
|
||||
format);
|
||||
}
|
||||
|
||||
// 绘制Ping状态信息
|
||||
using (Font pingFont = new Font("Arial", 36, FontStyle.Regular))
|
||||
using (SolidBrush pingBrush = new SolidBrush(pingColor))
|
||||
{
|
||||
StringFormat format = new StringFormat();
|
||||
format.Alignment = StringAlignment.Center;
|
||||
|
||||
// 将Ping状态文本位置放在主文本下方
|
||||
g.DrawString(pingText, pingFont, pingBrush,
|
||||
new RectangleF(0, BUFFER_HEIGHT * 2 / 3, BUFFER_WIDTH, BUFFER_HEIGHT / 3),
|
||||
new RectangleF(0, BUFFER_HEIGHT / 3, BUFFER_WIDTH, BUFFER_HEIGHT / 3),
|
||||
format);
|
||||
}
|
||||
}
|
||||
@@ -630,12 +628,8 @@ namespace JoyD.Windows.CS.Toprie
|
||||
|
||||
try
|
||||
{
|
||||
// 连接状态检查 - 只在设备实际连接时处理图像
|
||||
if (_deviceManager.ConnectionStatus != ConnectionStatus.Connected)
|
||||
{
|
||||
Console.WriteLine("设备未连接,跳过图像更新");
|
||||
return;
|
||||
}
|
||||
// 移除连接状态检查,确保在任何状态下都能更新UI
|
||||
// 根据流程要求,需要在断开或Ping不通时也能显示相关信息
|
||||
|
||||
// 检查图像缓冲区是否有效
|
||||
if (_imageBuffer == null)
|
||||
@@ -868,6 +862,9 @@ namespace JoyD.Windows.CS.Toprie
|
||||
case ConnectionStatus.Connected:
|
||||
Console.WriteLine("设备已连接");
|
||||
|
||||
// 连接时调用更新Info
|
||||
UpdateInfo();
|
||||
|
||||
// 仅在首次连接时设置为热图模式,重连时保留之前的模式
|
||||
if (!_isReceivingImage) // 首次连接时_isReceivingImage为false
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user