Esempio n. 1
0
BOOL GdiplusUtilities::DrawTextOutline(Gdiplus::Graphics& graphics, 
					 LPCTSTR lpchText, int cchText, const Gdiplus::Rect& rc, const Gdiplus::StringFormat& format, 
					 const Gdiplus::Font& font, Gdiplus::Color fill, Gdiplus::Color outline, INT outlineWidth,
					 BOOL bCalcOnly/* = FALSE*/, Gdiplus::Rect* rcCalc/* = NULL*/)
{
	Gdiplus::FontFamily fontFamily;
	font.GetFamily(&fontFamily);
	Gdiplus::GraphicsPath path;
	path.AddString(lpchText, cchText, &fontFamily, font.GetStyle(), font.GetHeight(&graphics), rc, &format);

	if (rcCalc != NULL)
	{
		path.GetBounds(rcCalc);
		rcCalc->Inflate(outlineWidth, outlineWidth);
	}
	if (bCalcOnly)
		return TRUE;

	Gdiplus::Pen pen(outline, (Gdiplus::REAL) outlineWidth);
	if (graphics.DrawPath(&pen, &path) == Gdiplus::Ok)
	{
		Gdiplus::SolidBrush brush(fill);
		return graphics.FillPath(&brush, &path) == Gdiplus::Ok;
	}
	return FALSE;
}
Esempio n. 2
0
void CListViewNode::OnCalcRects(Gdiplus::Graphics* graphics, LPRECT pRect, LPINT maxWidth)
{
	if ( !m_listView )
		return;

	Gdiplus::Font* pFont = NULL;

	if ( m_selected )
		pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView"));
	else
		pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView"));

	Gdiplus::PointF pt; pt.X = (Gdiplus::REAL)(pRect->left); pt.Y = (Gdiplus::REAL)(pRect->top);
	Gdiplus::RectF textRect;

	if ( m_text.IsEmpty() )
	{
		textRect.X = pt.X; textRect.Y = pt.Y; textRect.Height = pFont->GetHeight(graphics); textRect.Width = 10;
	}
	else
		graphics->MeasureString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), &textRect);

	Convert2Rect(pRect, &textRect);

	Gdiplus::Bitmap* image = NULL;
	LONG hImage = 0;

	if ( (m_imageIndex >= 0) && (((dword)m_imageIndex) < m_listView->get_ImageCount()) )
		image = m_listView->get_Image(m_imageIndex);
	if ( image && (image->GetHeight() > 0) )
		hImage = image->GetHeight();

	::SetRect(&m_iconRect, pRect->left, pRect->top, pRect->left + hImage, (hImage > 0)?(pRect->top + hImage):(pRect->bottom));
	if ( (hImage > 0) && ((pRect->bottom - pRect->top) > hImage) )
		::OffsetRect(&m_iconRect, 0, (pRect->bottom - pRect->top - hImage) / 2);
	::OffsetRect(pRect, hImage + 2, 0);
	::CopyRect(&m_textRect, pRect);
	if ( hImage > (pRect->bottom - pRect->top) )
		::OffsetRect(&m_textRect, 0,  (hImage - (pRect->bottom - pRect->top)) / 2);
	::CopyRect(&m_borderRect, &m_textRect);
	m_borderRect.right += 4; m_borderRect.bottom += 4;
	::OffsetRect(&m_textRect, 2, 2);
	if ( m_borderRect.right > *maxWidth )
		*maxWidth = m_borderRect.right;
	::OffsetRect(pRect, -(hImage + 2), 0);
	pRect->top = max(m_iconRect.bottom, m_borderRect.bottom);
	pRect->bottom = 0;
}