Drawing question

I have a few questions about drawing. The project I am working on I
did not write the drawing code it uses now, but I have to try an
update it, and I dont always understand why it does something one way
or another so I figured I would ask a few questions so I can better
understand how to use a DC (or GCDC) in general.

A little info about my project
1) It draws to a scrolled window
2) It has several "layers", basically just containers for diff types
of drawing that keep track of all the objects they are responsible for
(Images, lines, text etc.)
3) Every time an object is redrawn it creates a new DC, draws it then
deletes the DC
4) It uses a mix of ClientDC and MemoryDC (I have not figured out yet
why it uses one over the other in places)

So my questions

1) Would it be better to make a Canvas wide DC that each "layer" uses
when it wants to draw and not delete the DC or is it better to create,
draw, then delete like it does now?

2) How is the new Graphics Device better / worse then using ClientDC
and MemoryDC?

Dj Gilcrease wrote:

4) It uses a mix of ClientDC and MemoryDC (I have not figured out yet
why it uses one over the other in places)

Well, Memory DC draws to an of-screen bitmap. A ClientDC draws to the screen immediately.

1) Would it be better to make a Canvas wide DC that each "layer" uses
when it wants to draw and not delete the DC

I think so. It sure seems like overkill to create a new dc for each object. However, it is considered a bad idea to keep DCs around forever.

Usually, one creates a DC, draws everything to it, then throws it away, creating a new one when the drawing needs to be updated.

2) How is the new Graphics Device better / worse then using ClientDC
and MemoryDC?

The new graphics device supports alpha blending, anti-aliasing, and more sophisticated path-based drawing.

Make sure you read the relevant Wiki pages:
http://wiki.wxpython.org/index.cgi/RecipesImagesAndGraphics

and you might want to check out wx.lib.floatcanvas for an involved example.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Ok I have a another Drawing question now that I have started writing
some code. I have my code to a point that it draws some stuff works
well on windows, but fails to draw the 4 circles on Linux, but does
not output any errors to the console. So I was wondering if I am doing
something wrong or ?

map.py (17.3 KB)

Dj Gilcrease wrote:

Ok I have a another Drawing question now that I have started writing
some code. I have my code to a point that it draws some stuff works
well on windows, but fails to draw the 4 circles on Linux, but does
not output any errors to the console. So I was wondering if I am doing
something wrong or ?

There is still a couple holes in the GraphicsContext implementation on Linux, one of those is drawing bitmaps.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Dj Gilcrease wrote:

Ok I have a another Drawing question now that I have started writing
some code. I have my code to a point that it draws some stuff works
well on windows, but fails to draw the 4 circles on Linux, but does
not output any errors to the console. So I was wondering if I am doing
something wrong or ?

FWIW, it crashes on OS-X

Also, this is too much code for me to quickly figure out, but it looks like you could have saved yourself a lot of time by using wx.lib.floatcanvas, or better yet, the newest version at:

http://www.mithis.com/~chrisb/

That version has a "Group" object that is pretty much like a layer.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

I looked at FloatCanvas, but decided against it because it required
more external installs (numpy) for my end users, plus it, as far as I
could tell, does not support Alpha blending which I need for the
Circle and Fog layers.

As for it crashing on OS-X I bet thats due to the same reason it does
not work on Linux (Double Buffering does not yet work with
GraphicsContext on those platforms)

···

On 2/15/07, Christopher Barker <Chris.Barker@noaa.gov> wrote:

FWIW, it crashes on OS-X

Also, this is too much code for me to quickly figure out, but it looks
like you could have saved yourself a lot of time by using
wx.lib.floatcanvas, or better yet, the newest version at:

http://www.mithis.com/~chrisb/

That version has a "Group" object that is pretty much like a layer.

-Chris

Ok, well I made an even more simplistic example which just draws a
circle onto the panel (No buffer not other junk) and it still fails to
draw the circle on Linux

test.py (989 Bytes)

···

On 2/15/07, Robin Dunn <robin@alldunn.com> wrote:

There is still a couple holes in the GraphicsContext implementation on
Linux, one of those is drawing bitmaps.

For the record: both OS X and Gtk are natively double buffered and
implementing your own buffering on these platforms is a waste of time
at best.

···

On 2/15/07, Dj Gilcrease <digitalxero@gmail.com> wrote:

I looked at FloatCanvas, but decided against it because it required
more external installs (numpy) for my end users, plus it, as far as I
could tell, does not support Alpha blending which I need for the
Circle and Fog layers.

As for it crashing on OS-X I bet thats due to the same reason it does
not work on Linux (Double Buffering does not yet work with
GraphicsContext on those platforms)

I use GraphicsContext on linux without a problem. Try use it directly
instead of creating a GCDC.

···

On 2/15/07, Dj Gilcrease <digitalxero@gmail.com> wrote:

On 2/15/07, Robin Dunn <robin@alldunn.com> wrote:
> There is still a couple holes in the GraphicsContext implementation on
> Linux, one of those is drawing bitmaps.

Ok, well I made an even more simplistic example which just draws a
circle onto the panel (No buffer not other junk) and it still fails to
draw the circle on Linux

Christopher Barker wrote:

Dj Gilcrease wrote:

Ok I have a another Drawing question now that I have started writing
some code. I have my code to a point that it draws some stuff works
well on windows, but fails to draw the 4 circles on Linux, but does
not output any errors to the console. So I was wondering if I am doing
something wrong or ?

FWIW, it crashes on OS-X

Yes, I know about this too. It used to work so it is a regression...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Dj Gilcrease wrote:

···

On 2/15/07, Robin Dunn <robin@alldunn.com> wrote:

There is still a couple holes in the GraphicsContext implementation on
Linux, one of those is drawing bitmaps.

Ok, well I made an even more simplistic example which just draws a
circle onto the panel (No buffer not other junk) and it still fails to
draw the circle on Linux

Looks like another hole. Hopefully we'll get the Cairo backend for wxGraphicsContext up to scratch soon. BTW, if you drop down to the wx.GraphicsContext/wx.GraphicsPath API instead of wx.GCDC then drawing/filling circle paths works ok.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks this worked

···

On 2/16/07, Robin Dunn <robin@alldunn.com> wrote:

Looks like another hole. Hopefully we'll get the Cairo backend for
wxGraphicsContext up to scratch soon. BTW, if you drop down to the
wx.GraphicsContext/wx.GraphicsPath API instead of wx.GCDC then
drawing/filling circle paths works ok.