Pinch-To-Zoom Field

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
qberty1337
Posts: 35
Joined: Sun Sep 09, 2012 1:09 pm

Pinch-To-Zoom Field

Post by qberty1337 » Sun Nov 25, 2012 10:06 am

Here's some cheesy code I cooked up in like 6 minutes.

It basically allows you to pinch and pull on a field and change it's textSize. Just save this code into any fields script, and drag on it with two fingers. Easy peasy.

Code: Select all

local tID1
local tID2
local tX1
local tX2

on touchMove tID, tX, tY
   if the tTouch of me > 2 then
      exit touchMove
   else if the tTouch of me < 2 then
      exit touchMove
   else
      if tID1 is tID then
         put tX into tX1
      else
         put tX into tX2
      end if
      SetTextSize
   end if
end touchMove

on touchStart tID
   if the tTouch of me > 2 then
   
   else
      if tID1 is empty then
         put tID into tID1
      else
         put tID into tID2
      end if
      set the tTouch of me to (the tTouch of me + 1)
   end if
end touchStart

on touchEnd tID
   if the tTouch of me > 2 then
   
   else
      if tID1 is tID then 
         put empty into tID1
      else
         put empty into tID2
      end if
      set the tTouch of me to (the tTouch of me - 1)
   end if
end touchEnd

on touchRelease tID
   touchEnd tID
end touchRelease

on SetTextSize
   put tX1 into p1
   put tX2 into p2
   put round((abs(p1 - p2) / 10)) into tDistance
   set the textSize of me to tDistance
end SetTextSize
Of course this is EXTREMELY sloppy and inefficient (it uses distance traveled to calculate textSize rather than distance relative to the rectangle of the field), but if anyone could throw something better together quicker, be my guest ;)

Post Reply

Return to “Android Deployment”