Expose display device DPI
This commit is contained in:
@@ -19,6 +19,11 @@ class Display {
|
||||
|
||||
public var id (default, null):Int;
|
||||
|
||||
/**
|
||||
* Pixel density of the display
|
||||
*/
|
||||
public var dpi (default, null): { diagonal:Float, horizontal:Float, vertical:Float };
|
||||
|
||||
/**
|
||||
* The name of the device, such as "Samsung SyncMaster P2350", "iPhone 6", "Occulus Rift DK2", etc.
|
||||
**/
|
||||
|
||||
@@ -163,6 +163,19 @@ class System {
|
||||
}
|
||||
|
||||
display.currentMode = display.supportedModes[displayInfo.currentMode];
|
||||
|
||||
var dpi:Dynamic = lime_system_get_display_dpi (id);
|
||||
|
||||
if (dpi != null) {
|
||||
|
||||
display.dpi = { vertical:0, horizontal:0, diagonal:0 };
|
||||
|
||||
display.dpi.vertical = dpi.vertical;
|
||||
display.dpi.horizontal = dpi.horizontal;
|
||||
display.dpi.diagonal = dpi.diagonal;
|
||||
|
||||
}
|
||||
|
||||
return display;
|
||||
|
||||
}
|
||||
@@ -421,6 +434,7 @@ class System {
|
||||
@:cffi private static function lime_system_set_allow_screen_timeout (value:Bool):Bool;
|
||||
@:cffi private static function lime_system_get_directory (type:Int, company:String, title:String):Dynamic;
|
||||
@:cffi private static function lime_system_get_display (index:Int):Dynamic;
|
||||
@:cffi private static function lime_system_get_display_dpi (index:Int):Dynamic;
|
||||
@:cffi private static function lime_system_get_num_displays ():Int;
|
||||
@:cffi private static function lime_system_get_timer ():Float;
|
||||
#end
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace lime {
|
||||
static bool GetAllowScreenTimeout ();
|
||||
static const char* GetDirectory (SystemDirectory type, const char* company, const char* title);
|
||||
static value GetDisplay (int id);
|
||||
static value GetDisplayDPI (int id);
|
||||
static int GetNumDisplays ();
|
||||
static double GetTimer ();
|
||||
static bool SetAllowScreenTimeout (bool allow);
|
||||
|
||||
@@ -1160,6 +1160,12 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_system_get_display_dpi (int id) {
|
||||
|
||||
return System::GetDisplayDPI (id);
|
||||
|
||||
}
|
||||
|
||||
int lime_system_get_num_displays () {
|
||||
|
||||
return System::GetNumDisplays ();
|
||||
@@ -1512,6 +1518,7 @@ namespace lime {
|
||||
DEFINE_PRIME0 (lime_system_get_allow_screen_timeout);
|
||||
DEFINE_PRIME3 (lime_system_get_directory);
|
||||
DEFINE_PRIME1 (lime_system_get_display);
|
||||
DEFINE_PRIME1 (lime_system_get_display_dpi);
|
||||
DEFINE_PRIME0 (lime_system_get_num_displays);
|
||||
DEFINE_PRIME0 (lime_system_get_timer);
|
||||
DEFINE_PRIME1 (lime_system_set_allow_screen_timeout);
|
||||
|
||||
@@ -304,6 +304,27 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
value System::GetDisplayDPI (int id) {
|
||||
|
||||
value dpi = alloc_empty_object ();
|
||||
|
||||
int id_diagonal = val_id ("diagonal");
|
||||
int id_horizontal = val_id ("horizontal");
|
||||
int id_vertical = val_id ("vertical");
|
||||
|
||||
float ddpi = 0.0;
|
||||
float hdpi = 0.0;
|
||||
float vdpi = 0.0;
|
||||
|
||||
SDL_GetDisplayDPI (id, &ddpi, &hdpi, &vdpi);
|
||||
|
||||
alloc_field (dpi, id_diagonal , alloc_float (ddpi));
|
||||
alloc_field (dpi, id_horizontal, alloc_float (hdpi));
|
||||
alloc_field (dpi, id_vertical , alloc_float (vdpi));
|
||||
|
||||
return dpi;
|
||||
|
||||
}
|
||||
|
||||
int System::GetNumDisplays () {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user