[wxPython-users] GCDC vs DC (was: Re: Automotive-type gauge)

Chris Mellon arkanes at gmail.com
Thu Aug 2 06:10:45 PDT 2007


On 8/2/07, Christian K <ckkart at hoc.net> wrote:
> Chris Mellon wrote:
> > On 8/1/07, Andrea Gavana <andrea.gavana at gmail.com> wrote:
> >> You might find my implementation of SpeedMeter useful:
> >>
> >> http://xoomer.alice.it/infinity77/eng/freeware.html#speedmeter
> >>
> >> I almost finished refactoring my web pages, so you might find some
> >> troubles today or tomorrow... but the code is there :-D
> >>
> >
> > Nice work as always Andrea. A one-liner wrapping the DC used for
> > drawing in a wxGCDC gives very nice anti-aliasing, but makes it quite
> > a bit slower. Maybe if I can find some time I'll work on a port that's
> > optimized for wxGraphicsContext. I think it could end up quite faster
> > than the raster based version.
>
> What kind of optimization can be done when using GCDC instead of DC? Do y=
ou
> think wx.lib.plot could be made faster, too?  plot.py is basically using
> DrawLine, DrawLineList, DrawText I think. Are there faster replacements?
>
> Thanks, Christian
>

Some clarification of terms:
wxGraphicsContext is the vector drawing implementation. wxGCDC is the
wxDC raster API on top of wxGraphicsContext. It's (mostly) a drop in
replacement, and while it's not as efficient you do get nice
anti-aliased drawing and smooth scaling.

So in most cases you can take your current drawing code, wrap a wxGCDC
around the actual DC required and get better quality drawing at the
expense of performance.


You can also write to the wxGraphicsContext directly, which allows for
quite some optimizations. wxGC is path-based, and you can pre-create
and define paths. You can then draw and fill these paths easily, even
repeatedly, at any rotation or transform you desire. wxGC also
supports alpha blended colors.

A lot of the code in Andreas control is managing all the layout, the
correct geometric transforms, and drawing all the right pieces in all
the right spots. A drawing implementation optimized for wxGC can move
a lot of this bookkeeping into the vector graphics implementation.

And, of course, you get high quality drawing and scaling for free.

I've attached the quick and dirty implementation I did. Note how I
draw the dropshadow by using the same path object, just with a
different brush (with alpha transparency) and a transform.

In a real implementation, you could pre-create all these paths
(allowing subclasses to customize, of course).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: g.py
Type: text/x-python
Size: 1652 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20070=
802/2c689be0/g.py


More information about the wxpython-users mailing list