finding the mousecolor in IOS

Scott Rossi scott at tactilemedia.com
Thu Jul 12 18:18:31 EDT 2012


Hi Howard:

It seems the mouseColor is not functional on iOS in 5.5.1 (but apparently it
has been fixed on Lion which is a huge relief).

That said, if you can work with an image as your color source (ie import a
snapshot if needed), you can use the following function as a workaround
(watch wrap):

local theImageData

function getPixelColor pImage,pX,pY
   if theImageData is empty then put the imageData of pImage into
theImageData
   put width of pImage into W
   put ((pY-1)*W)*4+pX*4 into lastChar
   put charToNum(char lastChar of theImageData) into B
   put charToNum(char lastChar-1 of theImageData) into G
   put charToNum(char lastChar-2 of theImageData) into R
   return R,G,B
end getPixelColor


This should retrieve the color of a pixel in a target image based on the X,Y
offset of the touch from the topLeft.  The idea is to store the imageData of
the target image in theImageData variable so the function doesn't have to
retrieve it repeatedly.

I've been wanting mouseColor on iOS myself and while not true mouseColor,
this comes close.  Hope this helps.

Regards,

Scott Rossi
Creative Director
Tactile Media, UX Design




Recently, Howard Bornstein wrote:

> I'm designing a an IOS app that makes extensive use of determining "the
> mousecolor". Everything is working fine in my stack, but when I port it to
> the simulator (or create the IOS app), the mousecolor only returns 0,0,0
> regardless of where the mouse is.
> 
> I found some early posts from last year discussing this issue and they
> conclude that the mousecolor can't be supported under IOS because there is
> no way to determine which pixel is being specified (I guess because our
> fingers are fatter than a single pixel).
> 
> However, this doesn't make sense. If you put this script into the card of a
> stack and run it in the simulator (it also works in an actual IOS app), it
> gives you the point your finger is pressing on the iphone:
> 
> *on* mousemove
> 
>     *put*  the mouseloc &&":"&& the mousecolor into fld "location"
> 
> *end* mousemove
> 
> However, the mousecolor, as I mentioned, is always black. Since LC can
> determine a specific pixel (or at least aggregates the points you are
> touching down to a specific pixel) it doesn't seem like there is any reason
> it can't get the mousecolor under that pixel.
> 
> In addition, I found this comment in the release notes for IOS 4.5.3:
> 
> *release-17 (2010-12-01)*
> 
> **
> 
> *Fixed issue with 'the mouseColor' causing a crash*
> 
> 
> This implies to me that the mousecolor is supported under IOS. So, has
> anyone gotten this to work or has anyone found another way to get the
> mousecolor for a point on an IOS screen?








More information about the use-livecode mailing list