LCMark wrote: ↑Thu Jun 30, 2022 6:56 am
Notice that exporting a snapshot of a rect from an object uses card-local co-ordinates - you can also export snapshot from a control directly - in which case *just* that control is rendered (snapshotting a card will render all objects intersecting the rect you specify).
Thanks Mark,
All this talk of snapshot had me thinking camera but in fact, when I rebuilt it again (you have to change the name and rebuild for the alert to popup) I grabbed a screen shot and it was for "recording the screen", which, I presume is something different but had me in my haste thinking camera. I've attached the prompt.
Also, the context of the line and the way the image gets built will be more meaningful to you than to me. I feel fortunate I just happened to find it here on the forums (originally attributed to Scott Rossi) and it did most of what I was looking for. There was however, this one little problem with the OS alert and then another problem I found only today which was, if you drag the dragimage off the field and release the mouse the drag image does not disappear because the the mouse up message (I presume) does not go to the field? Or something like that. Anyway, once dragged off the card it stays attached to the mouse and then I believe at that point I was forced to quit and restart LiveCode to get rid of it. Even sometimes when I restarted LiveCode when I moved the mouse over the field again the drag image reappeared. Very messy. Anyway, I wanted to clean that up before sending along a sample stack. I did find a solution (very oddly, your immediate reaction when the image does not disappear up is to click the mouse button again. I added a mouseUp handler on the card and when that was triggered I deleted the drag image). This apparently cleaned up a lot of other problems. The whole operation is now significantly more robust. It seems the fact that the drag image was not "disappearing" when it should was creating ongoing problems.
The code for building the drag image:
Code: Select all
on buildImageToDrag
###########################################################
#
# scrolls the field in the direction of pNum
#
# Thanks to Scott Rossi TactileMedia for example code
###########################################################
--if not sAllowDrag then exit buildImageToDrag
# ESTABLISH RECT FOR SCREEN CAPTURE
put the formattedRect of line sLineNoToMove of me into tRect
put left of me + borderWidth of me into item 1 of tRect
put right of me - 16 - borderWidth of me into item 3 of tRect # - tOffset
-- convert from screen to window coordinates - using globalLoc
put globalLoc(item 1 of tRect & "," & item 2 of tRect) into globalRect
put "," & globalLoc(item 3 of tRect & "," & item 4 of tRect) after globalRect
# DISABLE LIST BEHAVIOR SO TEXT STAYS VISIBLE IN FIELD
set listBehavior of me to false
reset the templateImage
-- create a picture from a portion of the screen
export snapshot from rect globalrect to draggerData as PNG -- I think this line triggers the OS alert?
set rect of the templateImage to tRect
set showBorder of the templateImage to false
set text of the templateImage to draggerData --!! text! what were they thinking of ? - data would seem more logical
set blendLevel of the templateImage to 20
set name of the templateImage to "RowSnapShot"
create image
reset the templateImage
end buildImageToDrag
Other oddities include (a) if you select Deny on OS alert it still functions normally. (b) If you select the "Open System Preferences" option and enable it, then later disable it, it also has no effect. ie. the prompt does not reappear and drag and drop continues to work normally. Happy to upload this to the QCC if it would be helpful to look at. Let me know.
Thanks btw, it did send me in a very useful direction in terms of resolving some issues.
Mark