flick problem

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.
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

flick problem

Post by gpu » Mon Sep 01, 2014 7:36 am

when I drag the panel on the wxScrollWindow , all the panels flick....
How to avoid this?
Thank you!

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Mon Sep 01, 2014 9:05 am

This is hard to tell, first you need to find out what exactly flickers. Often it helps to set different background colours for all elements involved to see what's going on.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Tue Sep 02, 2014 7:30 am

1) pan the wxScrollWindow: I caculate a postion in MouseMoved func, and call Refresh there. Then in Render func set this postion to Scroll().
//all the things I draw using PaintDC flickers a lot(including the lines I draw on wxScrollWindow, the semi-transparent bimap and text I draw on the big and small panel), but the controls just flickers a little. <ps.I use PaintDC everywhere, as wxBufferdPaintDC didn't work right>
2) I just tested, whereever I called the wxScrollWindow::Refresh, (<A>when I move the big panel on the wxScrollWindow; <B>when I pan the wxScrollWindow;), everything I draw with PaintDC, including the lines on the wxScrollWindow, the semi-transparent bimap and text I draw on the big and small panel...All of them flickers a lot...
meanwhile, I test the scrollbar(I not do nothing with the scrollbar, all the func are default), all the panles seem very good, but the wxScrollWindow I think it need refresh, cause I do nothing right now.
3) if I didn't call wxScrollWindow::Refresh when I move the panel, the panels don't flicker, but I have to Refresh the whole wxScrollWindow to get the right result...cause I need the right semi-transparent and have to refresh the line which linked two panels(ps. I now draw the link lines using the wxScrollWindow's PaintDC).

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Tue Sep 02, 2014 8:02 am

That's not what i meant when i talked about finding out what flickers.

Flickering is caused when something is drawn first (e.g. a background with a solid color) and then something else is drawn on top. If you're using wx[Auto]BufferedPaintDC for drawing, the flickering is most likely caused by the default background of one of the controls or the back panel.

Try setting different background colors for the different types of windows you're using. E.g. red, yellow and green. Then you should be able to see who's the culprit.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Tue Sep 02, 2014 8:25 am

ok thank u and I already tried to set the background color for the controls and small panels...only the big panel's back ground color not set.
so according to what u said, is it right to do like this? -> in the small panel's Render func, I call the parent's Render first and then do its own drawing, so as for the big panel.
//
and how to explain the lines I draw on the wxScrollWindow flikering...I called the Refresh...

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Tue Sep 02, 2014 8:37 am

is it right to do like this? -> in the small panel's Render func, I call the parent's Render first and then do its own drawing, so as for the big panel.
Yes, as long as you're using a wx[Auto]BufferedPaintDC.
and how to explain the lines I draw on the wxScrollWindow flikering
Do you use a wx[Auto]BufferedPaintDC here, too?

Also, if you haven't done already, try SetBackgroundStyle(wxBG_STYLE_PAINT) for the wxScrollWindow.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Tue Sep 02, 2014 10:14 am

no , i don't use wxBufferedPaintDC. I use wxPaintDC everywhere...
cause in order to get the right semi-transparent bitmap.... in the example u gave me that time , u use wxBufferedPaintDC, but i tried and that's wrong, and I changed it to wxPaintDC, the result is right.

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Tue Sep 02, 2014 10:23 am

Also, if you haven't done already, try SetBackgroundStyle(wxBG_STYLE_PAINT) for the wxScrollWindow.
I tried, and even worse...the backgound never clear&refresh...and i tried ClearBackground in paintEvent, it also flickers....

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Tue Sep 02, 2014 12:28 pm

no , i don't use wxBufferedPaintDC. I use wxPaintDC everywhere...
Then you must use wxBufferedPaintDC and find out why it didn't give the correct output. When using wxPaintDC it will probably always flicker.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Wed Sep 03, 2014 7:41 am

I just tried the wxScrollWindow first, when I use wxBufferedPadintDC, the background color is always black...
and I do nothing in eraseBckground...
and whether or not use SetBackgroundStyle(wxBG_STYLE_PAINT)...

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Thu Sep 04, 2014 10:22 am

all the flickering problem have solved...But only left 1 problem I really have no idea.
As u know, I have a wxScrollWindow, and some big panels on it, and some small panels on the big panels, and then some controls on the small panels.
And, I link 2 small panels with lines, and the lines are drawn using the wxScrollWindow's wxAutoBuffererPaintDC.
Here comes the problem:
when I drag the big panel to move it to a new position(of course the small panels and controls are moved together), in order to draw the linked line, I have to call wxScrollWindow::Refresh, NOW the big panel, small panel, and controls on it all seem very "dragging"(not flickering) especially when I move them fast(if I moved them very very slowly, the result looks much better and can accept).

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Thu Sep 04, 2014 10:49 am

Hard to tell from a distance. Maybe the code in the paint event handlers is just too slow. Try commenting out parts of it, even if it leaves garbage on the screen. Just to see if that's the problem.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Fri Sep 05, 2014 8:20 am

doublemax wrote:Hard to tell from a distance. Maybe the code in the paint event handlers is just too slow. Try commenting out parts of it, even if it leaves garbage on the screen. Just to see if that's the problem.
I located where the problem is, in the small panels' Render(), I first call the parent(big panel)'s Render(), then draw the backgound bitmap. I try commented the parent's Render() here, the wired "dragging&clipping" appearence when drag&move dissapear. But I have to call the parent's Render()...
And I tested, add only 1 small panel on the big panel, and what is more werid is that the "dragging&clipping" appearence also comes worse while the number of the big panels increase...the 1st big panel is perfect to drag&move whatever the situation is...and in this situation, the 2nd big panel is also good to move, but when I add 4 big panels, move the 4th big panel, the "dragging&clipping" appearence comes again as before(BUT what is really confusing me is that right now if I move the 2nd big panel, it's OK...i think the 4 big panels should be equivalant, but now...as i mentioned before, the 1st big panel is ALWAYS good to move...)
ps. for all the big panel and small panel, I use wxAutoBufferedPaintDC, then PrepareDC, then Render(): dc.Clear(), call the parent's Render(), dc.DrawBitmap.
And for the wxScrollWindow, wxAutoBufferedPaintDC, then PrepareDC, then Render(): dc.Clear(), DrawLine.
(The wrong appearance when move the panel is just like clip the whole big panel including the panel and controls on it, only when move it very very slowly it looks good, the faster the worse...)
plus! I remove all the controls on the small panels when i did the test above, so there is only the semi-transparent big and small panel.

User avatar
doublemax
Moderator
Moderator
Posts: 15651
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: flick problem

Post by doublemax » Fri Sep 05, 2014 9:25 am

And for the wxScrollWindow, wxAutoBufferedPaintDC, then PrepareDC, then Render(): dc.Clear(), DrawLine.
One thing you can try to improve performance is to use wxBufferedPaintDC with a static bitmap as buffer. That way it doesn't have to create a new bitmap each time. But then you have to make sure it's big enough yourself.
Use the source, Luke!

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: flick problem

Post by gpu » Fri Sep 05, 2014 11:25 am

doublemax wrote:
And for the wxScrollWindow, wxAutoBufferedPaintDC, then PrepareDC, then Render(): dc.Clear(), DrawLine.
One thing you can try to improve performance is to use wxBufferedPaintDC with a static bitmap as buffer. That way it doesn't have to create a new bitmap each time. But then you have to make sure it's big enough yourself.
I now use wxAutoBufferedPaintDC, u mean that it internally creates a bitmap each time?
is there any example shows how to realize what u just said, thank you

Post Reply