OnTouch X and Y coordinates on Android

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 416
Joined: Thu May 02, 2019 11:53 am

OnTouch X and Y coordinates on Android

Post by amyren »

I just played around using the OnTouch event to get the X and Y values from an android device, and had some strugles.
First I thought my touches did not get detected at all, but then I found they was just way out of place .
It turns out that the OnTouch X and Y does relate to the physical screen resolution, rather than the relative X and Y positions of the display like MouseX/Y does.
I did a workaround by making a ratio for recalculation of the X and Y coordinates.

Code: Select all

HWidth = GetAttribute(#DISPLAY, 0, #ATTRHOSTWIDTH)
HHeight = GetAttribute(#DISPLAY, 0, #ATTRHOSTHEIGHT)
DWidth = GetAttribute(#DISPLAY, 0, #ATTRWIDTH)
DHeight = GetAttribute(#DISPLAY, 0, #ATTRHEIGHT)
WidthRatio = HWidth/DWidth
HeightRatio = HHeight/DHeight
This worked when the app was scaled to full screen.
But in non-fullscreen, the app display will open as a smaller window on the midle of the screen. Then the OnTouch X and Y coordinates will start start from the upper left corner of the app, so that the X/Y's will be exact the same values as it would be using MouseX/Y.

Now this is not a problem anymore, since I found in this case I was better off using IsLeftMouse(), but I still wonder if this OnTouch behaviour is intentional?
User avatar
airsoftsoftwair
Posts: 5848
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnTouch X and Y coordinates on Android

Post by airsoftsoftwair »

amyren wrote: Fri Mar 27, 2020 10:08 am Now this is not a problem anymore, since I found in this case I was better off using IsLeftMouse(), but I still wonder if this OnTouch behaviour is intentional?
Actually, it is. "OnTouch" is a lowlevel event handler specific to Android. Hollywood just passes the raw data it receives from Android without any adjustments whatsoever so it can be a little tricky to use.

Having a more portable and consistent touch event API is on my list, though.
Post Reply