Mouse Rectangle

BlitzPlus Forums/BlitzPlus Beginners Area/Mouse Rectangle

Doggie(Posted 2010) [#1]
If MouseHit(1)
mx=	(MouseX()-232)
my=	(MouseY()-100)
End If

If MouseDown(1)
Rect mx,my,(MouseX()-232),(MouseY()-100),0
End If


Does not produce a rectangle sized by mouse. Why not?
Not like I thought it would actually work but unsure what is missing.
Thanks!

oops. meant to post in Blitz3D but should be the same I'd think.


Sauer(Posted 2010) [#2]
I'm not entirely sure what you're trying to accomplish, but if you want something like a high lighter (like when you press and click dragging on your desktop) then this will work:

If MouseHit(1)
		mx=	MouseX()
		my=	MouseY()
	End If
	
	If MouseDown(1)
		Rect mx,my,MouseX()-mx,MouseY()-my,0
	End If


Your offsets were a bit funky.

Can you post more specifically what you are trying to accomplish?


Doggie(Posted 2010) [#3]
That's about the same thing. I'm trying to make a rubberbanding function to draw a rectangle so that the user can drag the rectangle the size he desires then when he lets go of mouse(1) it draws the final product.
It will need to preserve the contents beneath the rubberbanding area or it will be of no value.
Figure I can apply the same/similar code to ovals and lines...

thanks for the reply!


Doggie(Posted 2010) [#4]
Graphics 800,600
SeedRnd MilliSecs()
Image=CreateImage(800,600)
For i=0 To 1000
	Color Rand(155),Rand(155),Rand(155)
	Rect Rand(0,800),Rand(0,600),Rand(0,60),Rand(0,60)
Next
GrabImage image,0,0
Color 255,255,255
Global RubberX%,RubberY%
RubberX=-1
Repeat
	Cls
	DrawImage image,0,0
	If MouseDown(1) Then
		If RubberX=-1 Then
			RubberX=MouseX()
			RubberY=MouseY()
		Else
			DrawNotFilledRect RubberX,RubberY,MouseX(),MouseY()
		EndIf
	Else
		RubberX=-1
	EndIf
	Flip 
Until KeyHit(Key_Escape)

Function DrawNotFilledRect(X1%, Y1%, X2%, Y2%)
Line x1,y1,x1,y2
	Line x2,y1,x2,y2
	Line x1,y1,x2,y1
	Line x1,y2,x2,y2
End Function



Stamm(Posted 2010) [#5]
Doggie,
why do you use an extra function to draw a hollow rectangle? its already included in the Rect function


Matty(Posted 2010) [#6]
I'm guessing the reason is because the Rect function uses two x/y coordinates and a width/height parameter, while his function draws the rect between 4 x/y coordinates...the rect function does not work if you need to pass -ve width/height parameters to it.


Stamm(Posted 2010) [#7]
oh yes thats right