blitz-research / monkey2

zlib License
133 stars 42 forks source link

SDL_GetDisplayDPI does not work for android #319

Open XANOZOID opened 6 years ago

XANOZOID commented 6 years ago

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 commented 6 years ago

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?

blitz-research commented 6 years ago

What is it used for?

On Thu, Jan 11, 2018 at 11:43 AM, Abrahim notifications@github.com 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 .

XANOZOID commented 6 years ago

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.

abakobo commented 6 years ago

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.

blitz-research commented 6 years ago

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 notifications@github.com 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 .

XANOZOID commented 6 years ago

@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 ```monkey2 Namespace abe.display #If __TARGET__="android" #Import "native/DisplayUtility.java" #Import "" #Import "" Using std.. Using sdl2.. #Else #Import "" 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 commented 6 years ago

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 ...