Resizing objects...

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MCla
Posts: 11
Joined: Sat Feb 20, 2010 5:37 am

Resizing objects...

Post by MCla » Mon Aug 30, 2010 8:05 am

I am looking for a reusable control that uses handles to change the size of an object (as in most drawing programs).
1- click the object to visualize its handles and borders (this creates/shows a rectangles with little handles in corners and middle of each border...
2- move the handles to resize (with possibly shift-key modifier to keep proportions)
3- resize the object when mouse is released.
Any ideaL

There might be something on revonline but the server seem to be acting up recently.

cheers,

Michel

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9680
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Resizing objects...

Post by dunbarx » Mon Aug 30, 2010 3:49 pm

I was playing for the first time with the "mouseMove" command when I first picked up Rev. I made a small button named "handle", about 10 X 10. I made another button (btn 2), about 100 X 100 and put all this into its script:

Code: Select all

local tCorner,tRect

on mouseMove x,y
   if the mouse is down then
      switch tCorner
         case "topRight"
            set the rect of btn 2  to  item 1 of tRect & "," & y & "," & x & "," & item 4 of tRect
            break
         case  "topLeft"
            set the rect of btn 2  to x & "," & y & "," & item 3 of tRect & "," & item 4 of tRect
            break
         case "botLeft"
            set the rect of btn 2  to  x & "," & item 2 of tRect & "," & item 3 of  tRect & "," & y
            break
         case "botRight"
            set the rect of btn 2 to  item 1 of  tRect  & "," & item 2 of tRect & "," & x & "," & y
            break
      end switch
       set the loc of  btn "handle" to x & "," & y 
   end if
end mouseMove

on mouseDown
   put the rect of btn 2 into tRect
   put whichCorner(the mouseLoc,tRect) into tCorner
end mouseDown

function whichCorner tMouseLoc,tRect
   switch 
      case abs(item 1 of tMouseLoc - item 3 of tRect) < 25 and abs(item 2 of tMouseLoc - item 2 of tRect) < 25
         show btn "handle"
         return "topRight"
         break
      case abs(item 1 of tMouseLoc - item 1 of tRect) < 25 and abs(item 2 of tMouseLoc - item 2 of tRect) < 25
         show btn "handle"
         return "topLeft"
         break
      case abs(item 1 of tMouseLoc - item 1 of tRect) < 25 and abs(item 2 of tMouseLoc - item 4 of tRect) < 25
         show btn "handle"
         return "botLeft"
         break
      case abs(item 1 of tMouseLoc - item 3 of tRect) < 25 and abs(item 2 of tMouseLoc - item 4 of tRect) < 25
         show btn "handle"
         return "botRight"
         break
      case var
         return ""
   end switch
end whichCorner

on mouseUp
   put "" into tCorner
   hide btn "handle"
end mouseUp

on mouseEnter
    put the rect of btn 2 into tRect
end mouseEnter
Seems to work...

Craig Newman

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4012
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Resizing objects...

Post by bn » Tue Aug 31, 2010 4:29 pm

mcla,

have a look at the stack I uploaded. It uses a little different approach from Craig. I uses a group that snaps to an image or a graphic or a field (locktext true). It snaps to the control if you click with the Alt-key down (Windows) or the Option-key down (Mac). Right now it has a handle in the lower right corner and at the left side.

tell me if it is something of this sort what you had in mind.
regards
Bernd

Addendum: see below for a new version of the stack that avoids the problem of an error occuring when clicking on a resize handle the first time. See also below for an explanation why (it is the use of the long ID which includes the path to the file.)
Attachments
Resize with handle.rev.zip
(5.64 KiB) Downloaded 290 times
Last edited by bn on Thu Apr 05, 2012 11:48 am, edited 2 times in total.

MCla
Posts: 11
Joined: Sat Feb 20, 2010 5:37 am

Re: Resizing objects...

Post by MCla » Tue Aug 31, 2010 4:45 pm

Thanks to both of you.

I started from both examples and did a working resizing group. To be uploaded soon.

cheers,

Michel

WinstonJenks
Posts: 36
Joined: Fri Jan 01, 2010 12:11 am

Re: Resizing objects...

Post by WinstonJenks » Sun Sep 19, 2010 10:05 am

I had to do this too. Given a group with a bunch of graphics inside of it, I set customKeys (one for each item in the group) in a specific customPropertySet with each key holding the relative location and relative height and width within the group (normalized from 0 to 1). Then a resize handler can find the new locations, heights and widths from this data and the current rect of the group. It's kind of a pain, but the nice thing is that you do not lose any resolution when the objects get small and then real big again. Lines are the biggest pain because you do not want the width of a vertical line to grow as the group grows--they get special handling inside the resize script. It does not handle nested groups, but only because I just thought of that now...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4012
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Resizing objects...

Post by bn » Thu Apr 05, 2012 11:44 am

Hi,

Billworld made me aware of a malfunction in the stack I posted above. The first time you start the stack on your computer and click right away on a resize handler it will throw an error. This is due to the use of a long ID in a custom property that is used to identify the control whose size is to be changed. The long ID of an object breaks on a different machine since it uses the path to the stack also.
Once you Alt-Click an object this is not longer a problem.
To work around this I resorted to using the id of a control. That should avoid the problem.

Here is the new version of the stack.
Resize with handle_0_0_2.livecode.zip
(5.58 KiB) Downloaded 256 times
If you have trouble using the stack please give feedback.

Kind regards

Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4012
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Resizing objects...

Post by bn » Thu Apr 12, 2012 10:33 pm

Hi,

lolokiki made me aware of the fact that Resize with handle does not work correctly with a player object on Windows.
(in this thread: http://forums.runrev.com/phpBB2/viewtop ... =15#p54817 )

I changed the code, which was also cleaned up and commented and post the new version here too in case anyone looks for the stack here
Bildschirmfoto 2012-04-12 um 22.13.15.png
Bildschirmfoto 2012-04-12 um 22.13.15.png (10.49 KiB) Viewed 6098 times
Resize with handle_0_0_4.livecode.zip
(6.25 KiB) Downloaded 251 times

Kind regards

Bernd

Post Reply

Return to “Talking LiveCode”