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?
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.
···
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?
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?
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.