Event Hook Questions
BlitzMax Forums/MaxGUI Module/Event Hook Questions
| ||
I have some questions about event hooks (some of this I posted on the event hook thread in the beginners area, sorry for cross posting, although I have added more to this and I thought this was a better place for it) the hook function, when it is called by an event taking place data contains the last event data. what does context contain? and you only return the data from the hook function if you want another hook function to work on the same event? Are all hooks processed in order of adding them and are they all processed. Also can you make your own events and check for them in the same way you would the default events, such as EVENT_WINDOWCLOSE and EVENT_MOUSEDOWN? Or is it that addhook needs to be used for that? Cheer. |
| ||
Ok, well after some playing with code. I have answered some of my questions. Such as the returning the data parameter does pass to the next hook and they seem to be processed in the order they were setup in. Still not sure what context is for. As for making your own events which are testable by wait event I have knocked up the following code SuperStrict Local window : TGadget = CreateWindow("Test" , 200 , 200 , 400 , 400) Local canvas : TGadget = CreateCanvas(0 , 0 , 300 , 300 , window) ActivateGadget(canvas) Local Hookevent : Int = AllocHookId() Local x : Int, y : Int While WaitEvent() Select EventID() Case EVENT_MOUSEMOVE x = EventX() y = EventY() If x >= 50 And x <= 100 And y >= 50 And y <= 50 CreateEvent(Hookevent , Null , 10 , 0 , x , y) DebugLog "event created" End If Case EVENT_GADGETPAINT SetGraphics(CanvasGraphics(canvas) ) Cls DrawText("X : " + x + " ---- Y : " + y , 0 , 0) Flip Case Hookevent Print "my own event" End Select RedrawGadget(canvas) Wend which I would think would should run throught the last bit of the case when the cursor is moved in the test area. but it does not. Any suggestions or pointers to get me on the right track would be appreciated. Thanks. |
| ||
Ah, So when I create an event I need to use PostEvent to add it to the queue then wait event can use it. It is starting to make sense :D |
| ||
You would use the context to path your own object to the hook. Often this is used to make a connection to the type which added itself to the eventqueue for easier callback handling. AddHook EmitEventHook,MyHook,Self In the hook function you can then cast the context to your type and call a method. If MyType(context) MyType(context).MyMethod Imagine a slider(type) which generates events while moving, creating this type adds itself to the hooks. While moving the slider the hook function detects the events and knows by the context immediately to which instance of this type it belongs and may 'move' something simultaneously on screen. |