コード例 #1
0
ファイル: MenuItem.cpp プロジェクト: guowei8412/upp-mirror
void MenuItemBase::PaintTopItem(Draw& w, int state) {
	Size sz = GetSize();
	if(GUI_GlobalStyle() >= GUISTYLE_XP) {
		bool opaque = InOpaqueBar();
		bool opaque2 = opaque || state;
		Color bg = SColorFace();
		if(opaque2)
			ChPaint(w, 0, 0, sz.cx, sz.cy, style->topitem[state]);
		else
		if(opaque)
			w.DrawRect(0, 0, sz.cx, sz.cy, bg);
		String text = GetText();
		Size isz = GetTextSize(text, StdFont());
		Color txt = opaque ? style->topitemtext[0] : GetLabelTextColor(this);
		Color hltxt = opaque2 ? style->topitemtext[state] : GetLabelTextColor(this);
		if(!opaque && state != 2) { // Fix issues when text color is not compatible with transparent background (e.g. Ubuntu Ambience)]
			Color c = state == 1 ? SColorHighlight() : bg;
			int g = Grayscale(c);
			bool dark = IsDark(c);
			if(abs(g - Grayscale(txt)) < 70)
				txt = dark ? White() : Black();
			if(abs(g - Grayscale(hltxt)) < 70)
				hltxt = dark ? White() : Black();
		}
		DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), state,
		             txt, hltxt);
	}
	else {
		w.DrawRect(sz, SColorFace);
		static const ColorF b0[] = { (ColorF)1, SColorLight, SColorLight, SColorShadow, SColorShadow, };
		static const ColorF b1[] = { (ColorF)1, SColorShadow, SColorShadow, SColorLight, SColorLight, };
		String text = GetText();
		Size isz = GetTextSize(text, StdFont());
		DrawMenuText(w, 6, (sz.cy - isz.cy) / 2, text, GetFont(), IsItemEnabled(), false,
		             SColorMenuText, SColorHighlightText);
		if(state)
			DrawBorder(w, 0, 0, sz.cx, sz.cy, state == 2 ? b1 : b0);
	}
}
コード例 #2
0
ファイル: coolmenu.cpp プロジェクト: pics860/callcenter
void CCoolMenu::OnDrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CRect rcItem, rcText;
	CString strText;
	int nIcon = -1;
	CDC dc;
	
	BOOL	bSelected	= lpDrawItemStruct->itemState & ODS_SELECTED;
	BOOL	bChecked	= lpDrawItemStruct->itemState & ODS_CHECKED;
	BOOL	bDisabled	= lpDrawItemStruct->itemState & ODS_GRAYED;
	BOOL	bKeyboard	= FALSE;
	BOOL	bEdge		= TRUE;
	
	dc.Attach( lpDrawItemStruct->hDC );
	
	if ( CWnd* pWnd = dc.GetWindow() )
	{
		CRect rcScreen( &lpDrawItemStruct->rcItem );
		CPoint ptCursor;
		
		GetCursorPos( &ptCursor );
		pWnd->ClientToScreen( &rcScreen );
		
		bKeyboard = ! rcScreen.PtInRect( ptCursor );
	}
	
	rcItem.CopyRect( &lpDrawItemStruct->rcItem );
	rcItem.OffsetRect( -rcItem.left, -rcItem.top );
	if ( m_hMsgHook != NULL ) rcItem.bottom += ( bEdge = m_bPrinted );
	
	rcText.CopyRect( &rcItem );
	rcText.left += 32;
	rcText.right -= 2;
	
	CDC* pDC = CoolInterface.GetBuffer( dc, rcItem.Size() );
	
	if ( m_bmWatermark.m_hObject != NULL )
	{
		DrawWatermark( pDC, &rcItem, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top );
	}
	else
	{
		pDC->FillSolidRect( rcItem.left, rcItem.top, 24, rcItem.Height(), CoolInterface.m_crMargin );
		pDC->FillSolidRect( rcItem.left + 24, rcItem.top, rcItem.Width() - 24, rcItem.Height(), CoolInterface.m_crBackNormal );
	}
	
	if ( m_pStrings.Lookup( lpDrawItemStruct->itemData, strText ) == FALSE )
	{
		int nMiddle = rcText.top + 1;
		
		pDC->FillSolidRect( rcText.left, nMiddle, rcText.Width() + 2, 1, CoolInterface.m_crDisabled );
		
		dc.BitBlt( lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top,
			rcItem.Width(), rcItem.Height(), pDC, 0, 0, SRCCOPY );
		dc.Detach();
		
		return;
	}
	
	if ( bSelected )
	{
		if ( ! bDisabled )
		{
			pDC->Draw3dRect( rcItem.left + 1, rcItem.top + 1,
				rcItem.Width() - 2, rcItem.Height() - 1 - bEdge,
				CoolInterface.m_crBorder, CoolInterface.m_crBorder );
			pDC->FillSolidRect( rcItem.left + 2, rcItem.top + 2,
				rcItem.Width() - 4, rcItem.Height() - 3 - bEdge,
				CoolInterface.m_crBackSel );
			
			pDC->SetBkColor( CoolInterface.m_crBackSel );
		}
		else if ( bKeyboard )
		{
			pDC->Draw3dRect( rcItem.left + 1, rcItem.top + 1,
				rcItem.Width() - 2, rcItem.Height() - 1 - bEdge,
				CoolInterface.m_crBorder, CoolInterface.m_crBorder );
			pDC->FillSolidRect( rcItem.left + 2, rcItem.top + 2,
				rcItem.Width() - 4, rcItem.Height() - 3 - bEdge,
				CoolInterface.m_crBackNormal );
			
			pDC->SetBkColor( CoolInterface.m_crBackNormal );
		}
	}
	else
	{
		pDC->SetBkColor( CoolInterface.m_crBackNormal );
	}
	
	if ( bChecked )
	{
		pDC->Draw3dRect( rcItem.left + 2, rcItem.top + 2, 20, rcItem.Height() - 3 - bEdge,
			CoolInterface.m_crBorder, CoolInterface.m_crBorder );
		pDC->FillSolidRect( rcItem.left + 3, rcItem.top + 3, 18, rcItem.Height() - 5 - bEdge,
			( bSelected && !bDisabled ) ? CoolInterface.m_crBackCheckSel : CoolInterface.m_crBackCheck );
	}
	
	nIcon = CoolInterface.ImageForID( (DWORD)lpDrawItemStruct->itemID );
	
	if ( bChecked && nIcon < 0 ) nIcon = m_nCheckIcon;
	
	if ( nIcon >= 0 )
	{
		CPoint pt( rcItem.left + 4, rcItem.top + 4 );
		
		if ( bDisabled )
		{
			ImageList_DrawEx( CoolInterface.m_pImages.m_hImageList, nIcon, pDC->GetSafeHdc(),
				pt.x, pt.y, 0, 0, CLR_NONE, CoolInterface.m_crDisabled, CM_DISABLEDBLEND );
		}
		else if ( bChecked )
		{
			CoolInterface.m_pImages.Draw( pDC, nIcon, pt, ILD_TRANSPARENT );
		}
		else if ( bSelected )
		{
			pt.Offset( 1, 1 );
			pDC->SetTextColor( CoolInterface.m_crShadow );
			CoolInterface.m_pImages.Draw( pDC, nIcon, pt, ILD_MASK );
			pt.Offset( -2, -2 );
			CoolInterface.m_pImages.Draw( pDC, nIcon, pt, ILD_TRANSPARENT );
		}
		else
		{
			ImageList_DrawEx( CoolInterface.m_pImages.m_hImageList, nIcon, pDC->GetSafeHdc(),
				pt.x, pt.y, 0, 0, CLR_NONE, CoolInterface.m_crMargin, ILD_BLEND25 );
		}
	}
	
	CFont* pOld = (CFont*)pDC->SelectObject(
					( lpDrawItemStruct->itemState & ODS_DEFAULT ) && ! bDisabled ?
					&CoolInterface.m_fntBold : &CoolInterface.m_fntNormal );
	
	pDC->SetBkMode( TRANSPARENT );
	pDC->SetTextColor( bDisabled ? CoolInterface.m_crDisabled :
		( bSelected ? CoolInterface.m_crCmdTextSel : CoolInterface.m_crCmdText ) );
	DrawMenuText( pDC, &rcText, strText );
	
	pDC->SelectObject( pOld );
	
	dc.BitBlt( lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top,
		rcItem.Width(), rcItem.Height(), pDC, 0, 0, SRCCOPY );
	dc.Detach();
}
コード例 #3
0
ファイル: JMenuEx.cpp プロジェクト: dulton/nampu
void JMenuEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// TODO:  添加您的代码以绘制指定项
	//TRACE("---%d\n", lpDrawItemStruct->itemID);
	CDC dc;
	CRect rc(lpDrawItemStruct->rcItem);
	dc.Attach(lpDrawItemStruct->hDC);
	PJMENUITEM pJMenuItem = (PJMENUITEM)(lpDrawItemStruct->itemData);
	//文本颜色
	if(lpDrawItemStruct->itemState & ODS_SELECTED)
	{
		dc.SetTextColor(m_crMenuTextSelect);
	}
	else
	{
		dc.SetTextColor(m_crMenuText);
	}
	//背景色
	CBrush brBK(m_crMenuBK);
	dc.FillRect(&rc, &brBK);

	int iOldBKMode = dc.SetBkMode(TRANSPARENT);

	//左边颜色
	CBrush brLeft(m_crMenuLeft);
	RECT rcLeft = lpDrawItemStruct->rcItem;
	rcLeft.right = rcLeft.left + LEFT_BORDER_MENUE;
	dc.FillRect(&rcLeft, &brLeft);

	//分隔条
	if(pJMenuItem->uID == 0)
	{
		CRect rcSpliter = lpDrawItemStruct->rcItem;
		rcSpliter.top += rcSpliter.Height() / 2;
		rcSpliter.bottom = rcSpliter.top + 2;
		rcSpliter.left += LEFT_BORDER_MENUE + 2;
		rcSpliter.right -= 1;
		CBrush br(m_crSpliterbar);
		dc.Draw3dRect(&rcSpliter, m_crSpliterbar, m_crMenuBK);
	}
	else
	{
		//画文字
		BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
		BOOL bGrayed = lpDrawItemStruct->itemState & ODS_GRAYED;
		BOOL bCheck = lpDrawItemStruct->itemState & ODS_CHECKED;
		CRect rcText(rc.left + LEFT_BORDER_MENUE + 5, rc.top, rc.right, rc.bottom);
		DrawMenuText(&dc, rc, rcText, bSelected, bGrayed, pJMenuItem);

		//勾选
		if(bCheck)
		{


			CRect rcCheckRect = lpDrawItemStruct->rcItem;
			rcCheckRect.left += 3;
			rcCheckRect.right = LEFT_BORDER_MENUE - 3;
			dc.FillSolidRect(rcCheckRect, RGB(186, 186, 186));
			dc.Draw3dRect(rcCheckRect, RGB(0, 100, 190), RGB(0, 180, 200));			
			
			dc.SetTextColor(m_crCheck);
			CRect rcCheck = lpDrawItemStruct->rcItem;
			rcCheck.left += LEFT_BORDER_MENUE / 2 - 3;
			dc.DrawText(_T("√"), &rcCheck, DT_EXPANDTABS|DT_VCENTER|DT_SINGLELINE);
		}
	}
	dc.SetBkMode(iOldBKMode);
	dc.Detach();
}
コード例 #4
0
ファイル: MenuItem.cpp プロジェクト: guowei8412/upp-mirror
void MenuItem::Paint(Draw& w)
{
	int q = text.Find('\t');
	String txt, keydesc;
	if(accel)
		keydesc = GetKeyDesc(accel);
	if(q >= 0) {
		keydesc = text.Mid(q + 1);
		txt = text.Mid(0, q);
	}
	else
		txt = text;
	state = GetVisualState();
	bool hl = state != NORMAL;
	Size sz = GetSize();

	if(hl) {
		if(GUI_GlobalStyle() >= GUISTYLE_XP)
			ChPaint(w, 0, 0, sz.cx, sz.cy, style->item);
		else
			w.DrawRect(sz, SColorHighlight);
	}
	UPP::Image li = licon;
	if(li.IsEmpty()) {
		switch(type) {
		case CHECK0: li = CtrlImg::MenuCheck0(); break;
		case CHECK1: li = CtrlImg::MenuCheck1(); break;
		case RADIO0: li = CtrlImg::MenuRadio0(); break;
		case RADIO1: li = CtrlImg::MenuRadio1(); break;
		}
	}
	Size isz = li.GetSize();
//	Size isz = min(maxiconsize, imsz);
//	if(isz != imsz)
//		li = CachedRescale(li, isz);
	int iy = (sz.cy - isz.cy) / 2;
	bool chk = false;
	int x = Zx(2);
	if(!licon.IsEmpty() && type) {
		chk = type == CHECK1 || type == RADIO1;
		if(GUI_GlobalStyle() >= GUISTYLE_XP) {
			if(chk && !hl)
				DrawXPButton(w, RectC(0, iy - Zy(2), isz.cx + Zx(4), isz.cy + Zy(4)),
				             BUTTON_EDGE|BUTTON_CHECKED);
		}
		else {
			w.DrawRect(x - Zx(1), iy - Zy(1), isz.cx + Zx(2), isz.cy + Zy(2),
			           chk ? Blend(SColorFace, SColorLight) : SColorFace);
			DrawBorder(w, x - Zx(2), iy - Zy(2), isz.cx + Zx(4), isz.cy + Zy(4),
			           chk ? ThinInsetBorder : ThinOutsetBorder);
		}
	}
	if(isenabled)
		DrawHighlightImage(w, x, iy, li, hl || chk, true);
	else
		w.DrawImage(x, iy, DisabledImage(li));
	x = max(isz.cx, leftgap) + textgap;
	isz = GetTextSize(text, StdFont());
	DrawMenuText(w, x, (sz.cy - isz.cy) / 2, txt, font, isenabled, hl, style->menutext,
	             style->itemtext);
	isz = ricon.GetSize();
	if(isenabled)
		w.DrawImage(sz.cx - isz.cx, (sz.cy - isz.cy) / 2, ricon, hl ? style->itemtext : style->menutext);
	else
		w.DrawImage(sz.cx - isz.cx, (sz.cy - isz.cy) / 2, DisabledImage(ricon));
	x = sz.cx - max(isz.cx, Zx(16)) - Zx(1);
	if(!IsEmpty(keydesc)) {
		isz = GetTextSize(keydesc, StdFont());
		UPP::DrawMenuText(w, x - isz.cx - Zx(2), (sz.cy - isz.cy) / 2, keydesc, font, isenabled, hl,
		                  0, SColorMenuMark(), style->itemtext, false);
	}
}