monkey2 icon indicating copy to clipboard operation
monkey2 copied to clipboard

SDL_GetDisplayDPI does not work for android

Open XANOZOID opened this issue 7 years ago • 7 comments

I think the patch should already be in one of the newer version of SDL2, but as of right now we do not have access to this functionality ...

https://stackoverflow.com/questions/46987812/sdl-getdisplaydpi-doesnt-work-on-android

I don't know how to work with JNI but I will be trying to figure it in the meantime while I have time

XANOZOID avatar Jan 10 '18 18:01 XANOZOID

Implemented a fix for now :), definitely does the job!

http://monkeycoder.co.nz/forums/topic/dpi-for-android/

@blitz-research do you think this is something which should be added to the Monkey2 source code for the time being?

XANOZOID avatar Jan 10 '18 22:01 XANOZOID

What is it used for?

On Thu, Jan 11, 2018 at 11:43 AM, Abrahim [email protected] wrote:

Implemented a fix for now :), definitely does the job!

http://monkeycoder.co.nz/forums/topic/dpi-for-android/

@blitz-research https://github.com/blitz-research do you think this is something which should be added to the Monkey2 source code for the time being?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/blitz-research/monkey2/issues/319#issuecomment-356762473, or mute the thread https://github.com/notifications/unsubscribe-auth/ADU3Ql5DJOFkteADPX1s9hvMGyz1hKL1ks5tJT0mgaJpZM4RZw7P .

blitz-research avatar Jan 10 '18 22:01 blitz-research

It is to make sure sizes are, ftmp, pixel(Dots*) density independent.

Problem: Screens of the same size can have different pixel(Dot*) densities which makes pixels an impractical form of measurement - especially for UI.

Solution: DPI allows us to make sure the sizes we are using is consistent across screens in terms of "inches" . . .

Unfortunately, there are no metric versions of this function.

XANOZOID avatar Jan 10 '18 22:01 XANOZOID

It would be great to have a dpi value! especially on mobiles where the screen size may vary from 3 to 10" for almost the same resolution.

abakobo avatar Jan 11 '18 11:01 abakobo

Any chance you can cpome up with something for other targets too? And in particular, the 'dpi/mouse scale', ie: 1 or 2 etc.

I kind of want:

GetDpi (dots per inch) GetDpiScale (OS dpi scale factor for screen coords eg: for window sizes/mouse coords).

Especially on macos, as the current solution involves creating a window, checking dpi, then resizing/repositioning window if it's high dpi. I'ts horribly ugly, and If I know 'dpi scale' before hane I could clean this up!

On Fri, Jan 12, 2018 at 12:59 AM, abakobo [email protected] wrote:

It would be great to have a dpi value! especially on mobiles where the screen size may vary from 3 to 10" for almost the same resolution.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/blitz-research/monkey2/issues/319#issuecomment-356914008, or mute the thread https://github.com/notifications/unsubscribe-auth/ADU3QjwQIllFpbwKzbKfVNjSLmVogp6mks5tJfecgaJpZM4RZw7P .

blitz-research avatar Jan 11 '18 20:01 blitz-research

@blitz-research I currently have my own module I've derived from my work from above that's more consistent and platform independent. . . All it does is use the SDL feature and if that fails fallback to a native attempt - does this look okay? I'm not sure about the DPIScale feature you're talking about

Block of Display DPI related code
Namespace abe.display

#If __TARGET__="android"
	#Import "native/DisplayUtility.java"
	#Import "<std>"
	#Import "<sdl2>"
	Using std..
	Using sdl2..
#Else 
	#Import "<sdl2>"
 	Using sdl2..
 #End
 
#Rem monkeydocs A class for handling display related features. eg: DPI
#End
 Class DisplayUtility Final
	 
	#Rem monkeydocs Returns the vertical(true) or horizontal(false) DPI for the DISPLAY*. 
	#End
	Function GetDPI:Int( vertical:Bool )
		Local dpi:Float
		Local hdpi:Float
		Local vdpi:Float
		Local result:= SDL_GetDisplayDPI(0, Null, Varptr(hdpi), Varptr(vdpi))
		        
        ' SDL fails if not 0, so use our backup plan	
		If result<>0 Then 
#If  __TARGET__="android"
			Local env:= sdl2.Android_JNI_GetEnv()	
			Local cls:= env.FindClass( "com/monkey2/lib/DisplayUtility" )
			Local mth:= env.GetStaticMethodID( cls, "getDPI", "(Z)I" )
			
			dpi = env.CallStaticIntMethod( cls, mth, New Variant[]( vertical ) )	
#Endif
		Else
			dpi = vertical? vdpi Else hdpi
		End
		
		Return dpi
	End

End

XANOZOID avatar Jan 11 '18 23:01 XANOZOID

The code is able to do this:

  1. Return you the dots per inch on any module horizontal and vertical
  2. Falls back to a native implementation if SDL2 doesn't support it

As such:

Local DPI:=New Vec2i( DisplayUtility.GetDPI( True ),DisplayUtility.GetDPI( False ) )

On second thought it might make the most sense to return a vec3 for this function ...

XANOZOID avatar Jan 12 '18 01:01 XANOZOID