event loop and canvas buffer

BlitzPlus Forums/BlitzPlus Programming/event loop and canvas buffer

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.

app=CreateWindow("bla",0,0,640,480)

Global cnv=CreateCanvas(32,32,400,300,app),r=255,g=255,b=255

timer=CreateTimer(30)

Global txt=CreateTextField(32,340,64,24,app)


button1=CreateButton("new color",128,340,64,24,app)

Repeat
	WaitEvent()
	If EventID()=$803 quit=True
	If EventID()=$4001 ; timer
		updatecanvas()
	EndIf
	
	If EventID()=$401
		If EventSource()=button1
			r=Rnd(255)
			g=Rnd(255)
			b=Rnd(255)
		EndIf
		
	EndIf
	
Until quit

End

Function updatecanvas()
	SetBuffer CanvasBuffer(cnv)
		Cls
		
		; random stuph
		Color r,g,b
		For k=0 To 31
			Rect Rnd(200),Rnd(150),100,100,True
		Next
		
		Color 255,255,255
		
		Text 0,0,TextFieldText$(txt)
		
	FlipCanvas cnv
End Function