如何在LiveCode应用程序中拖放项目?

时间:2014-03-03 15:30:02

标签: livecode

我正在构建一个LiveCode堆栈,并希望将拖放添加到我的应用程序中。特别是,我希望能够点击一个图像并将其拖到第二个位置。

我还想向用户提供他们实际上拖动的反馈。缩略图是理想的。

我知道当我将鼠标悬停在图片上时如何更改光标:

on mouseEnter
   lock cursor
   set the cursor to "hand"
end mouseEnter

on mouseLeave
   unlock cursor 
end mouseLeave

2 个答案:

答案 0 :(得分:5)

在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数组中,其dragAction设置为copy,拖动图像将设置为自身的图像ID。这是透明图像,表示您正在拖动的内容。

在图像2中,当用户拖动并输入图像时,它将acceptDrop设置为true,当用户释放鼠标(dragDrop)时,图像文本被设置为dragData [" text& #34;]数组

答案 1 :(得分:2)

虽然拖放命令和消息套件丰富而强大,但如果你需要做的就是在应用程序窗口内部从一个位置移动到另一个位置,不要忽略简单的抓取命令。它允许您单击对象并使对象跟随鼠标指针,直到释放鼠标按钮。例如,要拖动的对象中的以下脚本运行良好。

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