| 1 | module gg |
| 2 | |
| 3 | import os |
| 4 | import sokol.sapp |
| 5 | |
| 6 | #include <android/configuration.h> |
| 7 | |
| 8 | fn C.AConfiguration_new() voidptr |
| 9 | fn C.AConfiguration_fromAssetManager(voidptr, voidptr) |
| 10 | fn C.AConfiguration_getDensity(voidptr) u32 |
| 11 | fn C.AConfiguration_delete(voidptr) |
| 12 | |
| 13 | // android_dpi_scale returns the scale factor of the device. |
| 14 | pub fn android_dpi_scale() f32 { |
| 15 | config := C.AConfiguration_new() |
| 16 | activity := &os.NativeActivity(sapp.android_get_native_activity()) |
| 17 | C.AConfiguration_fromAssetManager(config, activity.assetManager) |
| 18 | density := C.AConfiguration_getDensity(config) |
| 19 | C.AConfiguration_delete(config) |
| 20 | return f32(density) / 160 |
| 21 | } |
| 22 | |