select rectangle area

Ken Ray kray at sonsothunder.com
Sun Mar 2 19:30:29 EST 2008


On Sun, 2 Mar 2008 00:04:04 +0100, R. Hillen wrote:

> Hello,
> 
> I want to select in an application an rectangle area of an image by 
> dragging the mouse from one edge to another, whereby the selected 
> rectangle is visualized.
> 
> As I have no idea how to do it, all tips are welcome! May you help?
> Thank you!

Try this:

- Create a rectangle graphic (I'll call it "SelectRect") that is not 
opaque, and has the line style you want for the "selection rectangle" 
(like a blue single line border perhaps). It doesn't matter where you 
create it, or what it overlaps - it only matters that it is in front of 
the image.

- Hide the rectangle graphic (hide grc "SelectRect")

- Put this script into the image object:

on mouseDown
  set the uStartLoc of me to the mouseLoc
end mouseDown

on mouseMove
  if the uStartLoc of me <> "" then
    put the uStartLoc of me & ","  & the mouseLoc into tRect
    set the rect of grc "SelectRect" to tRect
    if the vis of grc "SelectRect" is false then show grc "SelectRect"
  end if
end mouseMove

on mouseUp
  set the uStartLoc of me to ""
end mouseUp

on mouseRelease
  set the uStartLoc of me to ""
end mouseRelease

Hope this helps,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/



More information about the use-livecode mailing list