Please Use GetGadAttribute Only When Really Needed...

You need some new stunning features ? Tell us here.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Please Use GetGadAttribute Only When Really Needed...

Post by fsw »

Hello Polo,
Here you ask for more input in regards to ideas/requests etc.

Well here is one:
In the ResizeGadgetsWindow_0() procedure you call GetGadAttribute() once or twice (depending on the resize setting) for each gadget.
In a project I'm trying to port over to the form designer I have over 40 gadgets on the first PanelItem which results in a lot of calls of GetGadAttribute().
This adds to the flickering that is seable anyhow (because of the Panel) while resizing the window.

Maybe it's a good idea to call GetGadAttribute() once for the height, once for the width and fill variables with it and use the variables for each gadget instead.

BTW: you will know if there are more calls like this that would profit (speed wise) from a code refactoring.

Thanks for reading

I am to provide the public with beneficial shocks.
Alfred Hitshock
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Please Use GetGadAttribute Only When Really Needed...

Post by Polo »

Thanks fsw - are you able to provide a code that shows the difference in flickering? ie with and without getgadgetattribute?
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Please Use GetGadAttribute Only When Really Needed...

Post by fsw »

Sorry can't do it, the form designer changes the code back to what he thinks should be done...
Tried to remove the form file from the project in order to manipulate it manually, but removing the form file crashes PB5.3b3.

However, in the resize procedure GetGadgetAttribute() is called tons of times (69 times to be precise), which should be avoided.
And this is a panel with only 1 panel item populated. There will be more panel items with their own collection of gadgets...

Thanks

EDIT
Maybe it's even better to refactor the code to utilize BindEvent()...

I am to provide the public with beneficial shocks.
Alfred Hitshock
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Please Use GetGadAttribute Only When Really Needed...

Post by BorisTheOld »

fsw wrote:......However, in the resize procedure GetGadgetAttribute() is called tons of times (69 times to be precise), which should be avoided.
And this is a panel with only 1 panel item populated. There will be more panel items with their own collection of gadgets......
We use an in-house resize engine in all our applications, and reduce the potential for flickering by only resizing visible GUI objects. When a child object becomes visible it does a quick check of its parent to see if resizing is necessary. So, for example, when resizing a Panel, only the visible tab is resized. The others are only resized if they become the top-most tab.

In applications with thousands of active GUI objects, this strategy makes flickering a non-issue.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Please Use GetGadAttribute Only When Really Needed...

Post by PB »

> We use an in-house resize engine in all our applications

You know you'll have to sell your engine one day, right? ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Please Use GetGadAttribute Only When Really Needed...

Post by fsw »

@Boris,
thanks for your input.

However, the issue is not how to do it, but while utilizing the official FormDesigner the resizing becomes soo 90'...
(as I have my own GUI library and there are several good code snippets around in this forum on how to resize properly)

Now I need to revisit my decision to transfer my biggest project to the official FormDesigner or not; which could mean doing gui design manually again (as I did for the last 13 years with PureBasic)

Suppose there is always something.

BTW Boris:
I have only one big program running in a corporate environment but it seems you have a broad collection of PureBasic software running...

I am to provide the public with beneficial shocks.
Alfred Hitshock
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Please Use GetGadAttribute Only When Really Needed...

Post by Polo »

fsw wrote:Now I need to revisit my decision to transfer my biggest project to the official FormDesigner or not; which could mean doing gui design manually again (as I did for the last 13 years with PureBasic)
I hope you will, the point of the designer is to make it easier for you :)
I understand the problem with the getgadgetattribute but I would need a small .pb code that shows clearly it add flickering, as I'm not quite sure it does?
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Please Use GetGadAttribute Only When Really Needed...

Post by fsw »

BorisTheOld wrote:...When a child object becomes visible it does a quick check of its parent to see if resizing is necessary. So, for example, when resizing a Panel, only the visible tab is resized. The others are only resized if they become the top-most tab.

In applications with thousands of active GUI objects, this strategy makes flickering a non-issue.
This is a very good approach, good for you :twisted:

This reminds me that if BindEvent() is used in connection with resizing it might not look out for visibility...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Please Use GetGadAttribute Only When Really Needed...

Post by fsw »

@Polo
Understood, maybe the following helps.

The following resize procedure was created by the form designer:

Code: Select all

Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(Window_0)
  FormWindowHeight = WindowHeight(Window_0)
  ResizeGadget(MainPanel, 10, 10, FormWindowWidth - 20, FormWindowHeight - 20)
  ResizeGadget(SEARCH_SearchBox_1, 340, 30, GetGadgetAttribute(MainPanel,#PB_Panel_ItemWidth) - 750, 25)
  ResizeGadget(SEARCH_SearchBox_2, 400, GetGadgetAttribute(MainPanel,#PB_Panel_ItemHeight) - 48, GetGadgetAttribute(MainPanel,#PB_Panel_ItemWidth) - 810, 25)
  ResizeGadget(SEARCH_SearchBox_3, 400, GetGadgetAttribute(MainPanel,#PB_Panel_ItemHeight) - 78, GetGadgetAttribute(MainPanel,#PB_Panel_ItemWidth) - 810, 25)
  ;...
  ;... tons of other gadgets are resized...
EndProcedure
Now imagine the form designer would do this:

Code: Select all

Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  Protected MainPanelItemWidth, MainPanelItemHeight

  FormWindowWidth = WindowWidth(Window_0)
  FormWindowHeight = WindowHeight(Window_0)

  MainPanelItemWidth = GetGadgetAttribute(MainPanel,#PB_Panel_ItemWidth)
  MainPanelItemHeight = GetGadgetAttribute(MainPanel,#PB_Panel_ItemHeight)
  
  ResizeGadget(MainPanel, 10, 10, FormWindowWidth - 20, FormWindowHeight - 20)
  ResizeGadget(SEARCH_SearchBox_1, 340, 30, MainPanelItemWidth - 750, 25)
  ResizeGadget(SEARCH_SearchBox_2, 400, MainPanelItemWidth - 48, MainPanelItemHeight - 810, 25)
  ResizeGadget(SEARCH_SearchBox_3, 400, MainPanelItemWidth - 78, MainPanelItemHeight - 810, 25)
  ;...
  ;... tons of other gadgets are resized...
EndProcedure
And all of a sudden GetGadgetAttribute() is only called twice not 69 times (on my first PanelItem...).

Every call of GetGadgetAttribute() adds latency to the main loop, which makes stuff flicker more.
Hope you get the idea.

BTW: if you now only redraw gadgets on the active PanelItem you will be "THE MAN!" (and make Boris jealous) :mrgreen:
(just make sure that when another PanelItem is activated the gadgets are resized...)

I know you can do it :D

I am to provide the public with beneficial shocks.
Alfred Hitshock
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Please Use GetGadAttribute Only When Really Needed...

Post by Polo »

Ok I'll try to change the code, can't guarantee it'll be done for 5.30 as it's quite some work! :)
Post Reply