Drawing only the visible portion of a window

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ZuLuuuuuu
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Jun 21, 2009 8:48 am

Drawing only the visible portion of a window

Post by ZuLuuuuuu » Sun Aug 09, 2009 11:33 pm

Hello,

I read in the reference manual under wxScrolledWindow::GetViewStart that:

"Combined with wxWindow::GetClientSize, the application can use this function to efficiently redraw only the visible portion of the window."

How is this done? Is that something like:

- Get the region,
- Iterate over all the objects on the window and calculate if the current object has a portion inside this region,
- If it has, draw it,
- If it does not have, skip to the next object.

Or is there some other way? I ask this because I have a scrolled window device context, which will have thousands of shapes on it, and I want to draw efficiently.

mikeandtherest
Experienced Solver
Experienced Solver
Posts: 50
Joined: Fri Jul 24, 2009 5:27 pm
Location: Cluj-Napoca, Romania

Post by mikeandtherest » Mon Aug 10, 2009 12:05 am

Hi!

Search the forum, there are other topics similar to yours. And read this article, it will help you for sure http://www.informit.com/articles/article.aspx?p=405047

Cheers,
Mihai Paraschivescu
"The Journey Of A Thousand Miles Begins With A Single Step"

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Drawing only the visible portion of a window

Post by Auria » Mon Aug 10, 2009 1:29 am

ZuLuuuuuu wrote:Hello,

I read in the reference manual under wxScrolledWindow::GetViewStart that:

"Combined with wxWindow::GetClientSize, the application can use this function to efficiently redraw only the visible portion of the window."

How is this done? Is that something like:

- Get the region,
- Iterate over all the objects on the window and calculate if the current object has a portion inside this region,
- If it has, draw it,
- If it does not have, skip to the next object.

Or is there some other way? I ask this because I have a scrolled window device context, which will have thousands of shapes on it, and I want to draw efficiently.
basically, yes. but if you really have so many objects, you may want to look into laying them into a quad-tree, which would allow you to skip directly to visible shapes without having to iterate over non-visible ones.

That being said, don't underestimate the speed of modern computers. In my app, I can draw several thousands of objects by using the simple method you described above, and no slowdown occurs -- with additionnal processing on top of that.
"Keyboard not detected. Press F1 to continue"
-- Windows

ZuLuuuuuu
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Jun 21, 2009 8:48 am

Post by ZuLuuuuuu » Mon Aug 10, 2009 9:51 am

Thank you very much...

Post Reply