Opened 19 months ago

Closed 14 months ago

Last modified 13 months ago

#15150 closed defect (fixed)

[MSW] wxStaticBox flickering since 2.9.x

Reported by: ericj Owned by:
Priority: normal Milestone: 3.0.0
Component: wxMSW Version: stable-latest
Keywords: wxStaticBox wxStaticBoxSizer Cc:
Blocked By: Blocking:
Patch: yes

Description

Since 2.9.x items in a wxStaticBox flicker heavily, this wasn't the case in wx 2.8.x.

I added a patch to the minimal sample to show the issue. The two screenshots show the initial display. To increase the visual effect, i set the background color of the main panel to green and the wxStaticBox to red.

The first difference is obvious, in 2.8.x the background color of the panel shines through the wxStaticBox. This is probably because wxStaticBox had the WS_EX_TRANSPARENT style in 2.8.x

Clicking on any of the buttons will force 50 redraws of the panel. This does not flicker in 2.8.x, but flickers heavily in 2.9.x as the background of the panel is completely drawn and then the buttons are drawn on top.

I noticed that the flicker disappears if you set background style of the wxStaticBox to wxBG_STYLE_CUSTOM *and* create the items in the wxStaticBox as siblings, not children of it.

My theory what happens:
In 2.9.x the SB was transparent, so its background wasn't drawn. Setting the background style to wxBG_STYLE_CUSTOM has the same effect.

In src/msw/statbox.cpp there is the method wxStaticBox::MSWGetRegionWithoutChildren(). This works as intended if the items in the SB are siblings of it (as mandatory in 2.8.x). In 2.9. it's recommended to create the items as children of the SB, but this method was not adjusted accordingly as it only processes the siblings of the SB. (I'm not 100% sure about this).

Attachments (4)

staticbox_2_8_12.png download (14.8 KB) - added by ericj 19 months ago.
wxStaticBox in wx 2.8.12
staticbox_2_9_SVN.png download (16.1 KB) - added by ericj 19 months ago.
wxStaticBox in wx 2.9.5 (today's SVN)
minimal_staticbox_flicker.patch download (2.0 KB) - added by ericj 19 months ago.
minimal_staticbox_flicker_demo.patch download (1.8 KB) - added by ericj 14 months ago.
New patch to demonstrate flickering.

Download all attachments as: .zip

Change History (10)

Changed 19 months ago by ericj

wxStaticBox in wx 2.8.12

Changed 19 months ago by ericj

wxStaticBox in wx 2.9.5 (today's SVN)

Changed 19 months ago by ericj

comment:1 Changed 17 months ago by vadz

  • Milestone set to 3.0

I really need to look at this before 3.0 but if anybody else can try to do it, notably checking if iterating over children instead of siblings in MSWGetRegionWithoutChildren() helps, it would be welcome.

BTW, another idea: I wonder if we still need to do any custom drawing of the static box at all when its contents is created as its children. Perhaps we could avoid using our custom OnPaint() entirely now?

comment:2 Changed 14 months ago by vadz

  • Resolution set to wontfix
  • Status changed from new to closed

I finally looked at this and realized that you explicitly call Update(). IMO it's not surprising at all that it flickers in this case, as update is supposed to generate an immediate redraw and redrawing the buttons 50 times is visible. If you remove Update() (but leave Refresh()), I don't see any flicker, so IMO this is not a problem at all.

As for the background, the new behaviour is correct and the old one was a bug: we do want the static box background to be taken into account.

comment:3 Changed 14 months ago by ericj

  • Patch set
  • Resolution wontfix deleted
  • Status changed from closed to reopened

The Refresh/Update was only there to amplify the effect. But it also happens in the common use with a wxStaticBoxSizer. I added a new patch where is flickering is also visible by just resizing the window. This was tested under XP, it might be possible that the buffering of the Windows7+ window manager hides the flickering, but it's still there. (I can't test that at the moment, as my Windows7 system has no GPU available for hw-acceleration. And, the flickering doesn't occur with wx 2.8.12.

I know that flickering is usually considered a minor "cosmetic" problem, but IMHO it makes an application look unprofessional when it happens.

Changed 14 months ago by ericj

New patch to demonstrate flickering.

comment:4 Changed 14 months ago by vadz

  • Status changed from reopened to confirmed

OK, I agree the flicker is pretty horrible under XP (it can be seen but is much less serious under 7). I'm going to check in a fix, please retest and let me know if you notice any regressions, e.g. stuff like nested static boxes not displaying correctly and so on. TIA!

comment:5 Changed 14 months ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [74811]) Fix flickering of wxStaticBox background in wxMSW.

First of all, don't erase background in WM_ERASEBKGND at all if we erase it
anyhow in WM_PAINT, this is totally useless and is what wxBG_STYLE_PAINT is for.

Second, clip out not only the siblings of the static box but also its children
when erasing the background to avoid painting over the controls created as the
box children, which is the preferred way to create them now.

Closes #15150.

comment:6 Changed 13 months ago by ericj

I tested this with my sample code, my application and the wxWidgets samples. Everything seems to work fine now.

Thanks!

Note: See TracTickets for help on using tickets.