Draw polygon with transparency

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
olivier1978
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Mar 20, 2007 1:09 am

Draw polygon with transparency

Post by olivier1978 » Wed Apr 02, 2008 8:27 pm

Hi all,

I would like to know how to draw polygons setting a wxBrush with transparency.
I tries this, but it does not work :

Code: Select all

m_ringsColour.Set( 255 , 0 , 0);
m_shapesColour.Set( 255 , 128 , 0 , 0.5 );
m_ringsWidth = 1;
m_penStyle = wxSOLID;
m_brushStyle = wxSOLID;

// ...
wxPen penColour( m_ringsColour , m_ringsWidth , m_penStyle );
wxBrush brushColour( m_shapesColour , m_brushStyle );
// ...
dc.DrawPolygon( m_wxpolygons[i].size() , &(m_wxpolygons[i].front()) );
However, it does not work. Any idea ?

Regards

lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester » Wed Apr 02, 2008 8:45 pm

Code: Select all

	wxPoint points[6];
	border_points[0] = wxPoint( 0, 0 );
	...

	// draw tab outline
	dc.SetPen( *wxBLACK );
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.DrawPolygon(WXSIZEOF(points), points);

olivier1978
Knows some wx things
Knows some wx things
Posts: 27
Joined: Tue Mar 20, 2007 1:09 am

Post by olivier1978 » Wed Apr 02, 2008 9:31 pm

lester wrote:

Code: Select all

	wxPoint points[6];
	border_points[0] = wxPoint( 0, 0 );
	...

	// draw tab outline
	dc.SetPen( *wxBLACK );
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.DrawPolygon(WXSIZEOF(points), points);
Thank you lester. However, with this solution, I still cannot choose the color. I would like to set a color and an alpha transparency for this color.

Regards

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Thu Apr 03, 2008 1:01 am

I'm guessing you're using a wxDC-based device context, and not the wxGraphicsContext API. If this is the case, the alpha setting will only work on wxMac, none of the other platforms support it except when using wxGraphicsContext.

Post Reply