我正在构建一个 LiveCode 堆栈,并希望将拖放添加到我的应用程序中。特别是,我希望能够单击一个图像并将其拖动到第二个位置。
我还想向用户提供反馈,他们实际上是在拖动。缩略图将是理想的。
我知道如何将光标悬停在图像上时更改光标:
on mouseEnter
lock cursor
set the cursor to "hand"
end mouseEnter
on mouseLeave
unlock cursor
end mouseLeave
在 LiveCode 中拖动是通过各种可用的拖动消息完成的。如果您的堆栈上有两个图像,例如-
图像 1 的脚本
on dragStart
set the dragData["text"] to the text of image 1
set the dragImage to the id of me
end dragStart
图 2 的脚本
on dragEnter
set the dragaction to "copy"
end dragEnter
on dragDrop
set the text of the target to the dragData["text"]
end dragDrop
单击并拖动图像 1 时,其文本(内容)将放入 dragData 数组中,其拖动操作设置为复制,拖动图像设置为自身的图像 ID。这是指示您正在拖动的内容的透明图像。
在图 2 中,当用户拖动并输入图像时,它将 acceptDrop 设置为 true,当用户释放鼠标(dragDrop)时,图像的文本设置为 dragData["text"] 数组
虽然拖放命令和消息套件丰富而强大,但如果您需要做的就是在应用程序窗口中将某些内容从一个位置移动到另一个位置,请不要忽视简单的 grab 命令。它允许您向下单击对象并让对象跟随鼠标指针,直到您释放鼠标按钮。例如,要拖动的对象中的以下脚本运行良好。
on mouseDown
grab me
end mouseDown
on mouseUp
# do whatever evaluation you need to do here
# e.g., check to see whether the drop location is a valid target area
# Here is one way to do it:
if the location of the target is within the rect of graphic "hotspot" then
put "That's right!" into fld "feedback"
end if
# If you are dragging to an irregular target area do this instead:
if within(graphic "irregularPoly",the loc of the target) then
put "That's right!" into fld "feedback"
end if
end mouseUp