How do I change its location? I would prefer to specify the new position of its top left corner but the rectangletweak( function is acceptable if it’s the only way to do it.
I would probably use the changeobject statement for this, with the rectangletweak( function. This is exactly the sort of application these were designed for.
let topleft = 100
let topright = 200
changeobject "TextDisplayObject",
"rectangle",rectangletweak(objectinfo("rectangle","TextDisplayObject"),
"x", topleft,
"y", topright)
For some reason Discourse doesn’t understand this link to the rectangletweak( function. But it’s in the Help file.
I think this will work.You didn’t say how you were going to specify the new position, but you could do it with a mouse click. I assumed you could put a large white rectangle behind the other objects on the form, and put this code in the procedure for the rectangle, then an option-click will move the object to the spot where you clicked:
if optionclick()
moveobjects "TextDisplayObject", "=", v(xytoxy(info("click"),"s","f"))-rtop(objectinfo("rectangle","TextDisplayObject")),
h(xytoxy(info("click"),"s","f"))-rleft(objectinfo("rectangle","TextDisplayObject"))
endif
You need the xytoxy function because mouse clicks are returned in screen relative coordinates but form relative coordinates are needed. I see Jim’s solution but don’t see why one is preferable.
It’s purely personal preference. Under the hood, the moveobjects statement is a custom statement that uses changeobjects and the rectangleadjust( function to do the actual work.