Jump to content
  • Advertisement
Sign in to follow this  
KKTHXBYE

Get the real position for touch event

This topic is 922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After switching to newer device i saw that, when i click something at the bottom of the screen it gives me the value of 480 even when the device height is 540.

 

it must be something with scaling, however i didin't find anything about that on the net

 

this is how i get screen dim:

void GetDisplaySize()
{
	WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
	Display display = wm.getDefaultDisplay();
	
	Point outSize = new Point();
	display.getSize(outSize);
   
	ScreenWidth  = outSize.x;
	ScreenHeight = outSize.y;

    
	Log.d("ANDRO_ASYNC","W: "+Integer.toString(ScreenWidth));
	Log.d("ANDRO_ASYNC","H: "+Integer.toString(ScreenHeight));
}

and how i get pointer location:

	        float X = event.getX(index);
	        float Y = event.getY(index);

Share this post


Link to post
Share on other sites
Advertisement

Is it possible those missing 60 pixels are taken up by the hardware buttons (the back button and friends)?

 

I get my screen size from onSurfaceChanged from my GLSurfaceView (http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceChanged%28javax.microedition.khronos.opengles.GL10,%20int,%20int%29).

 

I don't know enough about WindowManager to know whether or not it'll include the built-in buttons in the dimensions it gives you.

Share this post


Link to post
Share on other sites

i fogot to mention that the screen is horizontal, but that shouldn't matter, anyway your method doesn't work either (shows the same dimensions) additionally its called after glInit() method.

 

 

i just wonder how the heck could i scale the pointer position to the screen size.

 

the screen is definetly 960x540, because i even take a screenshot from opengl thread and when telling it to take pixels from that rect it shows whole screen, (yeah whole app is fullscreen) this means getrawx and getrawy  return the same as getx and gety

 

worst part is x coordinate is good but not y (landscape)

Edited by WiredCat

Share this post


Link to post
Share on other sites


Is it possible those missing 60 pixels are taken up by the hardware buttons (the back button and friends)?


That exactly whats going on. On my sh!#y HTC desire 610, the actually screen resolution is 800 x 480, however, when queried via the NDK it comes up 782 x 480, the HW buttons takes up the additional pixels.

There shoud be no need to scale, the value you are getting is the actual window surface size and the touch event will take that into effect.

Share this post


Link to post
Share on other sites

i am not sure which surface it is since i have glsurfaceview (from java) and it claims that it has the same dimension as screen display. Maybe theres a way to find the handle to window of which touchpad event occurs and retreive width and height from that, because i am not quite willing to do calibration test on first run (you know there are quads draw in 4 corners of the screen and user is asked to touch them tongue.png <- this is my solution so far.)

 

tried something like that: super.getWindow().getWindowManager().getDefaultDisplay().getSize(outSize); but still it returns the screen size in pixels, not the thing that i want

Edited by WiredCat

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!