Questions about the concept of window backgrounds

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
Conststruct
In need of some credit
In need of some credit
Posts: 4
Joined: Fri May 26, 2023 3:11 pm

Questions about the concept of window backgrounds

Post by Conststruct »

Hello all,

This is a multi-question post; I apologize in advance if this format is inappropriate for this forum. If so, please let me know and I will avoid doing it in the future.

I'm continuing to learn wxWidgets, through the tutorials and other helps, but I'm not really clear on wxWidget's concept of backgrounds:

1. From the online docs,
An erase event is sent when a window's background needs to be repainted.
and
A paint event is sent when a window's contents needs to be repainted.
From this, my question is what is meant by "background", and what is meant by "contents"? Do the contents include the background? If not, how are they differentiated?

2. If my mental model of what a background is is correct, then the background would have to be drawn first, then followed by the contents so that they appear "on top" of the background. So then, does the erase event handler always get called before the paint event handler?

3. Do region iterators have any meaning outside of paint events? For example, can I use them within the erase event handler to redraw only the dirty background regions?

4. Apparently, device contexts have their own background? (via ::SetBackground()) What is the difference between context backgrounds and window backgrounds? (e.g. SetBackground() for contexts and SetBackgroundColour() for windows)
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Questions about the concept of window backgrounds

Post by PB »

(speaking from the original Windows API point of view).

Every window has a background colour (brush). You can set it with wxWindow::SetBackgroundColour(). By default, the OS will paint the background using the background colour, or you can paint it yourself in the wxEraseEvent handler. See also
https://docs.wxwidgets.org/stable/class ... event.html

Drawing background and then the window content separately can lead to flicker, so the erase event is often suppressed and everything including the window background is drawn in the paint event handler (ensuring no area is left unpainted), see MyCanvas code in my reply in your other thread.

See also the native docs on how it works in Windows with GDI, it may help understand:
https://learn.microsoft.com/en-us/windo ... erasebkgnd
https://learn.microsoft.com/en-us/windo ... i/wm-paint

Setting background colour for wxDC of course affects only drawing with this DC, which usually exists just inside the paint handler.

Please notice that with modern OSes, the drawing is now usually buffered, e.g., everything is first drawn to the offscreen buffer which is then blitted to the screen.

I have no idea about dirty region iterators in the background erase event handlers.
User avatar
nore
I live to help wx-kind
I live to help wx-kind
Posts: 167
Joined: Mon Apr 17, 2023 10:18 am
Location: San Francisco

Re: Questions about the concept of window backgrounds

Post by nore »

PB wrote: Tue May 30, 2023 3:19 pm (speaking from the original Windows API point of view).

Every window has a background colour (brush). You can set it with wxWindow::SetBackgroundColour(). By default, the OS will paint the background using the background colour, or you can paint it yourself in the wxEraseEvent handler. See also
https://docs.wxwidgets.org/stable/class ... event.html

Drawing background and then the window content separately can lead to flicker, so the erase event is often suppressed and everything including the window background is drawn in the paint event handler (ensuring no area is left unpainted), see MyCanvas code in my reply in your other thread.

See also the native docs on how it works in Windows with GDI, it may help understand:
https://learn.microsoft.com/en-us/windo ... erasebkgnd
https://learn.microsoft.com/en-us/windo ... i/wm-paint

Setting background colour for wxDC of course affects only drawing with this DC, which usually exists just inside the paint handler.

Please notice that with modern OSes, the drawing is now usually buffered, e.g., everything is first drawn to the offscreen buffer which is then blitted to the screen.

I have no idea about dirty region iterators in the background erase event handlers.


Thank you for clearing these issues up. Is blitting just the copying from the DC's buffer to the on-screen DC?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Questions about the concept of window backgrounds

Post by PB »

nore wrote: Tue May 30, 2023 3:56 pm Thank you for clearing these issues up. Is blitting just the copying from the DC's buffer to the on-screen DC?
I meant copying from memory to another, with at least the target being actual video memory, it is called double buffering. wxWidgets has wxBufferedDC for this, but as I said, most modern drawing APIs do this automatically (see also wxAutoBufferedDC).
User avatar
nore
I live to help wx-kind
I live to help wx-kind
Posts: 167
Joined: Mon Apr 17, 2023 10:18 am
Location: San Francisco

Re: Questions about the concept of window backgrounds

Post by nore »

PB wrote: Tue May 30, 2023 5:02 pm
nore wrote: Tue May 30, 2023 3:56 pm Thank you for clearing these issues up. Is blitting just the copying from the DC's buffer to the on-screen DC?
I meant copying from memory to another, with at least the target being actual video memory, it is called double buffering. wxWidgets has wxBufferedDC for this, but as I said, most modern drawing APIs do this automatically (see also wxAutoBufferedDC).
O.K., so just the transferring of memory to another in the context of graphical information? I am only wondering because this applies to some of my studies and programming, such as using a wxBufferedPaintDC with a wxBitmap the size of a window display.
Conststruct
In need of some credit
In need of some credit
Posts: 4
Joined: Fri May 26, 2023 3:11 pm

Re: Questions about the concept of window backgrounds

Post by Conststruct »

@PB Thank you sincerely for taking the time to put that explanation together; it was helpful!
Post Reply