Form Designer 5.10

You need some new stunning features ? Tell us here.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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...
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by ts-soft »

I think, it was a good idea to support:

Code: Select all

MenuHeight()
ToolBarHeight()
StatusBarHeight()
for calculation, but not so easy :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Polo »

For now it'll stay like that, I'll change it later maybe!
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Andre »

Polo wrote:For now it'll stay like that, I'll change it later maybe!
No problem :D

I just thought, it will speed up things when using a lot of gadgets, and also the generated code is better readable.
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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 :)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by ts-soft »

This values (WindowWidht, WindowY and so on), stored in the object of windows/gadgets.
This will be only changed on events!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Polo »

I'm not so surprised as it makes sense that PB caches those values ;)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Polo »

Added Toolbar/Statusbar/Menu support for automatic resizing.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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 :wink:
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Polo »

I've considered your suggestions but they don't change much to the end result ;)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post 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 :D

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.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Form Designer for Mac/Windows/Linux -5.00b2

Post by Polo »

Ok I add that to the todo list! :P
Post Reply