SourceCode/Bond/Servo/ServoGraph.cpp
@@ -21,6 +21,7 @@
   m_crBkgnd = RGB(255,255,255);
   m_pHighItem = nullptr;
   m_hWndTooltip = nullptr;
   m_slotBarSize = 0;
}
CServoGraph::~CServoGraph()
@@ -361,6 +362,37 @@
      // 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;
            slotSize = (m_slotBarSize > 0) ? m_slotBarSize : 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 +696,31 @@
   }
}
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::DrawImage(HDC hMemDC, IMAGE& item)
{
   // 载入BMP