Mobile: Convert from screen to card coords

Klaus major-k klaus at major-k.de
Tue Oct 18 11:31:23 EDT 2022


Hi Brian,

> 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

ah, thanks a bunch, I begin to understand, was always weak in math. 8-)

> This is without testing though.  I'll try to do a test to validate my method.  

Thank you very much!

> And remember, that anything placed outside the bounds of the card
> will just be there for looks and probably won't respond to touch.

I think I really got it! 

> Thanks,

I have to thank!

> 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