Slow gadget drawing

Everything else that doesn't fall into one of the other PB categories.
jvalks
User
User
Posts: 17
Joined: Thu Jun 05, 2003 12:47 pm

Slow gadget drawing

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Slow gadget drawing

Post 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()?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
jvalks
User
User
Posts: 17
Joined: Thu Jun 05, 2003 12:47 pm

Re: Slow gadget drawing

Post 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!!!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Slow gadget drawing

Post by PB »

You should only use Delay(1) if WindowEvent()=0.

If using WaitWindowEvent(), you don't need Delay() at all.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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!
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Post Reply