events

BlitzMax Forums/BlitzMax Beginners Area/events

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Try this...
Strict

Type test

	Field canvas:TGadget
	
	Method ev(event:TEvent)
		
		Select event.ID
			Case EVENT_MOUSEENTER
			 	update 1
		
			Case EVENT_MOUSELEAVE,EVENT_GADGETPAINT
				update
		End Select
		
	End Method

	Method update(state:Byte=0)
		SetGraphics CanvasGraphics(canvas)
			SetClsColor 128+state*127,128+state*127,128+state*127
			Cls
		Flip
	End Method
	
	Function create:test(parent:tgadget)
		Local a:test=New test
	a.canvas=CreateCanvas(10,10,20,20,parent)
	Return a
	End Function 

End Type


Local win:TGadget=CreateWindow("o_O",0,0,400,120)

Global t:test=test.create(win)

AddHook EmitEventHook,EventHook

Repeat
	WaitEvent()
	't.ev
	If EventID()=EVENT_WINDOWCLOSE End
Forever

Function EventHook:Object(iId,tData:Object,tContext:Object)
'event is in TDATA
'source --> event.Source (method)
'event ID (EVENT_MOUSEENTER...) --> event.ID

    Local Event:TEvent=TEvent(tData)

	Print "Event : "+event.tostring()
	Print "Source: "+String(event.source)

    Select Event.Source
      Case t.canvas
		t.ev(event)
		Print "event catched..."
        Return Null      
		Default
		Print "No event..."
      End Select
    Return Event         'Event pass through (nothing thats been captured)
End Function

I modified some thing to reach the goal...I extended your TEST type to catch the event, the EventHook function is from this forum - I don't remember who wrote it.