From 351086486441b80cfe71550b43cbe1e4dc440f5d Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期一, 09 二月 2026 13:58:30 +0800
Subject: [PATCH] 1.状态图右侧数据,Slot不刷新,修复刷新逻辑。
---
SourceCode/Bond/Servo/ServoGraph.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 85 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/Servo/ServoGraph.cpp b/SourceCode/Bond/Servo/ServoGraph.cpp
index 8e037e1..735f2c4 100644
--- a/SourceCode/Bond/Servo/ServoGraph.cpp
+++ b/SourceCode/Bond/Servo/ServoGraph.cpp
@@ -21,6 +21,9 @@
m_crBkgnd = RGB(255,255,255);
m_pHighItem = nullptr;
m_hWndTooltip = nullptr;
+ m_slotBarSize = 0;
+ m_slotBarSize8 = 0;
+ m_slotBarSizeOther = 0;
}
CServoGraph::~CServoGraph()
@@ -361,6 +364,48 @@
// text
::DrawText(hMemDC, item.szText, static_cast<int>(strlen(item.szText)),
&rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+
+ // slot bar
+ if (item.slotBarPos != SlotBarPos::None && !item.slotColors.empty()) {
+ const int slotCount = static_cast<int>(item.slotColors.size());
+ const int gap = 1;
+ int slotSize = 4;
+ if (slotCount > 0) {
+ const int maxSize = (item.box1Width - gap * (slotCount - 1)) / slotCount;
+ if (slotCount == 8 && m_slotBarSize8 > 0) {
+ slotSize = m_slotBarSize8;
+ }
+ else if (slotCount != 8 && m_slotBarSizeOther > 0) {
+ slotSize = m_slotBarSizeOther;
+ }
+ else if (m_slotBarSize > 0) {
+ slotSize = m_slotBarSize;
+ }
+ else {
+ slotSize = maxSize;
+ }
+ if (slotSize < 2) slotSize = 2;
+ }
+ const int barWidth = slotCount * slotSize + gap * (slotCount - 1);
+ const int startX = item.x - barWidth / 2;
+ const int baseTop = (item.slotBarPos == SlotBarPos::Top)
+ ? (item.y - item.box1Width / 2 - slotSize - 2)
+ : (item.y + item.box1Width / 2 + 2);
+
+ HBRUSH hbrBorder = CreateSolidBrush(RGB(100, 100, 100));
+ for (int i = 0; i < slotCount; ++i) {
+ RECT rcSlot;
+ rcSlot.left = startX + i * (slotSize + gap);
+ rcSlot.top = baseTop;
+ rcSlot.right = rcSlot.left + slotSize;
+ rcSlot.bottom = rcSlot.top + slotSize;
+ HBRUSH hbrSlot = CreateSolidBrush(item.slotColors[i]);
+ ::FillRect(hMemDC, &rcSlot, hbrSlot);
+ ::FrameRect(hMemDC, &rcSlot, hbrBorder);
+ ::DeleteObject(hbrSlot);
+ }
+ ::DeleteObject(hbrBorder);
+ }
}
@@ -664,6 +709,40 @@
}
}
+void CServoGraph::SetIndicateBoxSlotBarPosition(int id, SlotBarPos pos)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->slotBarPos = pos;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+ }
+}
+
+void CServoGraph::SetIndicateBoxSlotColors(int id, const std::vector<COLORREF>& colors)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->slotColors = colors;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+ }
+}
+
+void CServoGraph::SetSlotBarSize(int size)
+{
+ if (size < 0) size = 0;
+ m_slotBarSize = size;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+}
+
+void CServoGraph::SetSlotBarSizeByCount(int size8, int sizeOther)
+{
+ if (size8 < 0) size8 = 0;
+ if (sizeOther < 0) sizeOther = 0;
+ m_slotBarSize8 = size8;
+ m_slotBarSizeOther = sizeOther;
+ InvalidateRect(m_hWnd, nullptr, TRUE);
+}
+
void CServoGraph::DrawImage(HDC hMemDC, IMAGE& item)
{
// 载入BMP
@@ -722,4 +801,9 @@
}
return nullptr;
-}
\ No newline at end of file
+}
+
+void CServoGraph::Invalidata()
+{
+ ::InvalidateRect(m_hWnd, NULL, TRUE);
+}
--
Gitblit v1.9.3