Page 18 of 45
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 8:36 pm
by Andre
Polo wrote:It would work the same - not sure if it would change anything, I'm pretty sure WindowWidth() and so on return a stored variable and do not actually retrieve it each time?
That's what I think - I don't believe, that the function is so "intelligent", to know if it's called already before and then simply store / reuse the already retrieved size value.
So I think it will call / retrieve the window size again each time...
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 8:36 pm
by ts-soft
I think, it was a good idea to support:
Code: Select all
MenuHeight()
ToolBarHeight()
StatusBarHeight()
for calculation, but not so easy

Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 8:47 pm
by luciano
WWOOOWW for this useful improvement to FD!
So I think it will call / retrieve the window size again each time...
I think the same as Andre, I believe that this way, will be faster (mainly in applications with many gadgets)
Code: Select all
Global Window_0
Global Button_0, Button_0_1, Tree_0, Panel_0
Declare ResizeGadgetsWindow_0()
Procedure InitWindow_0()
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
Button_0 = ButtonGadget(#PB_Any, WindowWidth(Window_0) - 100, WindowHeight(Window_0) - 30, 90, 25, "Save")
Button_0_1 = ButtonGadget(#PB_Any, WindowWidth(Window_0) - 200, WindowHeight(Window_0) - 30, 90, 25, "Cancel")
Tree_0 = TreeGadget(#PB_Any, 10, 10, 210, WindowHeight(Window_0) - 50)
Panel_0 = PanelGadget(#PB_Any, 230, 10, WindowWidth(Window_0) - 240, WindowHeight(Window_0) - 50)
AddGadgetItem(Panel_0, -1, "Tab 1")
CloseGadgetList()
EndProcedure
Procedure ResizeGadgetsWindow_0()
; stored values
storedW.i=WindowWidth(Window_0)
storedH.i=WindowHeight(Window_0)
ResizeGadget(Button_0, storedW - 100, storedH- 30, 90, 25)
ResizeGadget(Button_0_1, storedW - 200, storedH - 30, 90, 25)
ResizeGadget(Tree_0, 10, 10, 210, storedH - 50)
ResizeGadget(Panel_0, 230, 10, storedW - 240, storedH - 50)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
EndProcedure
InitWindow_0()
Repeat
event = WaitWindowEvent()
If event = #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndIf
Until event = #PB_Event_CloseWindow
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 9:14 pm
by Polo
For now it'll stay like that, I'll change it later maybe!
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 9:35 pm
by Andre
Polo wrote:For now it'll stay like that, I'll change it later maybe!
No problem
I just thought, it will speed up things when using a lot of gadgets, and also the generated code is better readable.
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 9:46 pm
by Polo
Andre wrote:I just thought, it will speed up things when using a lot of gadgets, and also the generated code is better readable.
That's true, though for gadget resizing inside a container there's the same issue then!
I always had in my mind that PB buffered that kind of data, we'll see what Fred or Timo say about that - if it's not buffered I'll make the change, if it is buffered I'd rather leave the functions directly

Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 9:52 pm
by ts-soft
This values (WindowWidht, WindowY and so on), stored in the object of windows/gadgets.
This will be only changed on events!
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 9:58 pm
by luciano
To my surprise, there is no real difference between the two methods, I made a test with a repeated loop and the results were very similar.
Code: Select all
Repeat
event = WaitWindowEvent(10)
If event = #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndIf
millisecond.i=ElapsedMilliseconds()
For conta=0 To 10000
ResizeGadgetsWindow_0()
Next
Debug ElapsedMilliseconds()-millisecond
Until event = #PB_Event_CloseWindow
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 10:05 pm
by Polo
I'm not so surprised as it makes sense that PB caches those values

Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sat Sep 01, 2012 10:38 pm
by Polo
Added Toolbar/Statusbar/Menu support for automatic resizing.
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sun Sep 02, 2012 7:15 am
by wilbert
@luciano, you should never do timing tests with debug turned on.
The results are not reliable in that case. It's better to use a MessageRequester to show the results and test with debug turned off.
@Polo, have you considered passing width and height to the procedure ?
Code: Select all
Procedure InitWindow_0(WindowWidth, WindowHeight)
Window_0 = OpenWindow(#PB_Any, 0, 0, WindowWidth, WindowHeight, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
Button_0 = ButtonGadget(#PB_Any, WindowWidth - 100, WindowHeight - 30, 90, 25, "Save")
...
EndProcedure
Procedure ResizeGadgetsWindow_0(WindowWidth, WindowHeight)
ResizeGadget(Button_0, WindowWidth - 100, WindowHeight - 30, 90, 25)
...
EndProcedure
InitWindow_0(640, 400)
Repeat
event = WaitWindowEvent()
If event = #PB_Event_SizeWindow
ResizeGadgetsWindow_0(WindowWidth(Window_0), WindowHeight(Window_0))
EndIf
Until event = #PB_Event_CloseWindow
On OS X Cocoa by the way, the system can also take care of things when resizing.
Every View (including Gadgets) responds to setAutoresizingMask: that controls what should happen on a resize of the superview.
I know you are making things cross platform so it's not very relevant but I thought it was nice to mention

Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sun Sep 02, 2012 8:25 am
by luciano
Wilbert,
you are right of corse about debug mode, but I still had made tests without debug
using
Code: Select all
MessageRequester("time",Str(ElapsedMilliseconds()-millisecond))
to show the result
with longer loops, but I could not get significant differenceces .
Since panelgadget is slow to resize by itself I replaced it with another one, my resize routine was:
Code: Select all
Procedure ResizeGadgetsWindow_0()
storedW.i=WindowWidth(Window_0)
storedH.i=WindowHeight(Window_0)
ResizeGadget(Button_0, storedW - 100, storedH- 30, #PB_Ignore, #PB_Ignore)
ResizeGadget(Button_0_1, storedW - 200, storedH - 30, #PB_Ignore, #PB_Ignore)
ResizeGadget(Tree_0, #PB_Ignore, #PB_Ignore, #PB_Ignore, storedH - 50)
ResizeGadget(Panel_0, #PB_Ignore, #PB_Ignore, storedW - 240, storedH - 50)
; ResizeGadget(Button_0, WindowWidth(Window_0) - 100, WindowHeight(Window_0) - 30, 90, 25)
; ResizeGadget(Button_0_1, WindowWidth(Window_0) - 200, WindowHeight(Window_0) - 30, 90, 25)
; ResizeGadget(Tree_0, 10, 10, 210, WindowHeight(Window_0) - 50)
; ResizeGadget(Panel_0, 230, 10, WindowWidth(Window_0) - 240, WindowHeight(Window_0) - 50)
EndProcedure
I also used #PB_Ignore to replace fixed values, but still I got no real timing differences
( with #PB_Ignore it would be easier to manually make adjustements in the init_window procedure, without the need of copying values in the resize procedure)
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sun Sep 02, 2012 11:10 am
by Polo
I've considered your suggestions but they don't change much to the end result

Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sun Sep 02, 2012 12:20 pm
by wilbert
Polo wrote:I've considered your suggestions but they don't change much to the end result

It's up to you of course
There is a big difference in speed however.
With the resize itself taken into the loop the results are already significant (at least on OS X) but when you look at getting the window dimensions itself, the difference is extreme.
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)
Container = ContainerGadget(0, 10, 10, 380, 180)
Start1 = ElapsedMilliseconds()
For i = 0 To 10000000
Width = WindowWidth(0) - 20
Height = WindowHeight(0) - 20
Next
ResizeGadget(0, 10, 10, Width, Height)
End1 = ElapsedMilliseconds()
Start2 = ElapsedMilliseconds()
WindowWidth = WindowWidth(0)
WindowHeight = WindowHeight(0)
For i = 0 To 10000000
Width = WindowWidth - 20
Height = WindowHeight - 20
Next
ResizeGadget(0, 10, 10, Width, Height)
End2 = ElapsedMilliseconds()
MessageRequester("", Str(End1 - Start1) + " vs " + Str(End2 - Start2))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
The results of the test code above on my computer OS X (x64) are
3860 vs 63 that is over 60x faster for not retrieving the width and height all the time.
I know of course in reality the routine isn't called that often but it makes clear that the results are most likely not cached.
Re: Form Designer for Mac/Windows/Linux -5.00b2
Posted: Sun Sep 02, 2012 12:28 pm
by Polo
Ok I add that to the todo list!
