Simplify display.dpi to diagonal value
This commit is contained in:
@@ -2,6 +2,7 @@ package lime.system;
|
||||
|
||||
|
||||
import lime.math.Rectangle;
|
||||
import lime.system.display;
|
||||
|
||||
|
||||
class Display {
|
||||
@@ -22,7 +23,7 @@ class Display {
|
||||
/**
|
||||
* Pixel density of the display
|
||||
*/
|
||||
public var dpi (default, null): { diagonal:Float, horizontal:Float, vertical:Float };
|
||||
public var dpi (default, null):Float;
|
||||
|
||||
/**
|
||||
* The name of the device, such as "Samsung SyncMaster P2350", "iPhone 6", "Occulus Rift DK2", etc.
|
||||
|
||||
@@ -151,6 +151,8 @@ class System {
|
||||
display.id = id;
|
||||
display.name = displayInfo.name;
|
||||
display.bounds = new Rectangle (displayInfo.bounds.x, displayInfo.bounds.y, displayInfo.bounds.width, displayInfo.bounds.height);
|
||||
display.dpi = displayInfo.dpi;
|
||||
|
||||
display.supportedModes = [];
|
||||
|
||||
var displayMode;
|
||||
@@ -164,18 +166,6 @@ 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;
|
||||
|
||||
}
|
||||
@@ -434,7 +424,6 @@ 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,7 +28,6 @@ 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,12 +1160,6 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_system_get_display_dpi (int id) {
|
||||
|
||||
return System::GetDisplayDPI (id);
|
||||
|
||||
}
|
||||
|
||||
int lime_system_get_num_displays () {
|
||||
|
||||
return System::GetNumDisplays ();
|
||||
@@ -1518,7 +1512,6 @@ 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);
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace lime {
|
||||
|
||||
static int id_bounds;
|
||||
static int id_currentMode;
|
||||
static int id_dpi;
|
||||
static int id_height;
|
||||
static int id_name;
|
||||
static int id_pixelFormat;
|
||||
@@ -226,6 +227,7 @@ namespace lime {
|
||||
|
||||
id_bounds = val_id ("bounds");
|
||||
id_currentMode = val_id ("currentMode");
|
||||
id_dpi = val_id ("dpi");
|
||||
id_height = val_id ("height");
|
||||
id_name = val_id ("name");
|
||||
id_pixelFormat = val_id ("pixelFormat");
|
||||
@@ -251,6 +253,10 @@ namespace lime {
|
||||
SDL_GetDisplayBounds (id, &bounds);
|
||||
alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ());
|
||||
|
||||
float dpi = 0.0;
|
||||
SDL_GetDisplayDPI (id, &dpi, NULL, NULL);
|
||||
alloc_field (display, id_dpi, alloc_float (dpi));
|
||||
|
||||
SDL_DisplayMode currentDisplayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
||||
SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
||||
|
||||
@@ -304,27 +310,6 @@ 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 () {
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#include <graphics/ImageBuffer.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
static int id_bitsPerPixel;
|
||||
static int id_buffer;
|
||||
static int id_data;
|
||||
static int id_format;
|
||||
static int id_height;
|
||||
static int id_premultiplied;
|
||||
static int id_transparent;
|
||||
static int id_width;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
ImageBuffer::ImageBuffer () {
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
bitsPerPixel = 32;
|
||||
format = RGBA32;
|
||||
data = 0;
|
||||
premultiplied = false;
|
||||
transparent = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
ImageBuffer::ImageBuffer (value imageBuffer) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_bitsPerPixel = val_id ("bitsPerPixel");
|
||||
id_transparent = val_id ("transparent");
|
||||
id_buffer = val_id ("buffer");
|
||||
id_width = val_id ("width");
|
||||
id_height = val_id ("height");
|
||||
id_data = val_id ("data");
|
||||
id_format = val_id ("format");
|
||||
id_premultiplied = val_id ("premultiplied");
|
||||
init = true;
|
||||
|
||||
}
|
||||
|
||||
width = val_int (val_field (imageBuffer, id_width));
|
||||
height = val_int (val_field (imageBuffer, id_height));
|
||||
bitsPerPixel = val_int (val_field (imageBuffer, id_bitsPerPixel));
|
||||
format = (PixelFormat)val_int (val_field (imageBuffer, id_format));
|
||||
transparent = val_bool (val_field (imageBuffer, id_transparent));
|
||||
value data_value = val_field (imageBuffer, id_data);
|
||||
value buffer_value = val_field (data_value, id_buffer);
|
||||
premultiplied = val_bool (val_field (imageBuffer, id_premultiplied));
|
||||
data = new Bytes (buffer_value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ImageBuffer::~ImageBuffer () {
|
||||
|
||||
delete data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Blit (const unsigned char *data, int x, int y, int width, int height) {
|
||||
|
||||
if (x < 0 || x + width > this->width || y < 0 || y + height > this->height) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int stride = Stride ();
|
||||
unsigned char *bytes = this->data->Data ();
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
|
||||
memcpy (&bytes[(i + y) * this->width + x], &data[i * width], stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
||||
|
||||
this->bitsPerPixel = bitsPerPixel;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
int stride = Stride ();
|
||||
|
||||
if (!this->data) {
|
||||
|
||||
this->data = new Bytes (height * stride);
|
||||
|
||||
} else {
|
||||
|
||||
this->data->Resize (height * stride);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ImageBuffer::Stride () {
|
||||
|
||||
return width * (((bitsPerPixel + 3) & ~0x3) >> 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
value ImageBuffer::Value () {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_bitsPerPixel = val_id ("bitsPerPixel");
|
||||
id_transparent = val_id ("transparent");
|
||||
id_buffer = val_id ("buffer");
|
||||
id_width = val_id ("width");
|
||||
id_height = val_id ("height");
|
||||
id_data = val_id ("data");
|
||||
id_format = val_id ("format");
|
||||
id_premultiplied = val_id ("premultiplied");
|
||||
init = true;
|
||||
|
||||
}
|
||||
|
||||
mValue = alloc_empty_object ();
|
||||
alloc_field (mValue, id_width, alloc_int (width));
|
||||
alloc_field (mValue, id_height, alloc_int (height));
|
||||
alloc_field (mValue, id_bitsPerPixel, alloc_int (bitsPerPixel));
|
||||
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ());
|
||||
alloc_field (mValue, id_transparent, alloc_bool (transparent));
|
||||
alloc_field (mValue, id_format, alloc_int (format));
|
||||
alloc_field (mValue, id_premultiplied, alloc_bool (premultiplied));
|
||||
return mValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user