Re: wxWindow::Refresh( EraseBackground, Rect )

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by Rohit Agarwal »

I call wxCanvas->Refresh( false, rect )
I do not want the background to be erased in the refresh of the rect.
On OSX it erases the background.
On Windows it does not (as I desire)
On Linux it does.

wx ver 3.1.5
OSX BigSur M1
Windows 10 MingW
Linux Ubuntu GTK3

My code is derived from the drawing sample but it's too big to post.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by ONEEYEMAN »

Hi,
What is "Canvas"?
And how do you know it erases it or not?

Thank you.
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by Rohit Agarwal »

There is no wxCanvas.
MyCanvas is a subclass of wxWindow.
My app's drawing happens in 2 layers, a background layer and a foreground layer.
When MyCanvas first get a paint message
{which is on initialisation or when my app gets focus after being switched out)
I draw only the background layer and wait for the user to do something.
Subsequently, when MyCanvas get's a keydown message,
The keydown processor determines what needs to be drawn in the foreground,
Determines the rect that needs to be erased
and then calls MyCanvas->Refresh( false, rect ).
When I get the paint event for this refresh,
I determine where it came from and ask that function (the keydown processor) to do the drawing.

On Mac (BigSur M1), if I don't draw the background behind the foreground in the keydown processor,
I get a white patch.
Same behaviour on Linux (Ubuntu 20.3, GTK3).
On Windows 10, I don't get a white patch but the original background.

My code is 1200 lines and somewhat sketchy so I don't think that will save time.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by doublemax »

Just like i said in your previous thread: Make your life easier and redraw everything in the paint event handler. It will also make your code much cleaner, if you just have a state that you're changing, instead of keep track of what is already on screen and where and trying to update only parts of it.

If you're worried about performance, you can cache static parts of the background in a bitmap. But i would leave that for later.
Use the source, Luke!
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by Rohit Agarwal »

All redraws do happen in PaintEvent handler,
It just delegates the drawing to a function and passes it the DC.
Also, I am using wxMemoryDC for the both the background and the foreground
and DC.Blit for both cases to do the drawing.

I'll create a minimal sample that illustrates the platform dependent behaviour.
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by doublemax »

Rohit Agarwal wrote: Tue Jul 27, 2021 5:35 am All redraws do happen in PaintEvent handler,
When i said "everything", i meant to redraw the whole content unconditionally. Regardless of who or what initiated the redraw.
Use the source, Luke!
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by Rohit Agarwal »

Here's a minimal sample that demonstrates the platform difference.
It's build setting are the same as the Drawing sample.
Press any key to draw the rect in the foreground.
Erases BG on my Mac, not on Windows.
File attached
minimal.cpp
(5.1 KiB) Downloaded 109 times
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: wxWindow::Refresh( EraseBackground, Rect )

Post by Rohit Agarwal »

The conclusion is there is a platform dependency here.
Developers who expect the same behaviour across platforms
must always set eraseBackgound to true.
Post Reply