Mobile: Convert from screen to card coords
Brian Milby
brian at milby7.com
Tue Oct 18 11:25:15 EDT 2022
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
On Tue, Oct 18, 2022 at 9:39 AM Klaus major-k via use-livecode <
use-livecode at lists.runrev.com> wrote:
> Hi Mark,
>
>
> yes, sure, but i'd like to avoid this and currently only need an answer to
> my question.
>
>
> 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