diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index cbb732b7b..89067159c 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -20,7 +20,6 @@ import lime.ui.Window; @:access(lime._backend.native.NativeRenderer) @:access(lime.app.Application) @:access(lime.graphics.Renderer) -@:access(lime.system.Display) @:access(lime.ui.Gamepad) @:access(lime.ui.Window) @@ -59,33 +58,6 @@ class NativeApplication { handle = lime_application_create (null); - #if !lime_console - - // TODO: Evolve this more - - var displays:Array = lime_display_get_details (); - - for (displayInfo in displays) { - - var display = new Display (); - display.name = displayInfo.name; - display.supportedModes = []; - display.bounds = new Rectangle (displayInfo.bounds.x, displayInfo.bounds.y, displayInfo.bounds.width, displayInfo.bounds.height); - - for (mode in cast (displayInfo.supportedModes, Array)) { - - var displayMode = new DisplayMode (mode.width, mode.height, mode.refreshRate, mode.pixelFormat); - display.supportedModes.push (displayMode); - - } - - display.currentMode = display.supportedModes[displayInfo.currentMode]; - Display.devices.push (display); - - } - - #end - if (config != null) { setFrameRate (config.fps); @@ -475,7 +447,6 @@ class NativeApplication { private static var lime_application_set_frame_rate = System.load ("lime", "lime_application_set_frame_rate", 2); private static var lime_application_update = System.load ("lime", "lime_application_update", 1); private static var lime_application_quit = System.load ("lime", "lime_application_quit", 1); - private static var lime_display_get_details = System.load ("lime", "lime_display_get_details", 0); private static var lime_gamepad_event_manager_register = System.load ("lime", "lime_gamepad_event_manager_register", 2); private static var lime_key_event_manager_register = System.load ("lime", "lime_key_event_manager_register", 2); private static var lime_mouse_event_manager_register = System.load ("lime", "lime_mouse_event_manager_register", 2); diff --git a/lime/system/Display.hx b/lime/system/Display.hx index 51312293e..5e3788686 100644 --- a/lime/system/Display.hx +++ b/lime/system/Display.hx @@ -7,8 +7,6 @@ import lime.math.Rectangle; class Display { - public static var devices = new Array (); - /** * The desktop area represented by this display, with the upper-leftmost display at 0,0 **/ @@ -19,6 +17,8 @@ class Display { **/ public var currentMode (default, null):DisplayMode; + public var id (default, null):Int; + /** * The name of the device, such as "Samsung SyncMaster P2350", "iPhone 6", "Occulus Rift DK2", etc. **/ diff --git a/lime/system/DisplayMode.hx b/lime/system/DisplayMode.hx index aefe6598d..c9dcba4d5 100644 --- a/lime/system/DisplayMode.hx +++ b/lime/system/DisplayMode.hx @@ -28,7 +28,7 @@ class DisplayMode { public var width (default, null):Int; - public function new (width:Int, height:Int, refreshRate:Int, pixelFormat:PixelFormat) { + private function new (width:Int, height:Int, refreshRate:Int, pixelFormat:PixelFormat) { this.width = width; this.height = height; diff --git a/lime/system/System.hx b/lime/system/System.hx index 6eafa07d9..5a135e7d4 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -1,6 +1,8 @@ package lime.system; +import lime.math.Rectangle; + #if !macro import lime.app.Application; #end @@ -22,6 +24,9 @@ import js.Browser; import sys.io.Process; #end +@:access(lime.system.Display) +@:access(lime.system.DisplayMode) + class System { @@ -32,6 +37,7 @@ class System { public static var disableCFFI:Bool; public static var documentsDirectory (get, null):String; public static var fontsDirectory (get, null):String; + public static var numDisplays (get, null):Int; public static var userDirectory (get, null):String; @@ -162,6 +168,39 @@ class System { } + public static function getDisplay (id:Int):Display { + + #if (cpp || neko || nodejs) + var displayInfo = lime_system_get_display (id); + + if (displayInfo != null) { + + var display = new Display (); + display.id = id; + display.name = displayInfo.name; + display.bounds = new Rectangle (displayInfo.bounds.x, displayInfo.bounds.y, displayInfo.bounds.width, displayInfo.bounds.height); + display.supportedModes = []; + + var displayMode; + + for (mode in cast (displayInfo.supportedModes, Array)) { + + displayMode = new DisplayMode (mode.width, mode.height, mode.refreshRate, mode.pixelFormat); + display.supportedModes.push (displayMode); + + } + + display.currentMode = display.supportedModes[displayInfo.currentMode]; + return display; + + } + #end + + return null; + + } + + public static function getTimer ():Int { #if flash @@ -531,6 +570,17 @@ class System { } + private static function get_numDisplays ():Int { + + #if (cpp || neko || nodejs) + return lime_system_get_num_displays (); + #else + return 1; + #end + + } + + private static function get_userDirectory ():String { #if (cpp || neko || nodejs) @@ -551,6 +601,8 @@ class System { #if (cpp || neko || nodejs) private static var lime_system_get_directory = System.load ("lime", "lime_system_get_directory", 3); + private static var lime_system_get_display = System.load ("lime", "lime_system_get_display", 1); + private static var lime_system_get_num_displays = System.load ("lime", "lime_system_get_num_displays", 0); private static var lime_system_get_timer = System.load ("lime", "lime_system_get_timer", 0); #end diff --git a/project/Build.xml b/project/Build.xml index e5a3cb4e9..de7e4bbb9 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -178,7 +178,6 @@ - diff --git a/project/include/system/Display.h b/project/include/system/Display.h deleted file mode 100644 index 47c4edf27..000000000 --- a/project/include/system/Display.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LIME_SYSTEM_DISPLAY_H -#define LIME_SYSTEM_DISPLAY_H - - -#include - - -namespace lime { - - - class Display { - - - public: - - static value GetDetails (); - - - }; - - -} - - -#endif \ No newline at end of file diff --git a/project/include/system/System.h b/project/include/system/System.h index 3ef96aeb6..5e9516cce 100644 --- a/project/include/system/System.h +++ b/project/include/system/System.h @@ -1,6 +1,7 @@ #ifndef LIME_SYSTEM_SYSTEM_H #define LIME_SYSTEM_SYSTEM_H +#include #include @@ -25,6 +26,8 @@ namespace lime { public: static const char* GetDirectory (SystemDirectory type, const char* company, const char* title); + static value GetDisplay (int id); + static int GetNumDisplays (); static double GetTimer (); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 9d88f8921..6c097e029 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -161,13 +160,6 @@ namespace lime { } - value lime_display_get_details () { - - return Display::GetDetails (); - - } - - void lime_font_destroy (value handle) { Font *font = (Font*)(intptr_t)val_float (handle); @@ -922,6 +914,20 @@ namespace lime { } + value lime_system_get_display (value id) { + + return System::GetDisplay (val_int (id)); + + } + + + value lime_system_get_num_displays () { + + return alloc_int (System::GetNumDisplays ()); + + } + + value lime_system_get_timer () { return alloc_float (System::GetTimer ()); @@ -1164,7 +1170,6 @@ namespace lime { DEFINE_PRIM (lime_bytes_from_data_pointer, 2); DEFINE_PRIM (lime_bytes_get_data_pointer, 1); DEFINE_PRIM (lime_bytes_read_file, 1); - DEFINE_PRIM (lime_display_get_details, 0); DEFINE_PRIM (lime_font_get_ascender, 1); DEFINE_PRIM (lime_font_get_descender, 1); DEFINE_PRIM (lime_font_get_family_name, 1); @@ -1221,6 +1226,8 @@ namespace lime { DEFINE_PRIM (lime_renderer_unlock, 1); DEFINE_PRIM (lime_render_event_manager_register, 2); DEFINE_PRIM (lime_system_get_directory, 3); + DEFINE_PRIM (lime_system_get_display, 1); + DEFINE_PRIM (lime_system_get_num_displays, 0); DEFINE_PRIM (lime_system_get_timer, 0); DEFINE_PRIM (lime_text_event_manager_register, 2); DEFINE_PRIM (lime_text_layout_create, 3); diff --git a/project/src/backend/sdl/SDLDisplay.cpp b/project/src/backend/sdl/SDLDisplay.cpp deleted file mode 100644 index 5c67b904b..000000000 --- a/project/src/backend/sdl/SDLDisplay.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include -#include -#include - - -namespace lime { - - - static int id_bounds; - static int id_currentMode; - static int id_height; - static int id_name; - static int id_pixelFormat; - static int id_refreshRate; - static int id_supportedModes; - static int id_width; - static bool init = false; - - - value Display::GetDetails () { - - if (!init) { - - id_bounds = val_id ("bounds"); - id_currentMode = val_id ("currentMode"); - id_height = val_id ("height"); - id_name = val_id ("name"); - id_pixelFormat = val_id ("pixelFormat"); - id_refreshRate = val_id ("refreshRate"); - id_supportedModes = val_id ("supportedModes"); - id_width = val_id ("width"); - init = true; - - } - - int numDevices = SDL_GetNumVideoDisplays (); - value devices = alloc_array (numDevices); - - value display, supportedModes, mode; - int numDisplayModes; - SDL_Rect bounds = { 0, 0, 0, 0 }; - SDL_DisplayMode currentDisplayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; - SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; - - for (int i = 0; i < numDevices; i++) { - - display = alloc_empty_object (); - alloc_field (display, id_name, alloc_string (SDL_GetDisplayName (i))); - SDL_GetDisplayBounds (i, &bounds); - alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ()); - - SDL_GetCurrentDisplayMode (i, ¤tDisplayMode); - numDisplayModes = SDL_GetNumDisplayModes (i); - supportedModes = alloc_array (numDisplayModes); - - for (int j = 0; j < numDisplayModes; j++) { - - SDL_GetDisplayMode (i, j, &displayMode); - - if (displayMode.format == currentDisplayMode.format && displayMode.w == currentDisplayMode.w && displayMode.h == currentDisplayMode.h && displayMode.refresh_rate == currentDisplayMode.refresh_rate) { - - alloc_field (display, id_currentMode, alloc_int (j)); - - } - - mode = alloc_empty_object (); - alloc_field (mode, id_height, alloc_int (displayMode.h)); - - switch (displayMode.format) { - - case SDL_PIXELFORMAT_ARGB8888: - - alloc_field (mode, id_pixelFormat, alloc_int (ARGB32)); - break; - - case SDL_PIXELFORMAT_BGRA8888: - case SDL_PIXELFORMAT_BGRX8888: - - alloc_field (mode, id_pixelFormat, alloc_int (BGRA32)); - break; - - default: - - alloc_field (mode, id_pixelFormat, alloc_int (RGBA32)); - - } - - alloc_field (mode, id_refreshRate, alloc_int (displayMode.refresh_rate)); - alloc_field (mode, id_width, alloc_int (displayMode.w)); - - val_array_set_i (supportedModes, j, mode); - - } - - alloc_field (display, id_supportedModes, supportedModes); - val_array_set_i (devices, i, display); - - } - - return devices; - - } - - -} \ No newline at end of file diff --git a/project/src/backend/sdl/SDLSystem.cpp b/project/src/backend/sdl/SDLSystem.cpp index 1168796b5..842791c6a 100644 --- a/project/src/backend/sdl/SDLSystem.cpp +++ b/project/src/backend/sdl/SDLSystem.cpp @@ -1,3 +1,5 @@ +#include +#include #include #ifdef HX_MACOS @@ -26,15 +28,24 @@ #endif #endif -#include -#include -#include +#include #include namespace lime { + static int id_bounds; + static int id_currentMode; + static int id_height; + static int id_name; + static int id_pixelFormat; + static int id_refreshRate; + static int id_supportedModes; + static int id_width; + static bool init = false; + + const char* System::GetDirectory (SystemDirectory type, const char* company, const char* title) { switch (type) { @@ -168,6 +179,98 @@ namespace lime { } + value System::GetDisplay (int id) { + + if (!init) { + + id_bounds = val_id ("bounds"); + id_currentMode = val_id ("currentMode"); + id_height = val_id ("height"); + id_name = val_id ("name"); + id_pixelFormat = val_id ("pixelFormat"); + id_refreshRate = val_id ("refreshRate"); + id_supportedModes = val_id ("supportedModes"); + id_width = val_id ("width"); + init = true; + + } + + int numDisplays = GetNumDisplays (); + + if (id < 0 || id >= numDisplays) { + + return alloc_null (); + + } + + value display = alloc_empty_object (); + alloc_field (display, id_name, alloc_string (SDL_GetDisplayName (id))); + + SDL_Rect bounds = { 0, 0, 0, 0 }; + SDL_GetDisplayBounds (id, &bounds); + alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ()); + + SDL_DisplayMode currentDisplayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + + SDL_GetCurrentDisplayMode (id, ¤tDisplayMode); + + int numDisplayModes = SDL_GetNumDisplayModes (id); + value supportedModes = alloc_array (numDisplayModes); + value mode; + + for (int i = 0; i < numDisplayModes; i++) { + + SDL_GetDisplayMode (id, i, &displayMode); + + if (displayMode.format == currentDisplayMode.format && displayMode.w == currentDisplayMode.w && displayMode.h == currentDisplayMode.h && displayMode.refresh_rate == currentDisplayMode.refresh_rate) { + + alloc_field (display, id_currentMode, alloc_int (i)); + + } + + mode = alloc_empty_object (); + alloc_field (mode, id_height, alloc_int (displayMode.h)); + + switch (displayMode.format) { + + case SDL_PIXELFORMAT_ARGB8888: + + alloc_field (mode, id_pixelFormat, alloc_int (ARGB32)); + break; + + case SDL_PIXELFORMAT_BGRA8888: + case SDL_PIXELFORMAT_BGRX8888: + + alloc_field (mode, id_pixelFormat, alloc_int (BGRA32)); + break; + + default: + + alloc_field (mode, id_pixelFormat, alloc_int (RGBA32)); + + } + + alloc_field (mode, id_refreshRate, alloc_int (displayMode.refresh_rate)); + alloc_field (mode, id_width, alloc_int (displayMode.w)); + + val_array_set_i (supportedModes, i, mode); + + } + + alloc_field (display, id_supportedModes, supportedModes); + return display; + + } + + + int System::GetNumDisplays () { + + return SDL_GetNumVideoDisplays (); + + } + + double System::GetTimer () { return SDL_GetTicks ();