How can i draw a wxDc with alpha?

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
tntfanfan
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jun 19, 2009 5:22 am

How can i draw a wxDc with alpha?

Post by tntfanfan » Mon Jul 06, 2009 2:09 am

in win32 MFC, I can do:

Code: Select all

	CBitmap BarBitmap;
	CDC   BarDC;
	RECT rect;
	rect.left = m_TrackPos.x + m_TrackBarCentrePos.x * m_TrackUnitLength - m_TrackBarWidth / 2;
	rect.right = rect.left + m_TrackBarWidth;
	rect.top = m_TrackBarCentrePos.y;
	rect.bottom = m_TrackBarCentrePos.y + m_TrackBarHeight;
	BarDC.CreateCompatibleDC( &painDC );
	BarBitmap.CreateCompatibleBitmap( &painDC,m_TrackBarWidth, m_TrackBarHeight );
	CBitmap* pOldBarBitmap = BarDC.SelectObject( &BarBitmap );

	CBrush BarBrush;
	RECT BarRect;
	BarRect.left = 0;
	BarRect.top = 0;
	BarRect.right = m_TrackBarWidth;
	BarRect.bottom = m_TrackBarHeight;
	BarBrush.CreateSolidBrush( m_BarColorBk );
	BarDC.FillRect( &BarRect, &BarBrush );
	BarBrush.DeleteObject( );
	BarDC.Draw3dRect( &BarRect, m_TrackBarTrackFrameColor, m_TrackBarTrackFrameColor );

	BLENDFUNCTION BlendFun;
	ZeroMemory( &BlendFun, sizeof( BlendFun ) );
	BlendFun.BlendOp = AC_SRC_OVER;
	BlendFun.AlphaFormat = 0;
	BlendFun.SourceConstantAlpha = 180;
	MemDC.AlphaBlend( 
		rect.left,
		rect.top,
		m_TrackBarWidth,
		m_TrackBarHeight,
		&BarDC,
		0, 
		0,
		m_TrackBarWidth,
		m_TrackBarHeight,
		BlendFun );


	BarDC.SelectObject( pOldBarBitmap );
	BarBitmap.DeleteObject( );
	BarDC.DeleteDC( );

	painDC.BitBlt( 0, 0, ClientRect.right, ClientRect.bottom, &MemDC, 0, 0, SRCCOPY );
	MemDC.SelectObject( pOldBitmap );
	MemBitmap.DeleteObject( );
	MemDC.DeleteDC( );

EDIT by Auria : please use code tags

Post Reply