ios: add method for calculating DPI and read UIscreen scale

This commit is contained in:
Mathieu Virbel 2012-11-02 20:03:50 +01:00
parent 2a0d4408d2
commit f24fc6844f
3 changed files with 33 additions and 0 deletions

View file

@ -14,6 +14,8 @@ cdef extern from "ios_wrapper.h":
int ios_send_email(char *subject, char *text, char *mimetype, char
*filename, char *filename_alias, ios_send_email_cb cb, void *userdata)
void ios_open_url(char *url)
float ios_uiscreen_get_scale()
int ios_uiscreen_get_dpi()
cdef void _send_email_done(char *status, void *data):
cdef object callback = <object>data
@ -159,3 +161,13 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None,
return 0
return 1
def get_scale():
'''Return the UIScreen scale (1 on iPad, 2 on iPad 3)
'''
return ios_uiscreen_get_scale()
def get_dpi():
'''Return the approximate DPI of the screen
'''
return ios_uiscreen_get_dpi()

View file

@ -109,3 +109,22 @@ int ios_send_email(char *subject, char *text, char *mimetype, char *filename,
return 1;
}
float ios_uiscreen_get_scale() {
float scale = 1.0;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
scale = [[UIScreen mainScreen] scale];
};
return scale;
}
int ios_uiscreen_get_dpi() {
float scale = ios_uiscreen_get_scale();
float dpi = 160 * scale;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
dpi = 132 * scale;
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
dpi = 163 * scale;
}
return dpi;
}

View file

@ -1,6 +1,8 @@
#ifndef __IOS_WRAPPER
#define __IOS_WRAPPER
float ios_uiscreen_get_scale(void);
int ios_uiscreen_get_dpi(void);
void ios_open_url(char *url);
typedef void (*ios_send_email_cb)(char *, void *);