mirror of https://github.com/axmolengine/axmol.git
issue #1712: Getting DPI support for Blackberry.
This commit is contained in:
parent
3dd792475f
commit
2b8ea8145a
|
@ -0,0 +1,40 @@
|
|||
#include "platform/CCDevice.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "CCCommon.h"
|
||||
#include <screen/screen.h>
|
||||
#include <math.h>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
float CCDevice::getDPI()
|
||||
{
|
||||
static int dpi = -1;
|
||||
if (dpi == -1)
|
||||
{
|
||||
screen_display_t screen_disp = CCEGLView::sharedOpenGLView()->getScreenDisplay();
|
||||
#ifdef BLACKBERRY10
|
||||
// Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale
|
||||
|
||||
screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi);
|
||||
#else
|
||||
// Playbook: 1024x600, 7", 170DPI, 1.25f scale
|
||||
int screen_phys_size[2];
|
||||
|
||||
screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size);
|
||||
//CCLog("screen_phys_size[%d,%d]", screen_phys_size[0], screen_phys_size[1]);
|
||||
|
||||
int screen_resolution[2];
|
||||
screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
|
||||
//CCLog("screen_resolution[%d,%d]", screen_resolution[0], screen_resolution[1]);
|
||||
double diagonal_pixels = sqrt((double)(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]));
|
||||
// 1 millimeter = 0.0393700787 inches
|
||||
double diagonal_inches = 0.0393700787 * sqrt((double)(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]));
|
||||
dpi = (int)(diagonal_pixels / diagonal_inches + 0.5);
|
||||
//CCLog("dpi = %d, pixel = %lf, inches = %lf", dpi, diagonal_pixels, diagonal_inches );
|
||||
#endif
|
||||
}
|
||||
//CCLog("dpi = %d", dpi);
|
||||
return dpi;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -401,18 +401,23 @@ bool CCEGLView::initGL()
|
|||
screen_res[0] = atoi(width_str);
|
||||
screen_res[1] = atoi(height_str);
|
||||
|
||||
int rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res);
|
||||
rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, screen_res);
|
||||
if (rc)
|
||||
{
|
||||
fprintf(stderr, "screen_set_window_property_iv(SCREEN_PROPERTY_BUFFER_SIZE)");
|
||||
return false;
|
||||
}
|
||||
|
||||
rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_display);
|
||||
if (rc)
|
||||
{
|
||||
perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
screen_display_t screen_display;
|
||||
rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&screen_display);
|
||||
rc = screen_get_window_property_pv(m_screenWindow, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_display);
|
||||
if (rc)
|
||||
{
|
||||
perror("screen_get_window_property_pv(SCREEN_PROPERTY_DISPLAY)");
|
||||
|
@ -420,7 +425,7 @@ bool CCEGLView::initGL()
|
|||
}
|
||||
|
||||
screen_display_mode_t screen_mode;
|
||||
rc = screen_get_display_property_pv(screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
|
||||
rc = screen_get_display_property_pv(m_screen_display, SCREEN_PROPERTY_MODE, (void**)&screen_mode);
|
||||
if (rc)
|
||||
{
|
||||
perror("screen_get_display_property_pv(SCREEN_PROPERTY_MODE)");
|
||||
|
@ -793,4 +798,9 @@ bool CCEGLView::handleEvents()
|
|||
return true;
|
||||
}
|
||||
|
||||
screen_display_t CCEGLView::getScreenDisplay() const
|
||||
{
|
||||
return m_screen_display;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
static CCEGLView* sharedOpenGLView();
|
||||
|
||||
bool handleEvents();
|
||||
screen_display_t getScreenDisplay() const;
|
||||
|
||||
private:
|
||||
void release();
|
||||
|
@ -89,6 +90,7 @@ private:
|
|||
screen_event_t m_screenEvent;
|
||||
screen_window_t m_screenWindow;
|
||||
screen_context_t m_screenContext;
|
||||
screen_display_t m_screen_display;
|
||||
char m_windowGroupID[16];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue