Paint program help - drawing rectangles, restoring

BlitzMax Forums/BlitzMax Beginners Area/Paint program help - drawing rectangles, restoring

OK thanks everyone. I got it working - well under Windows anyway. It seems I had it working already, I just didn't know it as there seems to be a bug in the Blitzmax Linux version. The same code works under one OS and not the other.

Thanks again for your help.

I'll post the code here just incase anyone can spot the problem. It's the drawimage line with the *** comment ** that causes problems under Linux, an exception error occurs.

-------- cut here ----------------------------

Strict

' ------------ vars --------------------
' Screen res
Local screenwidth=800
Local screenheight=600

' Mouse coords
Global ox,oy, mx, my

' shape
Local width, height

' Colour
Global red, green, blue

' types of tools
Const PEN=1, RECTANGLE=2
' current tool
Local currenttool = PEN
' holds current keypress
Local key


'set graphics mode
'Graphics screenwidth,screenheight,16
Graphics screenwidth,screenheight,0

' set a buffer up big enough to hold the whole screen (so we can restore the image during drawing ops such as rectangle
Local screenbuf:timage = CreateImage(screenwidth,screenheight)


' ------------ main loop --------------------

red = 255
green = 100
blue = 100

'set the default colour
SetColor (red,green, blue)

' take an initial snapshot of the canvas
GrabImage screenbuf,0,0

While Not KeyHit(KEY_ESCAPE)


' See if key has been pressed or a tool clicked on
key = GetChar()

Select key
' p or P pressed, PEN mode
Case 80
currenttool = PEN
Case 112
currenttool = PEN
' r or R pressed, RECTANGLE mode
Case 82
currenttool = RECTANGLE
Case 114
currenttool = RECTANGLE
End Select


'update previous mouse coords
ox = MouseX()
oy = MouseY()

' Left mouse button pressed
While MouseDown(1)

' Get mouse coords
mx = MouseX()
my = MouseY()

Select currenttool
Case PEN
'Plot a pixel
Plot mx,my
Case RECTANGLE
' draw a rect
width = mx-ox
If width < 0 Then width = 1
height = my-oy
If height < 0 Then height = 1
Cls
' **** comment/uncomment this next line for a crash under linux *****
DrawImage screenbuf ,0,0,0
DrawRect(ox,oy,width,height)
End Select

' Flip the buffers
Flip

EndWhile

Select currenttool
Case RECTANGLE
' take a snapshot of the screen proir to the next draw operation if drawing rects, ovals etc
GrabImage screenbuf,0,0,0
End Select

' end of main loop
Wend