2021-02-22 20:24:18 +01:00
|
|
|
module gg
|
|
|
|
|
|
|
|
import sokol.sapp
|
|
|
|
|
|
|
|
#include <android/configuration.h>
|
|
|
|
#include <android/native_activity.h>
|
|
|
|
|
|
|
|
fn C.AConfiguration_new() voidptr
|
|
|
|
fn C.AConfiguration_fromAssetManager(voidptr, voidptr)
|
|
|
|
fn C.AConfiguration_getDensity(voidptr) u32
|
|
|
|
fn C.AConfiguration_delete(voidptr)
|
|
|
|
|
|
|
|
struct C.AAssetManager {}
|
2021-03-10 17:38:20 +01:00
|
|
|
|
|
|
|
// See https://developer.android.com/ndk/reference/struct/a-native-activity for more info.
|
2021-02-22 20:24:18 +01:00
|
|
|
struct C.ANativeActivity {
|
2021-03-10 17:38:20 +01:00
|
|
|
pub:
|
|
|
|
assetManager voidptr // Pointer to the Asset Manager instance for the application. (AAssetManager *)
|
|
|
|
callbacks voidptr // Pointer to the callback function table of the native application. (struct ANativeActivityCallbacks *)
|
|
|
|
clazz voidptr // The NativeActivity object handle.
|
|
|
|
env voidptr // JNI context for the main thread of the app.
|
2021-04-05 19:55:03 +02:00
|
|
|
externalDataPath &char // Path to this application's external (removable/mountable) data directory.
|
2021-03-10 17:38:20 +01:00
|
|
|
instance voidptr // This is the native instance of the application.
|
2021-04-05 19:55:03 +02:00
|
|
|
internalDataPath &char // Path to this application's internal data directory.
|
|
|
|
obbPath &char // Available starting with Honeycomb: path to the directory containing the application's OBB files (if any).
|
2021-03-10 17:38:20 +01:00
|
|
|
sdkVersion int // The platform's SDK version code.
|
|
|
|
vm voidptr // The global handle on the process's Java VM
|
2021-02-22 20:24:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn android_dpi_scale() f32 {
|
|
|
|
config := C.AConfiguration_new()
|
|
|
|
activity := &C.ANativeActivity(sapp.android_get_native_activity())
|
|
|
|
C.AConfiguration_fromAssetManager(config, activity.assetManager)
|
|
|
|
density := C.AConfiguration_getDensity(config)
|
|
|
|
C.AConfiguration_delete(config)
|
|
|
|
return f32(density) / 160
|
|
|
|
}
|