Gadget flickering

Everything else that doesn't fall into one of the other PB categories.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

I have the solution. It just need to be converted from another language.

- np
Last edited by NoahPhense on Tue Jun 29, 2004 1:58 am, edited 2 times in total.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> I just tried the exact same code again, and now I get the same nasty
> flickering like my home PC.

Confirmed: Your original post is now flickering for me too! 8O
It's probably related to how intensive the CPU is working, because
I haven't done anything different to before, yet before it didn't
flicker for me either. Weird. To me, the "flickering" looks a bit
like "mouse pointer trails", if you've ever seen those, but done
to the window instead of the mouse. I haven't changed my screen
resolution, refresh rate, or any other display settings. Strange!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@PB - Thanks for the confirmation. The odds that my age is affecting my mind/eyes/sanity has just dropped a few percentage points. :D
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

I was tinkering with my 'solution' trying to get it to work for my SkinBuilder app I'm designing... this thing is far more complicated (and flickers far more) than the example apps here...

Best solution to date (for me):
When processing the #PB_Event_SizeWindow event, resize all your gadgets as you normally would.
Then, insert this line at the very end of your size routine:

Code: Select all

RedrawWindow_(WindowID(#Window_Main),0,0,#RDW_INTERNALPAINT|#RDW_UPDATENOW)
This is a bit inefficient since some of the window/gadgets have already been drawn, but maybe someone can optimize it?

Edit:
This works just as well (and it's easier on the keyboard) :

Code: Select all

UpdateWindow_(WindowID())
Last edited by PolyVector on Tue Jun 29, 2004 6:25 am, edited 2 times in total.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

Try this..

Code: Select all

SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)
...
full listing

Code: Select all

Declare Resize()

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Listview_0
  #String_0
  #Button_0
  #Text_0
EndEnumeration

; don't really need to be global.. 
Global cx.l, cy.l, wpi.l, f.l

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 311, 255, 596, 292,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "blah..")
    ; **
    SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)

    If CreateGadgetList(WindowID())
      ListViewGadget(#Listview_0, 0, 5, 290, 175)
      StringGadget(#String_0, 300, 5, 295, 175, "")
      ButtonGadget(#Button_0, 5, 185, 285, 105, "")
      TextGadget(#Text_0, 325, 205, 155, 30, "This is a test...")
      ReSize()
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  
  Event = WaitWindowEvent()
  
  If Event = #PB_EventGadget
      ; Debug "WindowID: " + Str(EventWindowID())
    GadgetID = EventGadgetID()
    
    If GadgetID = #Listview_0
      ;
    ElseIf GadgetID = #String_0
      ;
    ElseIf GadgetID = #Button_0
      ;
    EndIf
  
  ElseIf Event = #PB_Event_SizeWindow 
    ReSize()  
  EndIf
  
Until Event = #PB_EventCloseWindow

End
;

Procedure ReSize() 

  f = #SWP_NOACTIVATE|#SWP_NOZORDER 
  cy = WindowHeight()
  cx = WindowWidth()
  hw = cx/2 
  hh = cy/2 

  wpi = BeginDeferWindowPos_(4) ; Pass the number of windows To be re-sized
;          Params For DeferWindowPos 
;          1) The value passed from BeginDeferWindowPos 
;          2) The Window handle (retrieved from GetDlgItem) 
;          3) A value specifing 'Z-order' (ignored here) 
;          4) x,y,w,h of window 
;          5) Flags (the values in 'f' seem To work best 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),0),0,0,0,hw,hh,f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),1),0,hw+1,0,(cx-(hw+1)),hh,f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),2),0,0,hh+1,hw,cy-(hh+1),f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),3),0,hw+1,hh+1,(cx-(hw+1)),cy-(hh+1),f) 
   EndDeferWindowPos_(wpi)
   wpi = 0 ; clearit
EndProcedure
Question, has anyone tried what Fred has suggested on page 1?

- np
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

@NoahPhense
Your code updates HORRIBLY slow when the window is large on my computer... If I take out this line, it solves the major slowdown, but flickering still occurs...

Code: Select all

SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)
I do, however, like the DeferWindowPos_() part... I'll be using it :)

I did try Fred's method when he posted it, but couldn't get it to work correctly...
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I treid freds method on my ConsoleX library - it flickered on resize on my machine.

Code: Select all

If Message=#WM_ERASEBKGND
    Result=-1 ; or #NULL the result is the same...
EndIf
It stopped the flicker completely. This was a resizing window screen.

But if you try it with gadgets it seem to still flicker. :(
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
Excludes the area occupied by child windows [gadgets] when drawing occurs within the parent window. This style is used when creating the parent window.
Has always worked for me.
El_Choni
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

El_Choni wrote:Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
Excludes the area occupied by child windows [gadgets] when drawing occurs within the parent window. This style is used when creating the parent window.
Has always worked for me.
I tried it. Can't say if it worked or not. Because I've yet to encounter
any flicker on any window, yet.. ;)

- np
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

There shouldn't be anything wrong with the code. I did not write this. I just copied it out of the "samples" directory because I knew it would flicker, just like every other PureBasic program I run.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

halo wrote:There shouldn't be anything wrong with the code. I did not write this. I just copied it out of the "samples" directory because I knew it would flicker, just like every other PureBasic program I run.
No I just meant that I don't have flickering, so it's hard for me to code
for something I cannot see. But I'm still trying.. ;)

- np

Try this out.. lemme know what happens:

no_flicker.rar
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
I Know what the problem was with using WS_CLIPCHILDREN... you can't simply use it on the main window... you must use it on all gadgets that are parents of anything that gets resized... When you do this, there is absolutly no flickering! :)

Code: Select all

Procedure ReduceFlicker_Enum(handle.l,Param.l)
  SetWindowLong_(handle,#GWL_STYLE,GetWindowLong_(handle,#GWL_STYLE)|#WS_CLIPCHILDREN)
  ProcedureReturn #True
EndProcedure

Procedure ReduceFlicker(WindowNumber.l)
  ReduceFlicker_Enum(WindowID(WindowNumber),0)
  EnumChildWindows_(WindowID(WindowNumber),@ReduceFlicker_Enum(),0)
EndProcedure
All you have to do now is call ReduceFlicker(WindowNumber) after all gadgets are created...
Then call UpdateWindow_(WindowID(WindowNum)) after you resize all your gadgets on the #PB_Event_SizeWindow event...

It has near-perfect results for me... Although there is some garbling on some things...hrmmmmm
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Putting

Code: Select all

LockWindowUpdate_(WindowID())
...
LockWindowUpdate_(0)
UpdateWindow_(WindowID())
around your resize code seems to help here although there is still some slight flickering on my system.

@PolyVector: are there any problems making all gadgets have the clipchildren style? Is it safe to use on gadgets which have no children?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

This method works great... :)

UNLESS

your using "PanelGadget":(

With PanelGadget the backgound of the PanelGadget is not erased on resize when you use your modification.

Is panelgadget created by PureBasic or Windows itself?

If its by PureBasic, FRED can u look into this? FRED, if you want to see what I mean I can send you an exe.

-Anthony
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

if you create another gadget AFTER your "ReduceFlicker(window#)" code, what is the process of making this new gadget "flickerfree"?

Do I just call ReduceFlicker(Window#) again?
Post Reply