//////////////////// // Draw the item void CListviewItem::Draw(SDL_Surface *bmpDest, const SDL_Rect &r) { // Save the clipping rect ScopedSurfaceClip clip(bmpDest, r); CItemStyle *style = getCurrentStyle(); // Background style->cBackground.Draw(bmpDest, r.x, r.y, r.w, r.h); // Draw the subitems std::list<CListviewSubitem *>::iterator subit = tSubitems.begin(); std::vector<CListviewColumn *>::const_iterator colit = cParent->getColumns().begin(); int cur_x = r.x + style->cBorder.getLeftW(); for ( ; subit != tSubitems.end() && colit != cParent->getColumns().end(); colit++, subit++) { (*subit)->Draw(bmpDest, MakeRect(cur_x, r.y + style->cBorder.getTopW(), (*colit)->getWidth(), r.h - style->cBorder.getTopW() - style->cBorder.getBottomW())); cur_x += (*colit)->getWidth(); } // If no subitems, draw the text if (tSubitems.size() == 0) { DrawItemText(bmpDest, r); } // Border style->cBorder.Draw(bmpDest, r.x, r.y, r.w, r.h); }
void CTreeListColumnDragWnd::DrawItemListText( CDC* pDC, CRect rcBkgnd, CTreeListItem* pItem, int iCol ) { // draw text on list CRect rcText; rcText = rcBkgnd; rcText.DeflateRect( 2, 0, 3, 0 ); rcBkgnd.bottom = rcBkgnd.bottom - 1; DrawItemText( pDC, rcBkgnd, rcText, pItem, iCol ); }
void CMenuElementUI::DoPaint(HDC hDC, const RECT& rcPaint) { if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; CMenuElementUI::DrawItemBk(hDC, m_rcItem); DrawItemText(hDC, m_rcItem); for (int i = 0; i < GetCount(); ++i) { if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) == NULL) GetItemAt(i)->DoPaint(hDC, rcPaint); } }
void SymbolList::ActionList::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const { const bool isCurrent = IsCurrent(n); if (isCurrent) dc.SetTextForeground(m_hlTextColor); else dc.SetTextForeground(m_textColor); const aItem& ai = m_items[n]; const vector<unsigned int>& hl = ai.hlChars; const wxString& name = *ai.action; // Draw action name DrawItemText(dc, rect, name, hl, isCurrent); }
///////////////// // Draw the text subitem void CTextSubitem::Draw(SDL_Surface *bmpDest, const SDL_Rect &r) { CItemStyle *style = getCurrentStyle(); // Background if (bUseCustomStyle) style->cBackground.Draw(bmpDest, r.x, r.y, r.w, r.h); // Image DrawItemText(bmpDest, r); // Border if (bUseCustomStyle) style->cBorder.Draw(bmpDest, r.x, r.y, r.w, r.h); }
void GotoFileList::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const { const bool isCurrent = IsCurrent(n); if (isCurrent) dc.SetTextForeground(m_hlTextColor); else dc.SetTextForeground(m_textColor); const FileEntry& file_entry = *m_items[n].file_entry; // m_project_root wxFileName displayPath(file_entry.path); displayPath.MakeRelativeTo(this->m_project_root); //displayPath.SetFullName(file_entry.name); const wxString& name = displayPath.GetFullPath(); const int path_size = displayPath.GetPath().size() + 1; const std::vector<unsigned int>& hl = m_items[n].hlChars; std::vector<unsigned int> offsets(hl.size()); for(unsigned int i = 0; i < hl.size(); i++) { offsets[i] = hl[i] + path_size; } /*// Calc extension width static const wxString ext = wxT(".. "); dc.SetFont(m_font); int w, h; dc.GetTextExtent(ext, &w, &h); const unsigned int extwidth = w; // See if we have to resize the action name to fit // note that this is not 100% correct as bold chars take up a bit more space. unsigned int len = name.length(); dc.GetTextExtent(name, &w, &h); if (w > (int)rightBorder) { do { name.resize(--len); dc.GetTextExtent(name, &w, &h); } while (len > 0 && w + extwidth > (int)rightBorder); name += ext; }*/ // Draw action name DrawItemText(dc, rect, name, offsets, isCurrent); }
void CMenuElementUI::DoPaint(HDC hDC, const RECT& rcPaint) { if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; if(m_bDrawLine) { RECT rcLine = { m_rcItem.left + m_rcLinePadding.left, m_rcItem.top + m_cxyFixed.cy/2, m_rcItem.right - m_rcLinePadding.right, m_rcItem.top + m_cxyFixed.cy/2 }; CRenderEngine::DrawLine(hDC, rcLine, 1, m_dwLineColor); } else { CMenuElementUI::DrawItemBk(hDC, m_rcItem); DrawItemText(hDC, m_rcItem); DrawItemIcon(hDC, m_rcItem); DrawItemExpland(hDC, m_rcItem); for (int i = 0; i < GetCount(); ++i) { if (GetItemAt(i)->GetInterface(_T("MenuElement")) == NULL) GetItemAt(i)->DoPaint(hDC, rcPaint); } } }
void CCustomMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item if(!lpDrawItemStruct->itemData) { return; } //To check if the drawing menu item that owned by this menu. if (!IsDrawingItem(this, lpDrawItemStruct->hwndItem)) { return; } CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); MenuItemInfo_t* itemInfo=(MenuItemInfo_t*)(lpDrawItemStruct->itemData); UINT itemTypeOrId = itemInfo->m_miiItemId; CString itemText = itemInfo->m_miiItemText; UINT iconIndex = itemInfo->m_miiIconIndex; UINT itemState = lpDrawItemStruct->itemState; CRect rect = lpDrawItemStruct->rcItem; pDC->SetBkMode(TRANSPARENT); switch(itemTypeOrId) { case TOPMOST_MENU://顶层菜单 DrawTopMenuItem(pDC, rect, (itemState & ODS_SELECTED) || (itemState & 0x0040)); //这里也不要用(m_state& ODS_SELECTED)|| // (lpDrawItemStruct->itemAction & (ODA_SELECT))); //(m_state&0x0040)也要加上,否则鼠标移入没反应 //0x0040 ==ODS_HOTLIGHT DrawItemText(pDC, itemText, rect, FALSE, FALSE, TRUE); break; case CHILD_MENU: DrawCommonMenuItem(pDC,rect,(itemState & ODS_SELECTED)||(itemState & 0x0040),FALSE); DrawItemText(pDC,itemText,rect,TRUE,FALSE,FALSE); DrawMenuIcon(pDC,rect,iconIndex + 1); break; case SEPARATOR_MENU: DrawSeparate(pDC, rect); break; default: //Common menu item. //||(lpDrawItemStruct->itemAction & (ODA_SELECT)) //这个不要加,加了之后会出现一直处于高亮显示 if(itemState & ODS_GRAYED) { DrawCommonMenuItem(pDC, rect, (itemState & ODS_SELECTED), TRUE); DrawItemText(pDC, itemText, rect, TRUE, TRUE, FALSE); } else { DrawCommonMenuItem(pDC, rect, (itemState & ODS_SELECTED), FALSE); DrawItemText(pDC, itemText, rect, TRUE, FALSE, FALSE); } if(itemState & ODS_CHECKED) DrawMenuIcon(pDC, rect, 0); //Use the first icon! else DrawMenuIcon(pDC, rect, iconIndex + 1); //DrawMenuTitle(pDC, rect, TEXT("华中科技大学")); break; } }
void FindCmdDlg::ActionList::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const { const bool isCurrent = IsCurrent(n); dc.SetTextForeground(isCurrent ? m_hlTextColor : m_textColor); const unsigned int ypos = rect.y + m_topMargen; unsigned int rightBorder = rect.GetRight(); const tmAction& action = *m_items[n].action; const vector<unsigned int>& hl = m_items[n].hlChars; wxString name = action.name; if (action.bundle) { name += wxT(" - "); name += action.bundle->name; } if ( !action.trigger.empty() ) { const wxString trig = action.trigger + wxT("\x21E5"); dc.SetFont(m_unifont); int trig_width, trig_height; dc.GetTextExtent(trig, &trig_width, &trig_height); // Draw a grey rounded rect as background for trigger const unsigned int bg_height = trig_height + 1; const unsigned int bg_width = trig_width + 10; const unsigned int bg_xpos = rect.GetWidth()-2-bg_width; const unsigned int bg_ypos = rect.y+ (int)((rect.GetHeight()-bg_height)/2.0); dc.SetPen(*wxLIGHT_GREY_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawRoundedRectangle(bg_xpos, bg_ypos, bg_width, bg_height, 2); // Draw the trigger text const wxColour prevColour = dc.GetTextForeground(); dc.SetTextForeground(*wxBLACK); dc.DrawText(trig, bg_xpos + 5, bg_ypos); dc.SetTextForeground(prevColour); rightBorder = bg_xpos; } else if (!action.key.shortcut.empty()) { const wxString& shortcut = action.key.shortcut; dc.SetFont(m_font); int accel_width, accel_height; dc.GetTextExtent(shortcut, &accel_width, &accel_height); const unsigned int xpos = rect.GetWidth()-2-accel_width; dc.DrawText(shortcut, xpos, ypos); rightBorder = xpos; } // Calc extension width static const wxString ext = wxT(".. "); dc.SetFont(m_font); int w, h; dc.GetTextExtent(ext, &w, &h); const unsigned int extwidth = w; // See if we have to resize the action name to fit // note that this is not 100% correct as bold chars take up a bit more space. unsigned int len = name.length(); dc.GetTextExtent(name, &w, &h); if (w > (int)rightBorder) { do { name.resize(--len); dc.GetTextExtent(name, &w, &h); } while (len > 0 && w + extwidth > rightBorder); name += ext; } // Draw action name DrawItemText(dc, rect, name, hl, isCurrent); }
//绘制图片 BOOL CxResLibImgList::OnItemPaint(LPNMLVCUSTOMDRAW lplvcd) { LONG x = 0; int nItem = ( int ) ( lplvcd->nmcd.dwItemSpec ); UINT nState = GetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED); RECT rcBound, rcIcon, rcLabel; GetItemRect(nItem, &rcBound, LVIR_BOUNDS); GetItemRect(nItem, &rcIcon, LVIR_ICON); GetItemRect(nItem, &rcLabel, LVIR_LABEL); UINT nSelCx = m_pImgSelected->GetHeight(); UINT nSelCy = m_pImgSelected->GetWidth(); rcBound.bottom = rcBound.top + nSelCy; rcLabel.bottom = rcBound.bottom; //调整 rcBound 尺寸 int nCyMinBound = CY_ICON_BOTTOM_SPACE + CY_ICON_LABEL_SPACE + CY_LABEL_TEXT; //int nReal = m_nImgCySpace; //if (nReal < nCyMinBound) //{ // rcBound.bottom -= (nCyMinBound - nReal); // if (rcLabel.bottom > rcBound.bottom) // rcLabel.bottom = rcBound.bottom; //} //右边界 //rcBound.right = rcBound.left + rcIcon.right - rcIcon.left // + (rcIcon.left - rcBound.left) * 2; //rcBound.left += 20; //rcBound.right -= 20; //rcBound.top += 10; //rcBound.bottom -= 10; //Icon区域 在 Bound区域 居中 x = ( ( rcBound.right - rcBound.left ) - m_nImgCx ) / 2; rcIcon.top = rcBound.top + 11; rcIcon.bottom = rcIcon.top + m_nImgCy; rcIcon.left = rcBound.left + x; rcIcon.right = rcIcon.left + m_nImgCx; //调整 rcLabel 位置和尺寸 int nIconLabelSpaceOffset = GetSpaceOfIconLabel(); int nLabelHeight = rcLabel.bottom - rcLabel.top; //调整 Icon 与 Label 之间的间距 rcLabel.top = rcIcon.bottom + nIconLabelSpaceOffset; //rcLabel.bottom = rcLabel.top + nLabelHeight; rcLabel.bottom = rcBound.bottom - 6; //调整Lable宽度 rcLabel.left = rcBound.left - 2; rcLabel.right = rcBound.right - 2; rcLabel.bottom+=2; //边界平行四边形点 Point BoundPoints[] = { Point( rcBound.left, rcBound.top ) //左上 , Point( rcBound.right, rcBound.top ) //右上 , Point( rcBound.left, rcBound.bottom ) //左下 }; //图标平行四边形点 Point IconPoints[] = { Point( rcIcon.left, rcIcon.top ) //左上 , Point( rcIcon.right, rcIcon.top ) //右上 , Point( rcIcon.left, rcIcon.bottom ) //左下 }; //绘制 if (nState & LVIS_FOCUSED) //有焦点 { if (nState & LVIS_SELECTED) //焦点 + 选中 { RectF rcBoundF( (float)rcBound.left, (float)rcBound.top , (float)(rcBound.right - rcBound.left) , (float)(rcBound.bottom - rcBound.top) ); if (m_pImgSelected != NULL) { m_pGraphics->DrawImage( m_pImgSelected, BoundPoints, 3 ); //DrawHighlight(m_pImgSelected, m_pGraphics, rcBoundF, 1.5f); } } //焦点 + 未选中 { RectF rcIconF( (float)rcIcon.left, (float)rcIcon.top , (float)(rcIcon.right - rcIcon.left), (float)(rcIcon.bottom - rcIcon.top) ); m_pGraphics->DrawImage( m_vImg[nItem], IconPoints, 3 ); //m_pGraphics->DrawImage( m_vImg[nItem], IconPoints, 3 ); //m_pGraphics->DrawImage( m_pImgFocused, BoundPoints, 3 ); ////DrawHighlight(m_vImg[nItem], m_pGraphics, rcIconF); } } else //没有焦点 { if (nState & LVIS_SELECTED) //无焦点 + 选中 { if (m_pImgSelected != NULL) { m_pGraphics->DrawImage( m_pImgSelected, BoundPoints, 3 ); } } //无焦点 + 未选中 { m_pGraphics->DrawImage( m_vImg[nItem], IconPoints, 3 ); } } //绘制文字 // if (m_nImgCx <= 16 || m_nImgCy <= 16 // || rcLabel.bottom - rcLabel.top < 16) // { // // } // else { DrawItemText(nItem, rcLabel); } return TRUE; }
void CTreeListCtrl::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClip, rcClient; dc.GetClipBox( &rcClip ); GetClientRect(&rcClient); // Set clip region to be same as that in paint DC CRgn rgn; rgn.CreateRectRgnIndirect( &rcClip ); dc.SelectClipRgn(&rgn); rgn.DeleteObject(); COLORREF m_wndColor = GetSysColor( COLOR_WINDOW ); dc.SetViewportOrg(m_nOffset, 0); dc.SetTextColor(m_wndColor); // First let the control do its default drawing. CWnd::DefWindowProc( WM_PAINT, (WPARAM)dc.m_hDC, 0 ); HTREEITEM hItem = GetFirstVisibleItem(); int n = GetVisibleCount(), m_nWidth; dc.FillSolidRect(GetColumnWidth(0),1,rcClient.Width(),rcClient.Height(),m_wndColor); CTreeListItem *pItem; // the most urgent thing is to erase the labels that were drawn by the tree while(hItem!=NULL && n>=0) { CRect rect; UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED; CRect m_labelRect; GetItemRect( hItem, &m_labelRect, TRUE ); GetItemRect( hItem, &rect, FALSE ); if (GetColumnsNum()>1) rect.left = min(m_labelRect.left, GetColumnWidth(0)); else rect.left = m_labelRect.left; rect.right = m_nColumnsWidth; dc.FillSolidRect(rect.left,rect.top,rect.Width(),rect.Height(),m_wndColor); hItem = GetNextVisibleItem( hItem ); n--; } // create the font CFont *pFontDC; CFont fontDC, boldFontDC; LOGFONT logfont; CFont *pFont = GetFont(); pFont->GetLogFont( &logfont ); fontDC.CreateFontIndirect( &logfont ); pFontDC = dc.SelectObject( &fontDC ); logfont.lfWeight = 700; boldFontDC.CreateFontIndirect( &logfont ); // and now let's get to the painting itself hItem = GetFirstVisibleItem(); n = GetVisibleCount(); while (hItem != NULL && n >= 0) { CRect rect; UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED; if ( !(GetItemState( hItem, selflag ) & selflag )) { dc.SetBkMode(TRANSPARENT); pItem = (CTreeListItem *)CTreeCtrl::GetItemData(hItem); CString sItem = ((pItem != NULL) ? pItem->GetItemText() : ""); CRect m_labelRect; GetItemRect( hItem, &m_labelRect, TRUE ); GetItemRect( hItem, &rect, FALSE ); if (GetColumnsNum()>1) rect.left = min(m_labelRect.left, GetColumnWidth(0)); else rect.left = m_labelRect.left; rect.right = m_nColumnsWidth; dc.SetBkColor( m_wndColor ); if (pItem != NULL) { dc.SetTextColor( pItem->m_Color ); if (pItem->m_Bold) { dc.SelectObject( &boldFontDC ); } } int imageIndex; int selectedImageIndex; GetItemImage(hItem,imageIndex,selectedImageIndex); int imageOffset = 0; if (imageIndex >= 0) { m_imageList->Draw(&dc,imageIndex,rect.TopLeft(),ILD_TRANSPARENT); imageOffset = 16; } DrawItemText(&dc, sItem, CRect(rect.left+2+imageOffset, rect.top, GetColumnWidth(0)-imageOffset, rect.bottom), GetColumnWidth(0)-rect.left-2-imageOffset, GetColumnAlign(0)); m_nWidth = 0; for (int i = 1;i < m_nColumns;i++) { CString subString = ((pItem != NULL) ? pItem->GetSubstring(*this,hItem,i) : ""); m_nWidth += GetColumnWidth(i-1); DrawItemText(&dc,subString,CRect(m_nWidth, rect.top, m_nWidth+GetColumnWidth(i), rect.bottom), GetColumnWidth(i), GetColumnAlign(i)); } dc.SetTextColor(::GetSysColor (COLOR_WINDOWTEXT )); if (pItem != NULL && pItem->m_Bold) { dc.SelectObject( &fontDC ); } } else { CRect m_labelRect; GetItemRect( hItem, &m_labelRect, TRUE ); GetItemRect( hItem, &rect, FALSE ); if (GetColumnsNum() > 1) rect.left = min(m_labelRect.left, GetColumnWidth(0)); else rect.left = m_labelRect.left; rect.right = m_nColumnsWidth; int imageIndex; int selectedImageIndex; GetItemImage(hItem,imageIndex,selectedImageIndex); int imageOffset = 0; if (selectedImageIndex >= 0) { m_imageList->Draw(&dc,selectedImageIndex,rect.TopLeft(),ILD_TRANSPARENT); imageOffset = 16; } // If the item is selected, paint the rectangle with the system color // COLOR_HIGHLIGHT COLORREF m_highlightColor = ::GetSysColor (COLOR_HIGHLIGHT); CBrush brush(m_highlightColor); CRect fillRect(rect); fillRect.left += imageOffset; dc.FillRect (fillRect, &brush); // draw a dotted focus rectangle dc.DrawFocusRect (rect); pItem = (CTreeListItem *)CTreeCtrl::GetItemData(hItem); CString sItem = ((pItem != NULL) ? pItem->GetItemText() : ""); dc.SetBkColor(m_highlightColor); dc.SetTextColor(::GetSysColor (COLOR_HIGHLIGHTTEXT)); if (pItem != NULL && pItem->m_Bold) { dc.SelectObject( &boldFontDC ); } //DrawItemText(&dc, sItem, CRect(rect.left+2, rect.top, GetColumnWidth(0), rect.bottom), GetColumnWidth(0)-rect.left-2, GetColumnAlign(0)); DrawItemText(&dc, sItem, CRect(rect.left+2+imageOffset, rect.top, GetColumnWidth(0)-imageOffset, rect.bottom), GetColumnWidth(0)-rect.left-2-imageOffset, GetColumnAlign(0)); m_nWidth = 0; for (int i = 1;i < m_nColumns;i++) { CString subString = ((pItem != NULL) ? pItem->GetSubstring(*this,hItem,i) : ""); m_nWidth += GetColumnWidth(i-1); DrawItemText(&dc,subString,CRect(m_nWidth, rect.top, m_nWidth+GetColumnWidth(i), rect.bottom), GetColumnWidth(i), GetColumnAlign(i)); } if (pItem != NULL && pItem->m_Bold) { dc.SelectObject( &fontDC ); } } hItem = GetNextVisibleItem( hItem ); n--; } dc.SelectObject( pFontDC ); }