2021-02-22 22:24:18 +03:00
|
|
|
module gg
|
|
|
|
|
2022-07-06 16:19:40 +03:00
|
|
|
import os
|
2021-02-22 22:24:18 +03:00
|
|
|
import sokol.sapp
|
|
|
|
|
|
|
|
#include <android/configuration.h>
|
|
|
|
|
|
|
|
fn C.AConfiguration_new() voidptr
|
|
|
|
fn C.AConfiguration_fromAssetManager(voidptr, voidptr)
|
|
|
|
fn C.AConfiguration_getDensity(voidptr) u32
|
|
|
|
fn C.AConfiguration_delete(voidptr)
|
|
|
|
|
2022-04-05 18:42:01 +03:00
|
|
|
// android_dpi_scale returns the scale factor of the device.
|
2021-02-22 22:24:18 +03:00
|
|
|
pub fn android_dpi_scale() f32 {
|
|
|
|
config := C.AConfiguration_new()
|
2022-07-06 16:19:40 +03:00
|
|
|
activity := &os.NativeActivity(sapp.android_get_native_activity())
|
2021-02-22 22:24:18 +03:00
|
|
|
C.AConfiguration_fromAssetManager(config, activity.assetManager)
|
|
|
|
density := C.AConfiguration_getDensity(config)
|
|
|
|
C.AConfiguration_delete(config)
|
|
|
|
return f32(density) / 160
|
|
|
|
}
|