Your techniques for MaxGUI

BlitzMax Forums/BlitzMax GUI Programming/Your techniques for MaxGUI

I understand that you are casting the context object as a TSmartSpinner, and then passing data cast as a TEvent to its 'ev' method. But what does the condition if TSmartspinner(context) test?






Method New()
AddHook EmitEventHook,eventhook,Self
End Method



The New method of the spinner takes the spinner itself (Self) as Object to the Hook and will be present there as Context.



Function eventhook:Object(id:Int,data:Object,context:Object)
If TSmartspinner(context) TSmartspinner(context).ev TEvent(data);Return data
EndFunction


EDIT to be more precise:
During processing of an event every hooked function will be checked.
When the event comes to the Spinner Hook function the instance we added via 'Self' is present in the Context. When we cast the context - stored as object - “Tsmartspinner(context)” to our original TSmartspinner, we are able to access the TSmartspinner methods (we call the .ev method of that type) and check if the current event we are processing were from this 'Self' instance.



Method ev(event:TEvent)

If event.source=canvas

If event.id=EVENT_GADGETPAINT update



When the event enters the ev method the first thing is to check which of the spinners this events belongs to. This is done here with “If event.source=canvas”. The canvas was set before in the type
Field canvas:tgadget

So, every spinner checks if his own canvas was producing the event. If it's matches then it processes the event....

Hope this helps