Пример #1
0
// *************************************************************
//		SetTransparency()
// *************************************************************
void ImageHelper::SetTransparency(Gdiplus::ImageAttributes& attributes, bool useTransparency, OLE_COLOR clr1, OLE_COLOR clr2)
{
	// setting range of colors which will be transparent
	if (useTransparency)
	{
		Gdiplus::Color color1(MIN(GetRValue(clr1), GetRValue(clr2)),
			MIN(GetGValue(clr1), GetGValue(clr2)),
			MIN(GetBValue(clr1), GetBValue(clr2)));

		Gdiplus::Color color2(MAX(GetRValue(clr1), GetRValue(clr2)),
			MAX(GetGValue(clr1), GetGValue(clr2)),
			MAX(GetBValue(clr1), GetBValue(clr2)));

		attributes.SetColorKey(color1, color2);
	}
}
Пример #2
0
void CListViewNode::OnPaint(Gdiplus::Graphics* graphics, INT xPos, INT yPos, INT cBottom, INT cRight)
{
	if ( !m_listView )
		return;

	RECT iconRect; ::CopyRect(&iconRect, &m_iconRect); ::OffsetRect(&iconRect, -xPos, -yPos);
	RECT textRect; ::CopyRect(&textRect, &m_textRect); ::OffsetRect(&textRect, -xPos, -yPos);
	RECT borderRect; ::CopyRect(&borderRect, &m_borderRect); borderRect.right = borderRect.left + cRight; ::OffsetRect(&borderRect, 0, -yPos);
	
	if ( iconRect.bottom < 0 )
		return;
	if ( iconRect.top >= cBottom )
		return;

	Gdiplus::Font* pFont = NULL;
	Gdiplus::Brush* pBrushBackground = NULL;
	Gdiplus::Brush* pBrushForeground = NULL;

	if ( m_selected )
	{
		pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Selected"), _T("ListView"), Gdiplus::Color::Blue);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Selected"), _T("ListView"), Gdiplus::Color::White);
	}
	else
	{
		pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Normal"), _T("ListView"), Gdiplus::Color::White);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Normal"), _T("ListView"), Gdiplus::Color::Black);
	}

	Gdiplus::RectF iconRectF; Convert2RectF(&iconRectF, &iconRect);
	Gdiplus::RectF textRectF; Convert2RectF(&textRectF, &textRect);
	Gdiplus::RectF borderRectF; Convert2RectF(&borderRectF, &borderRect);
	Gdiplus::PointF pt; pt.X = textRectF.X; pt.Y = textRectF.Y;

	graphics->FillRectangle(pBrushBackground, borderRectF);

	Gdiplus::Bitmap* image = NULL;
	UINT 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();
	if ( hImage > 0 )
	{
		Gdiplus::Color transparentcolor;
		Gdiplus::ImageAttributes imAtt;

		image->GetPixel(0, hImage - 1, &transparentcolor);
		imAtt.SetColorKey(transparentcolor, transparentcolor, Gdiplus::ColorAdjustTypeBitmap);

		graphics->DrawImage(image, iconRectF, 0.0, 0.0, Cast(Gdiplus::REAL,hImage), Cast(Gdiplus::REAL,hImage), Gdiplus::UnitPixel, &imAtt);
	}
	if ( !(m_text.IsEmpty()) )
		graphics->DrawString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), pBrushForeground);
	if ( m_focused )
	{
		Gdiplus::Pen grayPen(Gdiplus::Color::Gray);
		grayPen.SetDashStyle(Gdiplus::DashStyleDot);

		graphics->DrawRectangle(&grayPen, textRectF);
	}
}