Drawing, and saving... how?

BlitzMax Forums/BlitzMax Programming/Drawing, and saving... how?

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.

hah, the guys are playing already ..
http://www.fantasaar.com/forum/index.php/topic,161.msg1102.html#new

Im currently experimenting with a TBank as TList replacement.

-edit- done.
Graphics 800, 600,, , GRAPHICS_BACKBUFFER

Global drawing:TDrawing = TDrawing.Create()
Local FPS:TTicker = New TTicker
SetBlend ALPHABLEND

Incbin "map.png"
map:TImage=LoadImage("incbin::map.png")
SetLineWidth 3

Global mdrawing:TBank = ClearBank(CreateBank(12040)) 
Global mdrawingoffset:Int = 0
Function ClearBank:TBank(bank:TBank) 
	For i:Int = 0 To BankSize(bank) - 1
		PokeByte(bank, i, 0) 
	Next
	Return bank
End Function

Local DrawStart:Int
Local mx:Int
Local my:Int
Local oldmx:Int
Local oldmy:Int

While Not KeyDown(KEY_ESCAPE) 

	Cls() 
	DrawImage(map, 10, 10) 
	SetColor 100, 50, 0
	
	mx = MouseX()'(MouseX()/4)*4
	my = MouseY()'(MouseY()/4)*4
	If MouseDown(1) And mx > 24 And my > 24 And mx < 580 And my < 520
		IsMouseDown=True
		If Not DrawStart Then
			oldmx = mx
			oldmy = my
			DrawStart = True
			addpoint(mx, my)
		Else
			If (mx <> oldmx) Or (my <> oldmy) 
				DrawStart = False
				addpoint(mx, my) 
			EndIf
		EndIf
	EndIf
	
	If Not MouseDown(1) And IsMouseDown
		IsMouseDown=False
		addpoint(0,0)
	End If

	If MouseHit(2) Then
		SaveBank(mdrawing, "mydrawing.dat") 
	EndIf
	
	If MouseHit(3) Then
		mdrawing = LoadBank("mydrawing.dat") 
		'must reset mdrawingoffset by size X?
	EndIf

	draw()
	FPS.update() 
	
	SetColor 255,255,255
	DrawText "FPS: " + FPS.count, 10, 10
	Rem
	DrawText "X: " + MouseX(), 10, 30
	DrawText "Y: " + MouseY(), 10, 50
	EndRem
	Flip 0

Wend

End

Function addpoint( X:Int, Y:Int)
	PokeShort(mdrawing,mdrawingoffset,  Short(X))
	PokeShort(mdrawing,mdrawingoffset+2,Short(Y))
	mdrawingoffset:+4
End Function

Function draw() 
	Local pointer:Int = 0	
	Repeat
		Local x:Int = PeekShort(mdrawing, pointer) 
		Local y:Int = PeekShort(mdrawing, pointer + 2) 
		Local x2:Int = PeekShort(mdrawing, pointer + 4) 
		Local y2:Int = PeekShort(mdrawing, pointer + 6) 
		pointer:+4
		If X = 0 And Y = 0 And X2 = 0 And Y2 = 0 Exit
		If X > 0 And Y > 0 And X2 > 0 And Y2 > 0
			DrawLine(X, Y, X2, Y2)
		End If
	Forever
End Function

Type TTicker
	Field count:Int
	Field timeout:Float = 1
	Field timer:Float
	Field counter:Int
		 
	Method update() 
		If Self.timer < MilliSecs() 
			Self.timer = MilliSecs() + (Self.timeout * 1000) 
			Self.count = Self.counter
			Self.counter = 0
		Else
			Self.counter:+1
		End If
	End Method
End Type