The code I'm using is:
dc = wx.PaintDC( self )
dc.BeginDrawing()
dc.SetBackgroundMode( wx.SOLID )
dc.DrawBitmap( self.editor_bitmap, 0, 0, False )
c_x, c_y = self.__pixelPoint( self.cursor_x, self.cursor_y )
# alpha blend the cursor
dc.SetBackgroundMode( wx.TRANSPARENT )
cursor_colour = wx.Colour( 0, 0, 0, 92 )
dc.SetPen( wx.Pen( cursor_colour ) )
dc.SetBrush( wx.Brush( cursor_colour ) )
dc.DrawRectangle( c_x, c_y, self.char_width, self.char_length )
dc.EndDrawing()
Is this expected?
I'm using these wx versions:
'2.8.10.1 (mac-unicode)'
'2.8.9.2 (msw-unicode)'
'2.8.9.2 (gtk2-unicode)'
Barry
I you are on XP 32 then use wx.GCDC or wx.GraphicsContext. This
internally uses GDI+ on XP which supports transparency and anti-
aliased drawing. Have a look in Demo->Using Images> Alpha Drawing or
Demo>Miscellaneous>GraphicsContext example.
On GTK aka Linux I would suggest you to check the above examples or a
better and faster option would be use wx.lib.wxcairo. Robin Dunn has
done a great job (Thanks Robin;-)) and wrapped it using
wx.lib.graphics. I have personally used it on ms-win and Linux and it
has solved all the problems that I was facing with native DCs as well
as a slight performance boost in drawing operations.
Try this in above code if you are in hurry:
Replace:
dc = wx.PaintDC(self)
With:
pdc = wx.PaintDC(self)
dc = wx.GCDC(pdc)
Hope it helps.
If it doesn't, comment all the dc.SetBackgroundMode*.* commands and
check one more time.
Prashant
Thanks that fixed the problems.
I now have transparency work on Windows, Mac and Linux GTK.
>
> If it doesn't, comment all the dc.SetBackgroundMode*.* commands and
> check one more time.
>
> Prashant
>
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en
Barry
First of all, you appear to be misunderstanding what SetBackgroundMode(
wx.TRANSPARENT ) is for. It only effects the drawing of text, (whether
it is given a solid background color or not) not all the drawing
operations on the DC.
> On Windows and Linux (Fedora-12) no alpha blending takes place.
>
Secondly, on the Mac the wx.DC class is implemented using a
wx.GraphicsContext (sort of, IIRC they actually both use the same code
underneath the covers) so it is in effect the same as using wx.GCDC on
the other platforms, so that is why setting the alpha on the brush color
works there. This is technically an "implementation detail" and not a
bug. If you assume that wx.DC does not support alpha on the Mac (and
therefore don't try to use it) then it will work approximately the same
as wx.DC on the other platforms.
In an nutshell, wx.DC is designed for old-style 24-bit raster based
drawing with no alpha nor anti-aliasing other than drawing bitmaps that
have alpha and drawing text, but only if the platform automatically
anti-aliases text. wx.GraphicsContext on the other hand is designed to
be implemented using the new-style drawing APIs available on each
platform (GDI+, CoreGraphics, or Cairo) and is meant to be more vector
based and to fully support alpha and anti-aliasing. wx.GCDC is a hybrid
of the two where the DC API is reimplemented using wx.GraphicsContext.
So if you want to draw with alpha then you need to switch to using
wx.GraphicsContext or use wx.GCDC.
--
Robin Dunn
Software Craftsman
http://wxPython.org
If I got this right all I need to do is use colours with alpha and draw with a wx.GCDC.
I can remove the call to SetBackgroundMode( wx.TRANSPARENT ) as its not affecting DrawRectangle at all.
Barry