Does using MemoryDC have any advantages over PaintDC?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Does using MemoryDC have any advantages over PaintDC?

steve
Hi,

I'm drawing a gannt chart on a panel, the application draws rectangles which represents tasks.
Each task's information (start/end times, names, etc) is read from database and then written inside rectangle, therefore there are some complex drawing stuff (well, task informations are fetched into memory from database, thus database is read only once at start of app).
Drawing everything from scratch takes time when panel is refreshed (resized etc). I mean everything (all rectangles and texts inside them) is drawn again when panel needs to refresh (resize, etc)

I use a PaintDC and bind it to wx.EVT_PAINT event. But I noticed drawing is not very fast (there may be up to 700 rectangles on the panel at a time)

My questions:

1- If I use MemoryDC instead of PaintDC, will drawing be faster? 
2- What are the advantages of using MemoryDC over PaintDC?
3- Do you have any suggestions to make the drawing faster?

Thanks
Best Regards

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Does using MemoryDC have any advantages over PaintDC?

Tim Roberts
steve wrote:

I use a PaintDC and bind it to wx.EVT_PAINT event. But I noticed drawing is not very fast (there may be up to 700 rectangles on the panel at a time)

My questions:

1- If I use MemoryDC instead of PaintDC, will drawing be faster? 
2- What are the advantages of using MemoryDC over PaintDC?
3- Do you have any suggestions to make the drawing faster?

It won't literally be faster, but it might appear faster to the user.  This is a weird human perception thing.  By using a MemoryDC, you will doing you individual rectangle drawing into memory.  When you're all done, you'll blit that whole bitmap to the screen.  Thus, the user will see the whole thing appear all at once.  It will still have taken time to draw the rectangles, but because the image pops up, the human doesn't notice the delay like he does watching individual rectangles draw.

How much time does it take?  It's also possible your expectations are unrealistic.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Does using MemoryDC have any advantages over PaintDC?

nepix32
In reply to this post by steve
Additional to that what Tim Roberts said, there is the issue, if you have a complex paint routine triggered by EVT_PAINT, it will slow down the GUI on things like resizing, because it will still try to draw while the user has already triggered a new EVT_PAINT due to resizing.

The better option in this case may be to paint to a MemoryDC (maybe even in a separate thread), and blit it in as soon as it is finalized. The difference in this case is that you will get no lag in your GUI, because the bitmap will be put onto the screen only when its ready.

On Monday, January 9, 2017 at 5:21:37 AM UTC+1, steve wrote:
Hi,

I'm drawing a gannt chart on a panel, the application draws rectangles which represents tasks.
Each task's information (start/end times, names, etc) is read from database and then written inside rectangle, therefore there are some complex drawing stuff (well, task informations are fetched into memory from database, thus database is read only once at start of app).
Drawing everything from scratch takes time when panel is refreshed (resized etc). I mean everything (all rectangles and texts inside them) is drawn again when panel needs to refresh (resize, etc)

I use a PaintDC and bind it to wx.EVT_PAINT event. But I noticed drawing is not very fast (there may be up to 700 rectangles on the panel at a time)

My questions:

1- If I use MemoryDC instead of PaintDC, will drawing be faster? 
2- What are the advantages of using MemoryDC over PaintDC?
3- Do you have any suggestions to make the drawing faster?

Thanks
Best Regards

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Does using MemoryDC have any advantages over PaintDC?

Chris Barker - NOAA Federal
You can double-buffer, and then you'll only get a redraw when you need it.

and then be careful to redraw only what had actually changed, that may save you a lot.

Look in the wxpython Wiki for pages on "drawing" and "DC" and "buffer" for more detail.

You also may be able to use existing.lib.floatcanvas to handle much of it.

-CHB

CHB

Sent from my iPhone

On Jan 9, 2017, at 11:14 PM, nepix32 <[hidden email]> wrote:

Additional to that what Tim Roberts said, there is the issue, if you have a complex paint routine triggered by EVT_PAINT, it will slow down the GUI on things like resizing, because it will still try to draw while the user has already triggered a new EVT_PAINT due to resizing.

The better option in this case may be to paint to a MemoryDC (maybe even in a separate thread), and blit it in as soon as it is finalized. The difference in this case is that you will get no lag in your GUI, because the bitmap will be put onto the screen only when its ready.

On Monday, January 9, 2017 at 5:21:37 AM UTC+1, steve wrote:
Hi,

I'm drawing a gannt chart on a panel, the application draws rectangles which represents tasks.
Each task's information (start/end times, names, etc) is read from database and then written inside rectangle, therefore there are some complex drawing stuff (well, task informations are fetched into memory from database, thus database is read only once at start of app).
Drawing everything from scratch takes time when panel is refreshed (resized etc). I mean everything (all rectangles and texts inside them) is drawn again when panel needs to refresh (resize, etc)

I use a PaintDC and bind it to wx.EVT_PAINT event. But I noticed drawing is not very fast (there may be up to 700 rectangles on the panel at a time)

My questions:

1- If I use MemoryDC instead of PaintDC, will drawing be faster? 
2- What are the advantages of using MemoryDC over PaintDC?
3- Do you have any suggestions to make the drawing faster?

Thanks
Best Regards

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.