| | |
| | | m_crBkgnd = RGB(255,255,255); |
| | | m_pHighItem = nullptr; |
| | | m_hWndTooltip = nullptr; |
| | | m_slotBarSize = 0; |
| | | } |
| | | |
| | | CServoGraph::~CServoGraph() |
| | |
| | | |
| | | case WM_LBUTTONDOWN: |
| | | return pServoGraph->OnLButtonDown(wParam, lParam); |
| | | |
| | | case WM_SIZE: |
| | | return pServoGraph->OnSize(wParam, lParam); |
| | | |
| | | case WM_GETDLGCODE: |
| | | return DLGC_WANTALLKEYS; |
| | |
| | | return ::DefWindowProc(m_hWnd, WM_LBUTTONDOWN, wParam, lParam); |
| | | } |
| | | |
| | | /* |
| | | * WM_SIZE |
| | | */ |
| | | LRESULT CServoGraph::OnSize(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | return ::DefWindowProc(m_hWnd, WM_SIZE, wParam, lParam); |
| | | } |
| | | |
| | | /////////////////////////////// |
| | | // WM_PAINT |
| | | LRESULT CServoGraph::OnPaint(WPARAM wParam, LPARAM lParam) |
| | |
| | | // 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | 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 |
| | |
| | | graphics.DrawImage(&bitmap, item.x, item.y); |
| | | graphics.ResetTransform(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CServoGraph::SetIndicateBoxData(int id, void* pData) |
| | | { |
| | | INDICATEBOX* pib = GetIndicateBox(id); |
| | | if (pib != nullptr) { |
| | | pib->m_pData = pData; |
| | | } |
| | | } |
| | | |
| | | void* CServoGraph::GetIndicateBoxData(int id) |
| | | { |
| | | INDICATEBOX* pib = GetIndicateBox(id); |
| | | if (pib != nullptr) { |
| | | return pib->m_pData; |
| | | } |
| | | |
| | | return nullptr; |
| | | } |
| | | |
| | | void CServoGraph::Invalidata() |
| | | { |
| | | ::InvalidateRect(m_hWnd, NULL, TRUE); |
| | | } |