displays -- add bounds

This commit is contained in:
Lars A. Doucet
2015-07-30 16:23:30 -05:00
parent 691de634e3
commit 8c24a8ad24
4 changed files with 45 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
package lime.system;
import lime.math.Rectangle;
import lime.math.Vector2;
import lime.system.Display;
@@ -11,6 +12,8 @@ class Display {
/********STATIC*********/
public static var devices = new Map<Int, Display> ();
/**How many display devices are currently connected and actively displaying visuals**/
public static var numDisplays(get, null):Int;
/**
@@ -29,17 +32,6 @@ class Display {
}
/**
* Get the total number of connected displays
* @return
*/
public static function get_numDisplays():Int {
return lime_display_get_num_devices();
}
/**
* Get the display device with the given id
* @param id
@@ -57,6 +49,16 @@ class Display {
return null;
}
/**
* Get the total number of connected displays
* @return
*/
private static function get_numDisplays():Int {
return lime_display_get_num_devices();
}
/*********INSTANCE**********/
@@ -79,6 +81,9 @@ class Display {
/**All of the display modes supported by this device**/
public var modes(default, null):Array<DisplayMode>;
/**The desktop area represented by this display, with the upper-leftmost display at 0,0**/
public var bounds(default, null):Rectangle;
private function new(id:Int) {
this.id = id;
@@ -94,11 +99,15 @@ class Display {
name = lime_display_get_name(id);
var obj = lime_display_get_current_display_mode(id);
mode = new DisplayMode(obj.width, obj.height, obj.refresh_rate, obj.format);
var obj = null;
obj = lime_display_get_current_display_mode(id);
mode = new DisplayMode(obj.width, obj.height, obj.refresh_rate, obj.format);
resolution = new Resolution(mode.width, mode.height);
obj = lime_display_get_display_bounds(id);
bounds = new Rectangle(obj.x, obj.y, obj.width, obj.height);
modes = [];
var numModes = lime_display_get_num_display_modes(id);
@@ -130,6 +139,7 @@ class Display {
private static var lime_display_get_num_devices = System.load("lime", "lime_display_get_num_devices", 0);
private static var lime_display_get_name = System.load ("lime", "lime_display_get_name", 1);
private static var lime_display_get_num_display_modes = System.load ("lime", "lime_display_get_num_display_modes", 1);
private static var lime_display_get_display_bounds = System.load ("lime", "lime_display_get_display_bounds", 1);
private static var lime_display_get_display_mode = System.load ("lime", "lime_display_get_display_mode", 2);
private static var lime_display_get_current_display_mode = System.load ("lime", "lime_display_get_current_display_mode", 1);

View File

@@ -13,6 +13,7 @@ namespace lime {
static value GetCurrentDisplayMode (int displayIndex);
static value GetDisplayMode (int displayIndex, int modeIndex);
static value GetDisplayBounds (int displayIndex);
static int GetNumDevices ();
static const char* GetDisplayName (int displayIndex);
static int GetNumDisplayModes (int displayIndex);

View File

@@ -391,6 +391,12 @@ namespace lime {
}
value lime_display_get_display_bounds (value displayIndex) {
return Display::GetDisplayBounds(val_int(displayIndex));
}
value lime_display_get_current_display_mode (value displayIndex) {
return Display::GetCurrentDisplayMode(val_int(displayIndex));
@@ -1202,6 +1208,7 @@ namespace lime {
DEFINE_PRIM (lime_font_render_glyph, 3);
DEFINE_PRIM (lime_font_render_glyphs, 3);
DEFINE_PRIM (lime_font_set_size, 2);
DEFINE_PRIM (lime_display_get_display_bounds, 1);
DEFINE_PRIM (lime_display_get_current_display_mode, 1);
DEFINE_PRIM (lime_display_get_display_mode, 2);
DEFINE_PRIM (lime_display_get_name, 1);

View File

@@ -4,6 +4,20 @@
namespace lime {
value Display::GetDisplayBounds (int displayIndex) {
SDL_Rect rect = { 0, 0, 0, 0};
SDL_GetDisplayBounds(displayIndex, &rect);
value mValue = alloc_empty_object ();
alloc_field (mValue, val_id("x"), alloc_int(rect.x));
alloc_field (mValue, val_id("y"), alloc_int(rect.y));
alloc_field (mValue, val_id("width"), alloc_int(rect.w));
alloc_field (mValue, val_id("height"), alloc_int(rect.h));
return mValue;
}
value Display::GetCurrentDisplayMode (int displayIndex) {
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };