Mobile: Convert from screen to card coords = ALREADY BUILD-IN!

Klaus major-k klaus at major-k.de
Wed Oct 19 11:39:27 EDT 2022


Hi Brian,

Panos showed me the already build-in solution!

Just use globalloc() and localloc() to translate to and 
from screencoordinates/card coordinates also on "Mobile"!

Just tested and as far as I can tell this works a charme! :-)
A typical "slap on the forehead" thingie...

> Am 18.10.2022 um 17:25 schrieb Brian Milby via use-livecode <use-livecode at lists.runrev.com>:
> 
> Klaus,
> 
> My setBackground handler doesn't give a direct translation, but does start
> it.
> https://github.com/bwmilby/mobileDemo/blob/48b89b37aba41afb5a7b90cfc9bdbbca9e7f052c/mobileDemo_Scripts/stack_MobileDemo_card_id_1002.livecodescript#L105
> Since we are talking about portrait on mobile, the extra space will always
> be in the height direction.  That simplifies a few things.  The height of
> the screen from the card perspective will be:
>   put tCardW / (tScreenW / tScreenH) into tNewH
> You will need 3 things to calculate positions.  A ratio for each direction
> and a height offset.
>   put (tNewH - tCardH) / 2 into tHOffset -- 1/2 of the extra pixels with
> be at the top
>   put tNewH / tScreenH into tHRatio -- convert screen pixels to card pixels
>   put tCardW / tScreenW into tWRatio -- convert screen pixels to card
> pixels
> Using this, you should be able to calculate a card XY value from a screen
> XY value (safe XY for example).
>   put (tScreenY * tHRatio) - tHOffset into tCardY
>   put (tScreenX * tWRatio) into tCardX
> 
> This is without testing though.  I'll try to do a test to validate my
> method.  And remember, that anything placed outside the bounds of the card
> will just be there for looks and probably won't respond to touch.
> 
> Thanks,
> Brian

Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
klaus at major-k.de




More information about the use-livecode mailing list