I need support for an alpha value on a wxBrush when drawing a
rectangle on a wxDC object (so you can still what's behind the
rectangle, just obscured). The manual for wxDC says it works for Mac
OS X when using Core Graphics, but doesn't say for other wx ports.
Does anyone know about the others? I'd rather find out beforehand
before I discover I've wasted my effort..
Chris.
It _only_ works on OS X when using Core Graphics. You can however
accomplish this task easily on all platforms by using the newer
wxGraphicsContext API instead of wxDC.
Regards,
Bryan Petty
Perfect. Thanks Bryan.
Chris.
Or for an easier transition you can use the wxGCDC, which implements the
wxDC API using the wxGraphicsContext. (Not always a perfect match, but
it's close.)
--
Robin Dunn
Software Craftsman
http://wxPython.org
Is there a particular reason why wxGCDC isn't in the online docs yet? Is it
deprecated?
Also, is it possible to use wxGraphicsContext to draw into a bitmap?
I thought I've seen something related to this but couldn't find it anymore in
2.8.10. The wxMemoryDC constructor is MSW-only.
Cheers,
/uli
--
Uli Hertlein
Research and Development email: u...@xdt.com.au
XDT Pty Ltd Web: www.xdt.com.au
wxPaintDC dc(this);
wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
gc->SetBrush(wxBrush(wxColour(255, 204, 229, 63)));
gc->DrawBitmap(label_, 0, 0, label_.GetWidth(), label_.GetHeight());
gc->DrawRectangle(0, lines_, label_.GetWidth(), label_.GetHeight() - lines_);
This is called every half second or so using Refresh(). Quite
frequently there will be a very noticable flicker where the bitmap is
shown before the rectangle is drawn, or even a white background is
shown before even the bitmap is drawn. I tried using Freeze() and
Thaw() but it didn't make a difference. I works as intended in wxGTK.
First, am I using wxGraphicsContext correctly, and if so, any ideas
how to fix this?
On a related note, is it necessary to delete the graphics context at
the end of the function?
Chris.
Yes.
>
> I thought I've seen something related to this but couldn't find it anymore in
> 2.8.10. The wxMemoryDC constructor is MSW-only.
I think it still works on the other platforms though because the wxDC
inheritance hierarchy is slightly different.
Freeze/Thaw simply suspend the sending of Paint events, but since you
are already in the handler for a paint event it doesn't really do
anything. In a nutshell the issue is that on Windows the intermediate
steps in a set of drawing operations can be flushed to the screen at any
time, and so it's possible to see steps along the way.
> First, am I using wxGraphicsContext correctly, and if so, any ideas
> how to fix this?
Use a wxBufferedPaintDC on Windows instead of the wxPaintDC.
>
> On a related note, is it necessary to delete the graphics context at
> the end of the function?
Yes.
That's sorted it, thanks for that Robin.