void CheckPointListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { ItemData *data = (ItemData *)lpDrawItemStruct->itemData; if (data == NULL || data == (ItemData *)-1) { return; } CDC *dc = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rectItem(lpDrawItemStruct->rcItem); dc->FillSolidRect(rectItem, RGB(255, 255, 255)); rectItem.DeflateRect(32, 0, 32, 0); int index = lpDrawItemStruct->itemID; CFont *oldFont = dc->SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_BIG)); dc->SetBkMode(TRANSPARENT); int x = rectItem.right - 32 - 4; int y = rectItem.top + (rectItem.Height() - 32) / 2; if (imageList_ != NULL && data->state != -1) { imageList_->Draw(dc, data->state, CPoint(x, y), ILD_NORMAL); } dc->SetTextColor(RGB(0,0,0)); if (imageList_ != NULL && data->icon != -1) { imageList_->Draw(dc, data->icon, CPoint(rectItem.left + 10, y), ILD_NORMAL); } CRect rectText(rectItem); rectText.left = rectItem.left + 32 + spacing_; dc->DrawText(data->text, rectText, DT_SINGLELINE | DT_VCENTER); dc->SelectObject(oldFont); dc->Draw3dRect(CRect(rectText.left, rectItem.bottom - 1, rectItem.right, rectItem.bottom), RGB(221,221,221), RGB(221,221,221)); }
void TaskListView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC *dc = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rectItem(lpDrawItemStruct->rcItem); dc->FillSolidRect(rectItem, RGB(248, 248, 248)); TaskItem *item = (TaskItem *)lpDrawItemStruct->itemData; if (item == NULL || item == (TaskItem *)-1) { return; } CFont *font = GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL); CFont *oldFont = dc->SelectObject(font); dc->SetTextColor(RGB(0, 0, 0)); dc->DrawText(item->name, rectItem, DT_SINGLELINE | DT_VCENTER); int left = 0, right = rectItem.right; CSize textSize = dc->GetTextExtent(item->name); left += textSize.cx + 4; if (item->status == STATUS_PROCESSING) { CString processing; processing.LoadString(IDS_PROCESSING); dc->DrawText(processing, rectItem, DT_SINGLELINE | DT_VCENTER | DT_RIGHT); textSize = dc->GetTextExtent(processing); right -= textSize.cx + 4; } else if (item->status == STATUS_COMPLETED) { } else if (item->status == STATUS_ERROR) { } dc->SelectObject(oldFont); if (left < right) { int centerY = (rectItem.top + rectItem.bottom) / 2; CPen *oldPen = dc->SelectObject(&dotPen_); dc->MoveTo(left, centerY); dc->LineTo(right, centerY); dc->SelectObject(oldPen); } }
BOOL CColListCtrl::CreateComboBox( int nItem ) { if( m_nComboBoxColumn < 0 || nItem < 0 ) return FALSE; // Create if( !m_comboBox.GetSafeHwnd() ) { CRect rectItem( 0, 0, 35, 136 ); GetSubItemRect( nItem, m_nComboBoxColumn, LVIR_BOUNDS, rectItem ); CRect rect( 0, 0, rectItem.Width(), rectItem.Height()+120 ); if( !m_comboBox.Create( WS_CHILD | CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | CBS_HASSTRINGS, rect, this, IDC_COLLISTCTRL_COMBOBOX ) ) return FALSE; HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); if (hFont == NULL) hFont = (HFONT)GetStockObject(ANSI_VAR_FONT); m_comboBox.SendMessage(WM_SETFONT, (WPARAM)hFont); } // Add Strings if( nItem >= 0 && nItem < m_aptrItemStrings.GetSize() ) { CStringArray * pastr = (CStringArray *) m_aptrItemStrings.ElementAt(nItem); if( NULL != pastr && pastr->GetSize() > 0 ) { m_comboBox.ResetContent(); for( int k=0; k<pastr->GetSize(); k++ ) m_comboBox.AddString( pastr->ElementAt(k) ); m_comboBox.SelectString( 0, GetItemText(nItem,m_nComboBoxColumn) ); return TRUE; } } return FALSE; }
void CMyPropertySheet::OnNMCustomDraw(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLVCUSTOMDRAW pLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR); CRect rectRow, rectList; m_wndList.GetWindowRect(&rectList); ScreenToClient(&rectList); m_wndList.GetItemRect(0, &rectRow, LVIR_BOUNDS); int iItemHeight = rectRow.Height(); int iItemTop = rectRow.top ; ::SelectObject(pLVCD->nmcd.hdc, m_ftList); switch (pLVCD->nmcd.dwDrawStage) { case CDDS_PREPAINT: *pResult = CDRF_NOTIFYITEMDRAW; break; case CDDS_ITEMPREPAINT: *pResult = CDRF_NOTIFYSUBITEMDRAW; break; case (CDDS_ITEMPREPAINT | CDDS_SUBITEM): { int iCol = pLVCD->iSubItem ; int iRow = (int)pLVCD->nmcd.dwItemSpec; CRect rectItem(pLVCD->nmcd.rc), rectIcon; //计算每个子项的矩形 rectItem.top = iItemTop + iRow * iItemHeight; rectItem.bottom = rectItem.top + iItemHeight; rectItem.left +=3; rectItem.right -=3; if (iRow == 0) rectItem.top +=3; CDC *pDC = CDC::FromHandle(pLVCD->nmcd.hdc); LOGFONT lf; ::ZeroMemory(&lf, sizeof(lf)); pDC->GetCurrentFont()->GetLogFont(&lf); //获得第图标所在的矩形 m_wndList.GetSubItemRect(iRow,0, LVIR_ICON, rectIcon); const COLORREF clrBlack = RGB(0,0,0); const COLORREF clrWhite = RGB(255,255,255); if ((pLVCD->nmcd.uItemState & (CDIS_FOCUS | CDIS_SELECTED)) == (CDIS_FOCUS | CDIS_SELECTED)) { pDC->FillSolidRect(&rectItem, m_clrTextBkSele); pDC->SetTextColor(clrWhite); pDC->TextOut(rectItem.left + rectIcon.Width() + 8, (iRow == 0?(rectItem.top - 3):rectItem.top) + (iItemHeight - abs(lf.lfHeight))/2, m_wndList.GetItemText(iRow, iCol), (int)_tcslen(m_wndList.GetItemText(iRow, iCol))); ::DrawIconEx(*pDC,rectIcon.left, rectIcon.top + (iItemHeight - 16) / 2,m_imgList.ExtractIcon(iRow),16,16,NULL,NULL,DI_NORMAL); pDC->SetTextColor(clrBlack); DrawGradientLine(pDC,m_clrSeprator,CPoint(rectItem.left, rectItem.bottom-1), CPoint(rectItem.right, rectItem.bottom-1)); } else { pDC->FillSolidRect(&rectItem, clrWhite); pDC->TextOut(rectItem.left + rectIcon.Width() + 8, (iRow == 0?(rectItem.top - 3):rectItem.top) + (iItemHeight - abs(lf.lfHeight))/2, m_wndList.GetItemText(iRow, iCol), (int)_tcslen(m_wndList.GetItemText(iRow, iCol))); ::DrawIconEx(*pDC,rectIcon.left, rectIcon.top + (iItemHeight - 16) / 2, m_imgList.ExtractIcon(iRow),16,16,NULL,NULL,DI_NORMAL); DrawGradientLine(pDC,m_clrSeprator,CPoint(rectItem.left, rectItem.bottom-1), CPoint(rectItem.right, rectItem.bottom-1)); } *pResult = CDRF_SKIPDEFAULT; break; } default: *pResult = CDRF_SKIPDEFAULT; break; } }
void COXGridHeader::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) { if (m_UxTheme.IsUxThemeLoaded()) { HTHEME hTheme = m_UxTheme.GetWindowTheme(m_hWnd); if (hTheme != NULL) { // Draw the item background int iState = HIS_NORMAL; if (lpDrawItemStruct->itemState == ODS_SELECTED) iState = HIS_PRESSED; else { POINT ptCursor; ::GetCursorPos(&ptCursor); ScreenToClient(&ptCursor); CRect rectItem(lpDrawItemStruct->rcItem); if (rectItem.PtInRect(ptCursor)) iState = HIS_HOT; } m_UxTheme.DrawThemeBackground(hTheme, lpDrawItemStruct->hDC, HP_HEADERITEM, iState, &lpDrawItemStruct->rcItem, NULL); BOOL bDrawArrow; if (m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol) bDrawArrow = TRUE; else bDrawArrow = FALSE; // Get the column text and format TCHAR buf[256]; HD_ITEM hditem; hditem.mask = HDI_TEXT | HDI_FORMAT; hditem.pszText = buf; hditem.cchTextMax = 255; GetItem( lpDrawItemStruct->itemID, &hditem ); RECT rectText = lpDrawItemStruct->rcItem; rectText.left += 9; rectText.right -= 9; // Determine format for drawing column label UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS ; UINT uArrowFormat = DT_SINGLELINE | DT_VCENTER; if( hditem.fmt & HDF_CENTER) { uFormat |= DT_CENTER; uArrowFormat |= DT_RIGHT; if (bDrawArrow) rectText.right -= 12; } else if( hditem.fmt & HDF_RIGHT) { uFormat |= DT_RIGHT; uArrowFormat |= DT_LEFT; if (bDrawArrow) rectText.left += 12; } else { uFormat |= DT_LEFT; uArrowFormat |= DT_RIGHT; if (bDrawArrow) rectText.right -= 12; } m_UxTheme.DrawThemeText(hTheme, lpDrawItemStruct->hDC, HP_HEADERITEM, HIS_NORMAL, buf, -1, uFormat, 0, &rectText); // Draw the Sort arrow if (bDrawArrow) { CDC dc; dc.Attach(lpDrawItemStruct->hDC); int nSavedDC = dc.SaveDC(); CFont fontMarlett; fontMarlett.CreatePointFont(120, _T("Marlett")); dc.SelectObject(&fontMarlett); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(128, 128, 128)); CRect rectArrow = lpDrawItemStruct->rcItem; rectArrow.DeflateRect(5, 0, 5, 0); if (m_nSortOrder == 1) dc.DrawText(_T("5"), -1, &rectArrow, uArrowFormat); else dc.DrawText(_T("6"), -1, &rectArrow, uArrowFormat); // Restore dc dc.RestoreDC(nSavedDC); // Detach the dc before returning dc.Detach(); } return; } } CDC dc; dc.Attach( lpDrawItemStruct->hDC ); // Get the column rect CRect rcLabel( lpDrawItemStruct->rcItem ); // Save DC int nSavedDC = dc.SaveDC(); // Set clipping region to limit drawing within column CRgn rgn; rgn.CreateRectRgnIndirect( &rcLabel ); dc.SelectObject( &rgn ); rgn.DeleteObject(); // Draw the background CBrush brush(::GetSysColor(COLOR_3DFACE)); dc.FillRect(rcLabel,&brush); // Labels are offset by a certain amount // This offset is related to the width of a space character int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2; // Get the column text and format TCHAR buf[256]; HD_ITEM hditem; hditem.mask = HDI_TEXT | HDI_FORMAT; hditem.pszText = buf; hditem.cchTextMax = 255; GetItem( lpDrawItemStruct->itemID, &hditem ); // Determine format for drawing column label UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ; if( hditem.fmt & HDF_CENTER) uFormat |= DT_CENTER; else if( hditem.fmt & HDF_RIGHT) uFormat |= DT_RIGHT; else uFormat |= DT_LEFT; // Adjust the rect if the mouse button is pressed on it if( lpDrawItemStruct->itemState == ODS_SELECTED ) { rcLabel.left++; rcLabel.top += 2; rcLabel.right++; } // Adjust the rect further if Sort arrow is to be displayed if( lpDrawItemStruct->itemID == (UINT)m_nSortCol ) { rcLabel.right -= 3 * offset; } rcLabel.left += offset; rcLabel.right -= offset; // Draw column label if( rcLabel.left < rcLabel.right ) dc.DrawText(buf,-1,rcLabel, uFormat); // Draw the Sort arrow if( m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol ) { CRect rcIcon( lpDrawItemStruct->rcItem ); // Set up pens to use for drawing the triangle CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT)); CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW)); CPen *pOldPen = dc.SelectObject( &penLight ); if( m_nSortOrder==1 ) { // Draw triangle pointing upwards dc.MoveTo( rcIcon.right - 2*offset, offset-1); dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset ); dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset ); dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 ); dc.SelectObject( &penShadow ); dc.LineTo( rcIcon.right - 2*offset, offset-2); } else { // Draw triangle pointing downwords dc.MoveTo( rcIcon.right - 3*offset/2, offset-1); dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 ); dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset ); dc.SelectObject( &penShadow ); dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 ); dc.LineTo( rcIcon.right - 3*offset/2, offset -1); } // Restore the pen dc.SelectObject( pOldPen ); } // Restore dc dc.RestoreDC( nSavedDC ); // Detach the dc before returning dc.Detach(); }
void CSwingCheckBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); CRect rectItem(lpDIS->rcItem); CRect rectCheck(rectItem); rectCheck.right = rectCheck.left + 12; rectCheck.bottom = rectCheck.top + 12; CPoint TopLeft(rectCheck.left, rectCheck.top); CPoint BottomRight(rectCheck.right, rectCheck.bottom); CPoint TopRight(rectCheck.right, rectCheck.top); CPoint BottomLeft(rectCheck.left, rectCheck.bottom); // TODO: Add your code to draw the specified item pDC->SelectObject(&nInactiveBrush); pDC->SelectStockObject(NULL_PEN); pDC->Rectangle(rectItem); pDC->SelectObject(&nDarkBorder); pDC->MoveTo(TopLeft); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft); pDC->LineTo(BottomLeft); pDC->MoveTo(BottomLeft.x, BottomLeft.y - 1); pDC->LineTo(BottomRight.x, BottomRight.y - 1); pDC->MoveTo(BottomRight.x - 1, BottomRight.y); pDC->LineTo(TopRight.x - 1, TopRight.y); pDC->SelectObject(&nWhiteBorder); pDC->MoveTo(BottomLeft); pDC->LineTo(BottomRight); pDC->MoveTo(BottomRight); pDC->LineTo(TopRight); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(TopRight.x - 1, TopRight.y + 1); pDC->MoveTo(TopLeft.x + 1, TopLeft.y + 1); pDC->LineTo(BottomLeft.x + 1, BottomLeft.y - 1); pDC->SelectStockObject(DEFAULT_GUI_FONT); pDC->TextOut(16, 0, m_strCaption); if (m_Checked) { pDC->SelectObject(&nCheck); pDC->MoveTo(2, 3); pDC->LineTo(3, 8); pDC->MoveTo(3, 9); pDC->LineTo(9, 3); } if (lpDIS->itemState & ODS_FOCUS) { pDC->SelectObject(&nSelectedBorder); pDC->SelectStockObject(NULL_BRUSH); int xlen = pDC->GetTextExtent(m_strCaption).cx; pDC->Rectangle(15, 0, 13 + xlen + 3, 12); } }
//============================================================================= void CXListBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) //============================================================================= { COLORREF oldtextcolor, oldbackgroundcolor; CDC* pDC = CDC::FromHandle(lpDIS->hDC); pDC->GetCharWidth((UINT) ' ', (UINT) ' ', &m_nSpaceWidth); pDC->GetCharWidth((UINT) 'c', (UINT) 'c', &m_nAveCharWidth); for (int i = 0; i < MAXTABSTOPS; i++) m_nTabStopPositions[i] = (i+1) * m_nAveCharWidth * m_nTabPosition; // draw focus rectangle when no items in listbox if (lpDIS->itemID == (UINT)-1) { if (lpDIS->itemAction & ODA_FOCUS) pDC->DrawFocusRect(&lpDIS->rcItem); return; } else { int selChange = lpDIS->itemAction & ODA_SELECT; int focusChange = lpDIS->itemAction & ODA_FOCUS; int drawEntire = lpDIS->itemAction & ODA_DRAWENTIRE; if (selChange || drawEntire) { BOOL sel = lpDIS->itemState & ODS_SELECTED; int nLen = CListBox::GetTextLen(lpDIS->itemID); if (nLen != LB_ERR) { TCHAR *buf = new TCHAR [nLen + 16]; ASSERT(buf); if (buf && (GetTextWithColor(lpDIS->itemID, buf) != LB_ERR)) { CRect rectItem(lpDIS->rcItem); CSize size; if (m_bLineNumbers) { // draw gutter & line no. UINT index = GetTopIndex(); UINT n = rectItem.top / rectItem.Height(); index += n; //TRACE("index=%d\n", index); CString strLineNo = _T(""); for (int i = 0; i < m_nGutterWidth; i++) strLineNo += _T('9'); if (strLineNo.IsEmpty()) strLineNo = _T('9'); size = pDC->GetTextExtent(strLineNo); strLineNo = _T(""); strLineNo.Format(_T("%d"), index+1); rectItem.right = rectItem.left + size.cx + 6; pDC->SetBkColor(m_ColorGutter); pDC->SetTextColor(m_ColorLineNo); // fill the gutter with the gutter color the fast way pDC->ExtTextOut(0, 0, ETO_OPAQUE, &rectItem, NULL, 0, NULL); rectItem.left += 2; rectItem.right -= 2; pDC->DrawText(strLineNo, &rectItem, DT_RIGHT); // restore drawing rect rectItem.left = rectItem.right + 2; rectItem.right = lpDIS->rcItem.right; } // set text color from first character in string - // NOTE: 1 was added to color index to avoid asserts by CString int itext = int (buf[0] - 1); // set background color from second character in string - // NOTE: 1 was added to color index to avoid asserts by CString int iback = int (buf[1] - 1); buf[0] = _T(' '); buf[1] = _T(' '); COLORREF textcolor = sel ? m_ColorHighlightText : ColorTable[itext]; oldtextcolor = pDC->SetTextColor(textcolor); COLORREF backgroundcolor = sel ? m_ColorHighlight : ColorTable[iback]; oldbackgroundcolor = pDC->SetBkColor(backgroundcolor); // fill the rectangle with the background color the fast way pDC->ExtTextOut(0, 0, ETO_OPAQUE, &rectItem, NULL, 0, NULL); pDC->TabbedTextOut(rectItem.left+2, rectItem.top, &buf[2], (int)_tcslen(&buf[2]), MAXTABSTOPS, (LPINT)m_nTabStopPositions, 0); size = pDC->GetOutputTextExtent(&buf[2]); int nScrollBarWidth = ::GetSystemMetrics(SM_CXVSCROLL); size.cx += nScrollBarWidth; // in case of vertical scrollbar int cxExtent = (size.cx > m_cxExtent) ? size.cx : m_cxExtent; if (cxExtent > m_cxExtent) { m_cxExtent = cxExtent; SetHorizontalExtent(m_cxExtent+(m_cxExtent/32)); } } if (buf) delete [] buf; } } if (focusChange || (drawEntire && (lpDIS->itemState & ODS_FOCUS))) pDC->DrawFocusRect(&lpDIS->rcItem); } }
bool Plugin::render(QGraphicsView *graphicsView, QGraphicsItem *parent) { qDebug() << "Painting the Scenario"; m_itemGroup = new QGraphicsItemGroup(); while (!m_drawStack.isEmpty()) { const Plugin::Command *cmd = m_drawStack.front(); m_drawStack.pop_front(); QStringList tokList = cmd->values().split(':', QString::SkipEmptyParts); bool ret = true; // return value switch (cmd->drawCommand()) { case Plugin::Command::Pen: ret = setCurPen(tokList); break; // added brackets to delimit the variables scope // thats not necessary on case Pen. case Plugin::Command::Rect: { QGraphicsRectItem *rect = rectItem(tokList); if (rect) m_itemGroup->addToGroup(rect); else ret = false; } break; case Plugin::Command::Line: { QGraphicsLineItem *line = lineItem(tokList); if (line) m_itemGroup->addToGroup(line); else ret = false; } break; case Plugin::Command::Ellipse: { QGraphicsEllipseItem *ellipse = ellipseItem(tokList); if (ellipse) m_itemGroup->addToGroup(ellipse); else ret = false; } break; } if (!ret) { delete m_itemGroup; // force to delete the group return false; } } if (parent) m_itemGroup->setParentItem(parent); m_itemGroup->setPos(m_point); graphicsView->scene()->addItem(m_itemGroup); return true; }