Pinch resizing more than one image on a card

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Pinch resizing more than one image on a card

Post by tyarmsteadBUSuSfT » Sun Mar 23, 2014 4:39 pm

I am able to pinch resize one image on the card, but am having problems if I have more than one image on the card. Is it possible to pinch resize more than one image on a card? I've tried to differentiate which image at the touch start code with and if statement. Am I on the right track?
Thank you
Ty

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Pinch resizing more than one image on a card

Post by Klaus » Sun Mar 23, 2014 5:46 pm

Hi Ty,

you can check "the target" on touchstart, then you know if and what image to handle.
Is that what you mean?


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Pinch resizing more than one image on a card

Post by tyarmsteadBUSuSfT » Sun Mar 23, 2014 9:29 pm

Yes, I tried that, but let me re look at the code. Now that I know I can do, that helps a great deal.
Thank you
Ty

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Pinch resizing more than one image on a card

Post by tyarmsteadBUSuSfT » Mon Mar 24, 2014 12:11 am

Klause, This is where I am starting with the touch start:
local sinputId
local sTouchArray, sFRAMEWIDTH, sFRAMEHEIGHT

on touchStart pId, pX, pY
get target
if the target is image "itemPic1" or image "itemPic3" or image "itemPic4" then
put it into tPic
#to check if it is putting the target into tPic
answer yes
put the width of image tPic into sFRAMEWIDTH
put the height of image tPic into sFRAMEHEIGHT
else
end if
#to see if it is the correct target
answer the target
end touchStart

I can't get the if to work.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Pinch resizing more than one image on a card

Post by Simon » Mon Mar 24, 2014 1:05 am

if the target is image "itemPic1" or image "itemPic3" or image "itemPic4" then
if "itemPic1" is in the target or "itemPic3" is in the target or "itemPic4" is in the target then

See if that works, didn't test it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Pinch resizing more than one image on a card

Post by Klaus » Mon Mar 24, 2014 1:31 pm

Hi guys,

this should to the trick, please note the correct use of "IF... OR... OR" 8)

Code: Select all

local sinputId
local sTouchArray, sFRAMEWIDTH, sFRAMEHEIGHT

on touchStart pId, pX, pY
   put the short name of the target into tImageName   
   if tImageName = "itemPic1" OR tImageName = "itemPic2" OR tImageName = "itemPic4" then
      put the width of image tImageName into sFRAMEWIDTH
      put the height of image tImageName into sFRAMEHEIGHT
   end if
   
  ## to see if it is the correct target
   answer the target
end touchStart
Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Pinch resizing more than one image on a card

Post by tyarmsteadBUSuSfT » Tue Mar 25, 2014 12:50 am

Klause, thank you that part is working, but clearly I'm doing something else incorrectly. I want the user to be able to resize any of the three images that they have taken using the camera on this card card. I had it working for one image but when I started trying to use variables, that is when I ran into the problem of none of the images resizing.
Thank you so much for your help.
Ty

global gItemInfo
global gSeqNumb

local sinputId
local sTouchArray, sFRAMEWIDTH, sFRAMEHEIGHT

on touchStart pId, pX, pY
   put the short name of the target into tImageName   
   if tImageName = "itemPic1" OR tImageName = "itemPic3" OR tImageName = "itemPic4" then
      put the width of image tImageName into sFRAMEWIDTH
      put the height of image tImageName into sFRAMEHEIGHT
   end if
end touchStart

on touchEnd pId
delete variable sTouchArray[pId]
set the textSIZE of image tImageName to round(sFRAMEHEIGHT)
end touchEnd

on touchMove pId, pX, pY

if sTouchArray[pId]["startloc"] is empty then
put (pX & comma & pY) into sTouchArray[pId]["startloc"]
end if

put (pX & comma & pY) into sTouchArray[pId]["currentloc"]

if the number of lines of the keys of sTouchArray is 2 then
# First lets get the data out of the array
put line 1 of the keys of sTouchArray into tPointOne
put line 2 of the keys of sTouchArray into tPointTwo

put sTouchArray[tPointOne]["startloc"] into tStartLoc1
put sTouchArray[tPointTwo]["startloc"] into tStartLoc2
if tStartLoc1 is not empty and tStartLoc2 is not empty then
put resizeDistance(tStartLoc1, tStartLoc2) into tStartDistance
put resizeDistance(sTouchArray[tPointOne]["currentloc"], sTouchArray[tPointTwo]["currentloc"]) into tCurrentDistance
resizeImage tStartDistance, tCurrentDistance
end if
end if
end touchMove

function resizeDistance pLoc1, pLoc2
local dy, dx, tDistance
put item 2 of pLoc1 - item 2 of pLoc2 into dy
put item 1 of pLoc1 - item 1 of pLoc2 into dx
put sqrt((dy*dy) + (dx*dx)) into tDistance
return tDistance
end resizeDistance

on opencard
if environment() = "mobile" then
mobileControlCreate "input"
put the result into sinputID
mobileControlSet sinputID, "rect", "38,726,748,916"
mobileControlSet sinputID, "visible", "true"
mobileControlSet sinputID, "opaque", "true"
end if
end opencard

function resizeDistance pLoc1, pLoc2
local dy, dx, tDistance

put item 2 of pLoc1 - item 2 of pLoc2 into dy
put item 1 of pLoc1 - item 1 of pLoc2 into dx
put sqrt((dy*dy) + (dx*dx)) into tDistance

return tDistance
end resizeDistance

on resizeImage pStartDistance, pNewDistance
# Work out the percentage change between the old and new image
put round((pNewDistance / pStartDistance) * 100) into tPercentage
# Store the original location of the graphic
put the loc of image tImageName into tLoc
set the width of image tImageName to round(sFRAMEWIDTH * (tPercentage / 100))
set the height of image tImageName to round(sFRAMEHEIGHT * (tPercentage / 100))
set the loc of image tImageName to tLoc
set the textSIZE of image tImageName to round(sFRAMEHEIGHT )/5
unlock screen
end resizeImage

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Pinch resizing more than one image on a card

Post by Klaus » Tue Mar 25, 2014 12:55 pm

Hi Ty,

Klaus, my name is Klaus, without any E! 8)

OK, maybe adding:

Code: Select all

local tImageName
will help?

Question:
What does setting the textsize of an image do except not throwing an error? :D


Best

Klaus

tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

Re: Pinch resizing more than one image on a card

Post by tyarmsteadBUSuSfT » Tue Mar 25, 2014 11:08 pm

Klaus,
That did the trick.
Thank you and I apologize for the "e". I appreciate that as people often drop the e"e" from my name.
Ty

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Pinch resizing more than one image on a card

Post by Klaus » Wed Mar 26, 2014 12:55 pm

tyarmsteadBUSuSfT wrote:Thank you and I apologize for the "e". I appreciate that as people often drop the e"e" from my name.
No probem, Tie :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”