mrDarker
2025-06-06 4597db5a8e60149028e87d57692d61b97c456350
SourceCode/Bond/Servo/JobSlotGrid.cpp
@@ -229,9 +229,22 @@
    CRect rect;
    GetClientRect(&rect);
    if (m_nCols == 0 || m_nRows == 0) {
        return;
    }
    // 计算格子尺寸
    int nCellWidth = rect.Width() / m_nCols;
    int nCellHeight = rect.Height() / m_nRows;
    // 字体设置
    CFont* pOldFont = pDC->SelectObject(&m_fontText);
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(RGB(0, 0, 0));
    // 定义颜色常量
    constexpr COLORREF COLOR_HOVER = RGB(200, 230, 255);
    constexpr COLORREF COLOR_CLICK = RGB(0, 120, 215);
    for (int i = 0; i < m_nRows; ++i) {
        for (int j = 0; j < m_nCols; ++j) {
@@ -241,29 +254,39 @@
            bool bIsHover = (m_ptHover.x == j && m_ptHover.y == i);
            bool bIsClicking = bIsHover && m_bLButtonDown;
            // 选择颜色
            COLORREF fillColor;
            if (bIsClicking) {
                fillColor = RGB(0, 120, 215);   // 鼠标按下色
            }
            else if (bIsHover) {
                fillColor = RGB(200, 230, 255); // 悬停高亮
            }
            else {
                fillColor = m_vSlotStatus[i][j] ? m_colorHasJob : m_colorNoJob;
            // 选择填充颜色
            COLORREF fillColor = m_vSlotStatus[i][j] ? m_colorHasJob : m_colorNoJob;
            if (IsSlotClickable(i, j)) {
                if (bIsClicking)
                    fillColor = COLOR_CLICK;
                else if (bIsHover)
                    fillColor = COLOR_HOVER;
            }
            // 画背景
            CBrush brush(fillColor);
            pDC->FillRect(&cellRect, &brush);
            // 绘制背景(高效替代 CBrush)
            pDC->FillSolidRect(&cellRect, fillColor);
            // 边框
            // 绘制边框
            pDC->DrawEdge(&cellRect, EDGE_SUNKEN, BF_RECT);
            // 文本
            pDC->SetBkMode(TRANSPARENT);
            pDC->SetTextColor(RGB(0, 0, 0));
            pDC->DrawText(m_vSlotText[i][j], &cellRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
            // 获取文字(安全)
            CString strText;
            if (i < m_vSlotText.size() && j < m_vSlotText[i].size()) {
                strText = m_vSlotText[i][j];
            }
            if (!strText.IsEmpty()) {
                // 先计算文字高度(支持换行)
                CRect calcRect = cellRect;
                pDC->DrawText(strText, &calcRect, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX | DT_CALCRECT);
                // 重新设定居中绘制区域
                CRect textRect = cellRect;
                textRect.top += (cellRect.Height() - calcRect.Height()) / 2;
                // 实际绘制文字
                pDC->DrawText(strText, &textRect, DT_CENTER | DT_WORDBREAK | DT_NOPREFIX);
            }
        }
    }