File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
#include " platform/CCDevice.h"
2
+ #include < X11/Xlib.h>
3
+ #include < stdio.h>
2
4
3
5
NS_CC_BEGIN
4
6
5
7
float CCDevice::getDPI ()
6
8
{
7
-
9
+ static int dpi = -1 ;
10
+ if (dpi == -1 )
11
+ {
12
+ Display *dpy;
13
+ char *displayname = NULL ;
14
+ int scr = 0 ; /* Screen number */
15
+ dpy = XOpenDisplay (displayname);
16
+ /*
17
+ * there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
18
+ *
19
+ * dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
20
+ * = N pixels / (M inch / 25.4)
21
+ * = N * 25.4 pixels / M inch
22
+ */
23
+ double xres = ((((double ) DisplayWidth (dpy,scr)) * 25.4 ) /
24
+ ((double ) DisplayWidthMM (dpy,scr)));
25
+ dpi = (int ) (xres + 0.5 );
26
+ printf (" dpi = %d\n " , dpi);
27
+ }
28
+ return dpi;
8
29
}
9
30
10
31
NS_CC_END
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ OBJECTS = ../actions/CCAction.o \
96
96
../platform/linux/CCApplication.o \
97
97
../platform/linux/CCEGLView.o \
98
98
../platform/linux/CCImage.o \
99
+ ../platform/linux/CCDevice.o \
99
100
../script_support/CCScriptSupport.o \
100
101
../sprite_nodes/CCAnimation.o \
101
102
../sprite_nodes/CCAnimationCache.o \
You can’t perform that action at this time.
0 commit comments