Event hooks a couple of questions

BlitzMax Forums/MaxGUI Module/Event hooks a couple of questions

peltazoid(Posted 2008) [#1]
When you have created an event hook say for scrolling a canvas so it updates realtime. Do you need to place all your other event handling inside this hook function or can you still have a waitevent() loop?

I have tried this and the event structure in the while waitevent() loop does not seem to get executed but the hook function does.

If my understanding is correct, the hook function is called when an event is generated and then when it exits control is passed back to waitevent?

As I write this I'm beginning to realise that the item in the event queue may have been removed due to the hook so the waitevent loop never gets the event. so using peekevent in the hook would negate this to check if it is an event you need and if it is to remove it from the queue using currentevent?

Am i on the right tracks here?

Cheers.


Mark Tiffany(Posted 2008) [#2]
The event hook should return the event if it hasn't used it, return Null otherwise. Here's an example from my memchecktool code:

Function _memcheck_hook:Object(id:Int , data:Object , context:Object) 
	memcheck_e = TEvent(data) 
	If memcheck_e.source = memchecktimer And memcheck_e.id=EVENT_TIMERTICK Then
		ShowMem() 
		Return Null
	ElseIf memcheck_e.source = memcheckbutton And memcheck_e.id = EVENT_GADGETACTION Then
		DebugLog "Memory Use Reset"
		ShowMem()
		GCCollect() 
		memcheckbase = GCMemAlloced()
		ShowMem() 
		GCCollect()
		memcheckbase = GCMemAlloced() 
		ShowMem()
		Return Null
	Else
		Return data
	End If
End Function

Notice that if I handle the event, it Return Null. If I don't, I return the data.

Also, note that you can create many eventhooks - you can have more than one (which your post above implied you think you are restricted to).


Mark Tiffany(Posted 2008) [#3]
Actually, just noticed an improvement I can make to that code...as I know this is the ONLY bit of code that should care about those two eventsource's, I should ensure I Return Null for *ANY* eventid. By returning data, it means all other eventhooks & waittimer will run, making for potentially inefficient code...


peltazoid(Posted 2008) [#4]
Right, Thanks :D

That does make it a lot clearer. I did think it would be better to have many hooks, but my understanding of setting a hook up made it seem that in practice only one could be present at any time.

Thanks again :)