Hi board,
I am trying to double buffer stuff that I'm drawing in a wxScrolledWindow but I don't seem to be able to do it without allocating a bitmap that is the virtual size of the window. Obviously this won't work if the view is huge. What I want is to allocate a bitmap that is the size of the client rect and then blit it. But I can't. This is the code I've got, which works except for the allocated size of the bitmap. Everything drawn to the window is in "unscrolled coordinates". I've tried calling PrepareDC() on the MemoryDC and I've tried passing the PaintDC to the MemoryDC constructor but neither of these work. Can anyone help? A way that I know of to definitely get round it is to convert everything to window coords before drawing and then don't call PrepareDC - but this makes using a wxScrolledWindow a bit pointless. Can anyone help?
James
wxMemoryDC dc;
int x, y;
GetVirtualSize(&x, &y); // Want to call GetClientSize() here...
wxBitmap bitmap(x, y);
dc.SelectObject(bitmap);
dc.Clear();
paint(dc);
wxPaintDC paintDC(this);
PrepareDC(paintDC);
paintDC.Blit(0, 0, x, y, &dc, 0, 0);
Double buffering/wxScrolledWindow problem
-
- In need of some credit
- Posts: 8
- Joined: Sun Aug 29, 2004 11:13 pm
- Location: Oshkosh, WI, United States
- Contact:
You need to figure out your scroll position and blit from there. See wxScrolledWindow::CalcUnscrolledPosition.
I have a slightly more updated version of wxImagick on my website.
If this helped you, please take the time to rate the value of this post:
http://rate.affero.net/rhorn/
If this helped you, please take the time to rate the value of this post:
http://rate.affero.net/rhorn/
-
- Earned some good credits
- Posts: 120
- Joined: Sun Aug 29, 2004 3:09 pm
- Location: Grenoble, France
- Contact:
We talk about wxScrolledWindow, I have another problem with it too.
As a big flikking is visible, I would use a wxBufferedPaintDC. in my intercept of wPaintEvent.
It is OK : no flikkinkg, correct offset according scorllbars.
But one problem : when I scroll (pageup/pagedown) the old showed zone is correctly blited but the outer zone (now visible) is badly refreshed.
An idea ?
As a big flikking is visible, I would use a wxBufferedPaintDC. in my intercept of wPaintEvent.
It is OK : no flikkinkg, correct offset according scorllbars.
But one problem : when I scroll (pageup/pagedown) the old showed zone is correctly blited but the outer zone (now visible) is badly refreshed.
An idea ?
-
- Earned a small fee
- Posts: 14
- Joined: Fri Sep 03, 2004 11:26 am
- Location: Oxford, UK
- Contact:
I didn't know about the wxBufferedPaintDC. It basically does the same thing as the code I posted. I can't get it to work with a wxScrolledWindow. I've tried Ryan's suggestion but nothing works.Cursor wrote:We talk about wxScrolledWindow, I have another problem with it too.
As a big flikking is visible, I would use a wxBufferedPaintDC. in my intercept of wPaintEvent.
It is OK : no flikkinkg, correct offset according scorllbars.
But one problem : when I scroll (pageup/pagedown) the old showed zone is correctly blited but the outer zone (now visible) is badly refreshed.
An idea ?
I'm not sure how to interpret what you've written. I'm not sure whether you've got it nearly working, or whether its actually just completely broken...
Has anyone ever done double buffering with a wxScrolledWindow? How on earth do you do it???
-
- In need of some credit
- Posts: 8
- Joined: Sun Aug 29, 2004 11:13 pm
- Location: Oshkosh, WI, United States
- Contact:
Yes, and it's just like double buffering anywhere else. What I would suggest is to create a wxMemoryDC member for the class you want to double buffer, as well as a wxBitmap member and a wxImage (or wxImagick) member. Do all your drawing on the wxMemoryDC member (with the wxBitmap member created from the wxImage member), then just blit it to your target DC. I don't bother with wxBufferd[Paint]DC because they create too much overhead. It essentially does this, but continuously deletes and recreates them, which I find wasteful.jamesrf wrote:I didn't know about the wxBufferedPaintDC. It basically does the same thing as the code I posted. I can't get it to work with a wxScrolledWindow. I've tried Ryan's suggestion but nothing works.Cursor wrote:We talk about wxScrolledWindow, I have another problem with it too.
As a big flikking is visible, I would use a wxBufferedPaintDC. in my intercept of wPaintEvent.
It is OK : no flikkinkg, correct offset according scorllbars.
But one problem : when I scroll (pageup/pagedown) the old showed zone is correctly blited but the outer zone (now visible) is badly refreshed.
An idea ?
I'm not sure how to interpret what you've written. I'm not sure whether you've got it nearly working, or whether its actually just completely broken...
Has anyone ever done double buffering with a wxScrolledWindow? How on earth do you do it???
PS You'll want to do this in response to a paint event.
I have a slightly more updated version of wxImagick on my website.
If this helped you, please take the time to rate the value of this post:
http://rate.affero.net/rhorn/
If this helped you, please take the time to rate the value of this post:
http://rate.affero.net/rhorn/
-
- Earned a small fee
- Posts: 14
- Joined: Fri Sep 03, 2004 11:26 am
- Location: Oxford, UK
- Contact:
Thanks for your help Ryan - appreciated. I don't understand the need for a wxImage member. Also, this doesn't really help me that much because I'm basically doing this already (albeit with different lifetime semantics). I don't suppose there's an example of a double buffered wxScrolledWindow anywhere?rhorn wrote:Yes, and it's just like double buffering anywhere else. What I would suggest is to create a wxMemoryDC member for the class you want to double buffer, as well as a wxBitmap member and a wxImage (or wxImagick) member. Do all your drawing on the wxMemoryDC member (with the wxBitmap member created from the wxImage member), then just blit it to your target DC. I don't bother with wxBufferd[Paint]DC because they create too much overhead. It essentially does this, but continuously deletes and recreates them, which I find wasteful.jamesrf wrote:I didn't know about the wxBufferedPaintDC. It basically does the same thing as the code I posted. I can't get it to work with a wxScrolledWindow. I've tried Ryan's suggestion but nothing works.Cursor wrote:We talk about wxScrolledWindow, I have another problem with it too.
As a big flikking is visible, I would use a wxBufferedPaintDC. in my intercept of wPaintEvent.
It is OK : no flikkinkg, correct offset according scorllbars.
But one problem : when I scroll (pageup/pagedown) the old showed zone is correctly blited but the outer zone (now visible) is badly refreshed.
An idea ?
I'm not sure how to interpret what you've written. I'm not sure whether you've got it nearly working, or whether its actually just completely broken...
Has anyone ever done double buffering with a wxScrolledWindow? How on earth do you do it???
PS You'll want to do this in response to a paint event.
I had the same problem, and this is how you fix it.
void objectmap::OnPaint( wxPaintEvent &event )
{
wxBufferedPaintDC dc(this);
//get the current visible area (is this the easiest way!?!?)
wxSize clientsize = GetClientSize();
int xbegin, ybegin;
GetViewStart(&xbegin, &ybegin);
int xunit, yunit;
GetScrollPixelsPerUnit(&xunit, &yunit);
xbegin*=xunit;
ybegin*=yunit;
//this correct the problem with the scrolling
dc.SetDeviceOrigin(-xbegin, -ybegin);
//do your all drawing as if you don't know anything about scrolling nor double-buffering
}
{
wxBufferedPaintDC dc(this);
//get the current visible area (is this the easiest way!?!?)
wxSize clientsize = GetClientSize();
int xbegin, ybegin;
GetViewStart(&xbegin, &ybegin);
int xunit, yunit;
GetScrollPixelsPerUnit(&xunit, &yunit);
xbegin*=xunit;
ybegin*=yunit;
//this correct the problem with the scrolling
dc.SetDeviceOrigin(-xbegin, -ybegin);
//do your all drawing as if you don't know anything about scrolling nor double-buffering
}