Page 1 of 1

Slow gadget drawing

Posted: Wed Jul 09, 2008 11:54 am
by jvalks
Hi everyone,

I'm just killing some time at work ;) And I noticed that drawing gadgets is very slow in PB (using 4.20). The window opens immediately , but it takes about 1 second before I see the buttons and listview gadget... Any idea why??

Example code:

Code: Select all

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Listview_0
  #Button_0
  #Button_1
  #Button_2
EndEnumeration


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 462, 241, 202, 218, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ListViewGadget(#Listview_0, 10, 10, 180, 120)
      ButtonGadget(#Button_0, 10, 140, 60, 30, "1")
      ButtonGadget(#Button_1, 70, 170, 60, 30, "2")
      ButtonGadget(#Button_2, 130, 140, 60, 30, "3")
      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  Event = WindowEvent()
  Delay(1)
Until Event = #PB_Event_CloseWindow

Posted: Wed Jul 09, 2008 12:06 pm
by gnozal
It doesn't seem slow here, using a PII-300mHz !
You could try this (with #PB_Window_Invisible) :

Code: Select all

Enumeration 
  #Window_0 
EndEnumeration 

;- Gadget Constants 
; 
Enumeration 
  #Listview_0 
  #Button_0 
  #Button_1 
  #Button_2 
EndEnumeration 


Procedure Open_Window_0() 
  If OpenWindow(#Window_0, 462, 241, 202, 218, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_Invisible) 
    If CreateGadgetList(WindowID(#Window_0)) 
      ListViewGadget(#Listview_0, 10, 10, 180, 120) 
      ButtonGadget(#Button_0, 10, 140, 60, 30, "1") 
      ButtonGadget(#Button_1, 70, 170, 60, 30, "2") 
      ButtonGadget(#Button_2, 130, 140, 60, 30, "3") 
    EndIf 
    HideWindow(#Window_0, #False)
  EndIf 
EndProcedure 

Open_Window_0() 

Repeat 
  Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow

Re: Slow gadget drawing

Posted: Wed Jul 09, 2008 12:13 pm
by tinman
jvalks wrote:I'm just killing some time at work ;) And I noticed that drawing gadgets is very slow in PB (using 4.20). The window opens immediately , but it takes about 1 second before I see the buttons and listview gadget... Any idea why??
Have you tried removing the Delay(1) and replacing the WindowEvent() with WaitWindowEvent()?

Re: Slow gadget drawing

Posted: Wed Jul 09, 2008 12:19 pm
by jvalks
tinman wrote:
jvalks wrote:I'm just killing some time at work ;) And I noticed that drawing gadgets is very slow in PB (using 4.20). The window opens immediately , but it takes about 1 second before I see the buttons and listview gadget... Any idea why??
Have you tried removing the Delay(1) and replacing the WindowEvent() with WaitWindowEvent()?
Ow, that's it!!!! I used WindowEvent() because it's the recommended method, but not for GUI based programs I think...

Thanks!!!

Re: Slow gadget drawing

Posted: Wed Jul 09, 2008 1:14 pm
by PB
You should only use Delay(1) if WindowEvent()=0.

If using WaitWindowEvent(), you don't need Delay() at all.

Posted: Wed Jul 09, 2008 1:25 pm
by Foz
Due to some of my code relies on a network connection to a database, filling in drop down lists slows the rendering time right down ("box, pause, box, pause, etc")

So I start the window invisible and then show the window when it's finished. It's very effective!

Posted: Wed Jul 09, 2008 1:36 pm
by Kaeru Gaman
the problem with the first code is, that a Delay(1) will wait at least 1ms,
but in every case until the next system timeslice, wich is 16ms on a 32bit XP.

so, it will take 16ms to process each event produced during the window construction.
as a result WaitWindowEvent() is faster, because it will not wait 16ms each event.

creating the window invisible may help the look, you can add an "event-eater"
before making the window visible again to make sure it's completely created.