Page 1 of 1

Grabbing an image within a group

Posted: Sun Feb 19, 2012 2:52 pm
by teacherguy
I have an image I want to be able to grab regardless of whether or not the user is touching it directly. I created a group that is larger than the image and I put the grab command into the script of the group. However, the grab still functions only when I drag the image directly, not when I drag across other locations within the group. Thoughts?

Re: Grabbing an image within a group

Posted: Sun Feb 19, 2012 3:18 pm
by Klaus
Hi teacherguy,

could you post the script please?


Best

Klaus

Re: Grabbing an image within a group

Posted: Sun Feb 19, 2012 3:26 pm
by teacherguy

Code: Select all

on touchMove pId, pX, pY
   
   repeat with x = 1 to the number of images in group "slogans"
      if the visible of image x of group "slogans" is true then put the short name of image x of group "slogans" into tImage
   end repeat
   set the resizeQuality of img tImage to "normal"
   set the origPic of image tImage to the text of image tImage
   put the effective width of image tImage / the effective height of image tImage into sWHRatio
   if sTouches[pId] is empty then
      put (pX, pY) into sTouches[pId]
      if the number of elements in sTouches is 2 then
      put distBetweenPts(sTouches[line 1 of the keys of sTouches], sTouches[line 2 of the keys of sTouches]) into sDist 
   end if
      
   else if the number of elements in sTouches is 2 then
      put (pX, pY) into sTouches[pId]
      local tDist
      put distBetweenPts(sTouches[line 1 of the keys of sTouches], sTouches[line 2 of the keys of sTouches]) into tDist

      if tDist is not sDist then
         local tScale
         put 1 + (tDist - sDist) / 100 * kPinchScaleRatio into tScale
         local tWidth, tHeight, tLeft, tTop
         put round(the width of image tImage * tScale) into tWidth
         put round(the height of image tImage * tScale) into tHeight
         put round(the left of graphic "frame") into tLeft
         put round(the top of image tImage) into tTop
         put round(item 1 of the loc of the current card + (the left of image tImage - item 1 of the loc of the current card) * tScale) into tLeft
         put round(item 2 of the loc of the current card + (the top of image tImage - item 2 of the loc of the current card) * tScale) into tTop
         set the rect of image tImage to (tLeft, tTop, tLeft + tWidth, tTop + tHeight)
         put tDist into sDist
      end if
      
   else
      grab image tImage --here is the issue....shouldn't it grab even if the user is not touching directly since script is in the group??
   end if
end touchMove

Re: Grabbing an image within a group

Posted: Sun Feb 19, 2012 3:32 pm
by sturgis
When you set up your group, place a graphic behind everything, set it to opaque, if you want, set the blendlevel so that it doesn't show. This way there is a control to see the mousedown when it occurs. Then, rather than using grab you can do something like the following.

edit:(you guys posed while I was typing, could do the same with touchmove I think, but I only have desktop avail at the moment) Not sure how easily translatable it would be though but in case there is still something useful..

Code: Select all

on mousedown
   --dissalow buttons so they still work without causing funkiness
   --can dissalow specific controls this way also
   if the target contains "button" then --don't start drag on buttons. Could check for specific buttons
      pass mousedown -- if it was a button pass the mousedown and do nothing else
   else
      set the dragging of me to true --set a property to use in the mousemove handler

      set the loc of image 1 to the mouseloc -- set the position of the image to the mouse position. 
      --could ignore this part if you only want the graphic to change position AFTER the mouse begins to move
   end if
end mousedown

on mouseUp
   set the dragging of me to false -- stop moving the image when the mouse is released
end mouseUp

on mousemove
   if the dragging of me then
      set the loc of image 1 to the mouseloc -- does the actual move if the dragging of the group is true
   end if
end mousemove
Not as easy in some ways as using grab but it works. Do you need it to trigger something on drop based on position? If so, (since you can't look at "the target" or anything of that nature, this might be a great place to use intersect to see if you dropped it on something.

Could change the mouseup and add a repeat loop checking against a list of objects for intersect then act accordingly. If there is no intersect, do something else. Or you could use intersect inside the mousemove so that you can dynamically hilite/unhilite objects or locations as you pass over them.


teacherguy wrote:I have an image I want to be able to grab regardless of whether or not the user is touching it directly. I created a group that is larger than the image and I put the grab command into the script of the group. However, the grab still functions only when I drag the image directly, not when I drag across other locations within the group. Thoughts?

Re: Grabbing an image within a group

Posted: Mon Feb 20, 2012 1:45 am
by teacherguy
So, does the grab command require that the user be in direct contact with the target?

Re: Grabbing an image within a group

Posted: Mon Feb 20, 2012 5:06 am
by sturgis
It seems so to be though maybe a guru could chime in on this. I've tried everything I can think of to get grab to work for this with no luck which is why I posted the possible alternative.
teacherguy wrote:So, does the grab command require that the user be in direct contact with the target?

Re: Grabbing an image within a group

Posted: Mon Feb 20, 2012 2:15 pm
by Klaus
Hi guys,

the dictionary is VERY clear about GRAB, I really wonder why noone ever bothers to consult it?
...
You can only grab a control when the mouse pointer is within the control's rectangle at the time the mouse is clicked.
If the mouse pointer is outside the control when the grab command is executed, nothing happens.
...

Best

Klaus

Re: Grabbing an image within a group

Posted: Mon Feb 20, 2012 3:01 pm
by sturgis
Hmm. Found it now that you pointed it out. Hard to see considering its *cough* the first line of comments and sprinkled with some bold words and such. *slaps forehead*
I feel silly now. Reading. Who knew!
Klaus wrote:Hi guys,

the dictionary is VERY clear about GRAB, I really wonder why noone ever bothers to consult it?
...
You can only grab a control when the mouse pointer is within the control's rectangle at the time the mouse is clicked.
If the mouse pointer is outside the control when the grab command is executed, nothing happens.
...

Best

Klaus