Grabbing an image within a group

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Grabbing an image within a group

Post by teacherguy » Sun Feb 19, 2012 2:52 pm

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?

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Grabbing an image within a group

Post by Klaus » Sun Feb 19, 2012 3:18 pm

Hi teacherguy,

could you post the script please?


Best

Klaus

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Grabbing an image within a group

Post by teacherguy » Sun Feb 19, 2012 3:26 pm

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Grabbing an image within a group

Post by sturgis » Sun Feb 19, 2012 3:32 pm

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?

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Grabbing an image within a group

Post by teacherguy » Mon Feb 20, 2012 1:45 am

So, does the grab command require that the user be in direct contact with the target?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Grabbing an image within a group

Post by sturgis » Mon Feb 20, 2012 5:06 am

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?

Klaus
Posts: 14235
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Grabbing an image within a group

Post by Klaus » Mon Feb 20, 2012 2:15 pm

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Grabbing an image within a group

Post by sturgis » Mon Feb 20, 2012 3:01 pm

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

Post Reply