How many hooks can/should you use?

BlitzMax Forums/MaxGUI Module/How many hooks can/should you use?

NoOdle(Posted 2012) [#1]
I have recently looked into hooks and realised these are needed to redraw canvas' below moving/resizing windows and other nifty tricks.

My question is this, how many hooks does an application need? Does having multiple cause significant issues?

The application I am making has 2 canvas', group boxes with device information (gps and proton magnetometer) and timers to handle streaming serial data (rs232). Also the app will contain the standard Menu, Toolbar, Statusbar etc and various windows that open and close to change application settings and canvas view options.

The reason I ask is because I saw a post in the code archives by JoshK. He is using multiple hooks seperated into nice clean managable chunks. See: http://www.blitzbasic.com/codearcs/codearcs.php?code=2391

Is it safe to assume that I can use hooks for each type of gadget or should I limit them?

Are there some things that can be controlled in the usual manner without hooks? For example, I don't think a toolbar requires a hook... but I could be wrong.

Last edited 2012


jsp(Posted 2012) [#2]
My question is this, how many hooks does an application need? Does having multiple cause significant issues?


It depends on your application, some don't need any hook at all. Using more than one hook is no problem, but is a little different way it works.

The application I am making has 2 canvas', group boxes with device information (gps and proton magnetometer) and timers to handle streaming serial data (rs232). Also the app will contain the standard Menu, Toolbar, Statusbar etc and various windows that open and close to change application settings and canvas view options.

So you should have at least one hook for all stuff which needs immediately refreshed.

The reason I ask is because I saw a post in the code archives by JoshK. He is using multiple hooks seperated into nice clean managable chunks. See: http://www.blitzbasic.com/codearcs/codearcs.php?code=2391


That is just one possible way to go

Is it safe to assume that I can use hooks for each type of gadget or should I limit them?


Of course that is possible, just be careful that no endless loops occur (event related).

Are there some things that can be controlled in the usual manner without hooks? For example, I don't think a toolbar requires a hook... but I could be wrong.

Most gadgets don't need a hook! With a hook you can react immediately on a certain event which gives a lot better GUI feeling, redraw of a canvas, moving of a slider, resizing a window to name a few. It is also possible to have a more OOP approach with hooks than without, but for small forms it is quite irrelevant, the more important for bigger forms.


skn3(Posted 2012) [#3]
I use one hook per unique type of "gadget". I have created about 20 different custom gadgets. One example is a gadget proxy that doubles as a dialogue window that can be extended. There is a single hook for all dialogue gadgets that will filter events and pass them onto the dialogue gadget in question.

I have a property grid gadget, a special canvas gadget and many more. Each has a hook to manage and pass on events to their respected objects.

If you are only ever going to have a limited number of gadgets and not much complexity in your app then it is probably easier to just use one hook for everything.

Last edited 2012


NoOdle(Posted 2012) [#4]
Thank you jsp for answering all my queries. Very helpful! Im using LogicGUI for making my app, so much easier using this than trying to start out by hand! Great program.

Cheers skn3[ac] good to know, I can probably get away with one hook by the sounds of things. Might as well keep it simple.

Last edited 2012

Last edited 2012


skn3(Posted 2012) [#5]
No problem, it sounds like you are going with the sensible option! If you are planning to have something like a preference window or popup editor windows then it would be easier in the long run to have a hook just for these so you don't have to trawl through one gigantic select statement as your program code grows larger with more and more features!


jsp(Posted 2012) [#6]
Hi Noodle, just looked up your version number and you are up to date, that means you can leave all the hard work to Logic Gui.
Logic Gui comes with a base type which does the hook automatically for you!
Check out in the Logic Gui Example folder all the WindowType... examples. It will show how it works.
You can get hooked independent types from Panels and Windows (with other stuff on top of course) and you can create as many instances as you need in your program.
It is may a bit more difficult because then you are going OOP with your GUI, but nice in the long run.

The standard is a normal WaitEvent() loop, but when you chose in the Properties Editor, Application on the left side and in the tabber on the right 'Gadget', you will see the Option 'Type Creation' , just check this option to have it done automatically. Make a copy of your form and experiment with it.

There is also a section at the end of the User Manual which cares about the type structure, so one better understands what Logic Gui has created and how to use it.
There are different chapters which can be important:
8.2.4.2 Gadgets , Look for the Type Creation section
12.2 How to ..
13.2 TForm
13.3 TFormTimer

If this is too much or you are unsure what all this means just let me know.


JoshK(Posted 2012) [#7]
I use hundreds, maybe thousands of hooks.