I'm having an issue where for some reason, on compile, Blitz thinks there should be an "End Function" in the middle of a variable change.
sx = -1, sy = -1
Also, my code is stuck in the middle of implementing a "snap To" function. If anyone has a better way of doing it or any suggestions then I would love the input.
Edit: Forgive my comments in code... It actually was spaced correctly in my IDE.
Graphics 800,600,24,2
Global x1,y1,x2,y2,x1o,y1o,idc=1,b=0
Global drawing = 0
Global sx=-1,sy=-1
Type rectangle
Field x1,y1,x2,y2
Field r,g,b,a#
Field id
End Type
ClsColor 20,20,20
While Not KeyHit(1)
Cls
For out.rectangle=Each rectangle
Color 0,0,0
Rect out\x1-2,out\y1-2,out\x2+4,out\y2+4,1
Color out\r,out\g,out\b
Rect out\x1,out\y1,out\x2,out\y2,1
Next
Color 250,250,255
If MouseDown(1) Then
If drawing = 0
x1o = MouseX()
y1o= MouseY()
If snap = 1 Then
If sx <> -1 Then x1o = sx
If sy <> -1 Then y1o = sy
EndIf
drawing = 1
EndIf
If MouseX() < x1o Then ;| v (x1o)
x1 = MouseX() ;| Left |
x2 = x1o-x1 ;| |
Else ;| 1,1 | 0,0
x1 = x1o ;| Right |
x2 = MouseX()-x1o ;| |
EndIf ;| >------------------------< (y1o)
If MouseY() < y1o Then ;| |
y1 = MouseY() ;| Up |
y2 = y1o-y1 ;| 1,0 | 0,1
Else ;| |
y1 = y1o ;| Down |
y2 = MouseY()-y1o ;| ^
EndIf ;|
If snap = 1 Then
If sx <> -1 Then x2 = sx
If sy <> -1 Then y2 = sy
EndIf
Rect x1,y1,x2,y2,0
ElseIf Not MouseDown(1) Then
If drawing = 1 Then
drawing = 0
cur.rectangle = New rectangle
cur\x1 = x1
cur\x2 = x2
cur\y1 = y1
cur\y2 = y2
cur\id = idc : idc=idc+1
cur\r = Rnd(0,200)
cur\g = Rnd(0,200)
cur\b = Rnd(0,200)
cur\a# = 1
EndIf
EndIf
For mine.rectangle=Each rectangle ; / Debug
b=b+1 ;|
Text 5,5+(15*b), b + ": " + mine\id ;|
Next ;|
b=0 ;|
If KeyHit(44) Then ; / Z Undo
del.rectangle=Last rectangle ;|
Delete del ;|
EndIf ;|
If KeyDown(42) Then ; / Left select for snap
snapto(50) ;|
Line 0,sy,1000,sy ;|
EndIf ;|
Flip : Delay 9
Wend
Function snapto(t=1050)
t1 = MouseX()
t2 = MouseY()
snap = 0
sx = -1, sy = -1
Local cx=t,cy=t
Local ch1=0,ch2=0
For sn.rectangle = Each rectangle
If Abs(sn\x1-t1) < cx Then
cx = sn\x1
snap = 1
ch1 = 1
EndIf
If Abs(sn\x2-t1) < cx Then
cx = sn\x2
snap = 1
ch1 = 1
EndIf
If Abs(sn\y1-t2) < cy Then
cy = sn\y1
snap = 1
ch2 = 1
EndIf
If Abs(sn\y2-t2) < cy Then
cy = sn\y2
snap = 1
ch2 = 1
EndIf
Next
If ch1 = 1 Then sx = cx
If ch2 = 1 Then sy = cy
End Function
Last edited 2011
|