Expose Android Display Metrics to Löve

Create issue
Issue #10 resolved
Martin Felis repo owner created an issue

Comments (13)

  1. Jairo Luiz

    Done! https://bitbucket.org/tangerinagames/love-android-sdl2/commits/2b99a488d3a253b40b1472145344028e61551a59?at=display-metrics

    Sample:

    function love.draw()
      metrics = love.android:getDisplayMetrics()
    
      love.graphics.print("type: " .. metrics:type(), 10, 0)
    
      love.graphics.print("density: " .. metrics:getDensity(), 10, 20)
      love.graphics.print("scaledDensity: " .. metrics:getScaledDensity(), 10, 40)
      love.graphics.print("densityDpi: " .. metrics:getDensityDpi(), 10, 60)
    
      love.graphics.print("widthPixels: " .. metrics:getWidthPixels(), 10, 80)
      love.graphics.print("heightPixels: " .. metrics:getHeightPixels(), 10, 100)
    
      love.graphics.print("xdpi: " .. metrics:getXdpi(), 10, 120)
      love.graphics.print("ydpi: " .. metrics:getYdpi(), 10, 140)
    end
    
  2. Martin Felis reporter

    Erm... wow, thanks! Just merged it in.

    @slime73, @tangzero any suggestions on how one could create an API for this that is compatible for both iOS and Android?

  3. Jairo Luiz

    rename the android module to mobile. Then create subdirs with the specific implemetantion for each plataform.

  4. Alex Szpakowski

    I think the most important part of the display metrics for use in graphical programs is the expected pixel scale. LÖVE has an API for that with love.window.getPixelScale, so maybe you could make that work properly in Android (similar to how I did it for iOS), and then the rest of the metrics API would probably be unneeded.

  5. Alex Szpakowski

    Defer a common API design to some other time.

    Ah, but that was my point! 0.9.1 (mainline) already has an API which my iOS port takes advantage of, but the Android port doesn't - see love.window.getPixelScale / this commit for iOS.

    The implementation in mainline LÖVE only works in OS X right now since SDL for iOS and Android handles DPI a bit differently than it does for OSX, so you'll have to do something similar to my commit for iOS above to make it work properly on Android.

  6. Log in to comment