Program Drawing a Rectangle

Klaus Major klaus at major-k.de
Wed Mar 16 13:11:07 EST 2005


Hi David,

> Hi,
>
> I would like to draw a rectangle specified by the mouse down/up 
> position. I have a predefined Graphic Rectangle "Bounding Rect" which 
> the user clicks in to draw the rectangle. The script for 
> "BoundingRect" is as follows:
>
> global gMouseRawX
> global gMouseRawY
>
> on mouseDown
> put the mouseH into gMouseRawX
> put the mouseV into gMouseRawY
> end mouseDown
>
> on mouseUp
> put the mouseH into myMouseRawX
> put the mouseV into myMouseRawY
>
> set the style of templateGraphic to rectangle
> set the left of templateGraphic gMouseRawX
> set the top of templateGraphic gMouseRawY
> set the right of templateGraphic myMouseRawX
> set the bottom of templateGraphic myMouseRawY
> create graphic
>
> end mouseUp
>
> This draws a rectangle ok, but it is offset from where I expect it to 
> be. I obviously need to add on an offset, but not sure which offset to 
> add?

don't know why there is this offset, maybe setting the top and left 
does NOT set the widht and height?,
but this one DOES work AND is a lot shorter :-)

global gMouseRawX
global gMouseRawY

on mouseDown
   put the mouseH into gMouseRawX
   put the mouseV into gMouseRawY
end mouseDown

on mouseUp
   set the style of templateGraphic to rectangle
   set the rect of templateGraphic to gMouseRawX,gMouseRawY, the mouseH, 
the mouseV
   create graphic
end mouseUp

> Could anyone help?
> Thanks in advance
> Dave

Regards

Klaus Major
klaus at major-k.de
http://www.major-k.de



More information about the use-livecode mailing list