Sure.
When dragging a handle it limits the motion to be along a line.
Line equation:
Y=slope*(x-x0)+y0
Slope calculation uses the ratio of height to width.
Slope = changeInY/changeInX = originalHeight/originalWidth
The slope of the line should be negative for two of the points so I did
(int(mid(“2002”,self.iid,1))-1)
But either of these would be the same
((Self.iid=0 | self.iid=3)?1:-1)
(int((Self.iid+1)/2)%2*2-1)
Basically converting the index 0-3 to a negative or positive in a specified way.
0123 -> 0110 -> 1,-1,-1,1
The handles are laid out like this:
We also need to access the opposite handle to calculate the new size and position, as well as using it for x0,y0 in the line equation. In construct you can do sprite(i).x to access any instance by iid. And if we use 3-i you’ll get the opposite one:
0123 -> 3210
Then the new size would be the absolute value of the difference between the current handle and the opposite handle. The new position would be the midpoint.
Finally the last event positions all the handles around the box that aren’t being dragged.
I was trying to make it compact as possible so those iid tricks are a bit hard to read. The less terse way could look like this:
//make a family with the handles
var slope=0
handle: on drag start
pick family instance 3-handle.iid
-- set slope to (sprite.y-family.y)/(sprite.x-family.x)
handle is dragging
pick family instance 3-handle.iid
-- handle: set y to slope*(self.x-family.x)+family.y
-- sprite: set size to abs(handle.x-family.x), abs(handle.y-family.y)
-- sprite: set position to (handle.x+family.x)/2, (handle.y+family.y)/2
pick handle instance 0
handle is not dragging
-- set pos to sprite.bboxLeft, sprite.bboxTop
pick handle instance 1
handle is not dragging
-- set pos to sprite.bboxRight, sprite.bboxTop
pick handle instance 2
handle is not dragging
-- set pos to sprite.bboxLeft, sprite.bboxBottom
pick handle instance 3
handle is not dragging
-- set pos to sprite.bboxRight, sprite.bboxBottom
It uses a family to pick the opposite handle and is more verbose about how the other handles are positioned. The slope just uses the starting size more or less. However it has a failure case if the size starts at 0,0 then the slope would be NaN. That would have to be handled.