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.

Strict

Type Test
	Global test_List:TList = New TList
	Global Act_Can:Test = Null

	Field canvas:TGadget
	
	Function Hook:Object(id,data:Object,context:Object)
	Local ev:TEvent=TEvent(data)
	If Not ev Return data
	'Print ev.toString()
		Select ev.id
			Case Event_MouseEnter
				Act_Can = GetSelectedCanvas(Ev)
					If Act_Can <> Null Then
						Act_Can.Update(1)
					EndIf
			Case Event_MouseLeave
					If Act_Can <> Null 
						Act_Can.Update(0) 
						Act_Can = Null
					EndIf
			Case Event_TimerTick
				For Local T:Test = EachIn Test.Test_List
					RedrawGadget T.Canvas
				Next
		End Select
			
	Return data
	
	End Function
	
	Function GetSelectedCanvas:Test(Event:TEvent)
		For Local T:Test = EachIn Test.Test_List
			If T.Canvas = Event.Source Then
			Return T
			End If
		Next
		Return Null
	End Function

	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(x,y,w,h,parent:TGadget)
		Local a:Test=New Test
		a.canvas=CreateCanvas(x,y,w,h,parent)
		a.Update(0)
		Test.Test_List.Addlast(A)
		AddHook EmitEventHook,Test.Hook,A,0
		Return a
	End Function

End Type

Function createtest:Test(x,y,w,h,parent:TGadget)
	Return Test.Create(x,y,w,h,parent)
End Function

Local win:TGadget=CreateWindow("o_O",0,0,640,480)

Local t:Test=createtest(32,32,48,24,win)
t:Test=createtest(32,60,48,24,win)
t:Test=createtest(32,88,48,24,win)




Repeat
	WaitEvent()
	If EventID()=EVENT_WINDOWCLOSE End
Forever



This is a small workaround, I hope this helps you