summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2011-01-07 01:01:04 +0000
committerMatthias Melcher <fltk@matthiasm.com>2011-01-07 01:01:04 +0000
commit7dc05cb20ee92e38b3d1fbd88664e572d73a8d54 (patch)
treec1a4f03879c8c371a67e26c1213f45c5ee0ffebb /src
parentd6bffb20a3b75037d7e5811fdca87d0040873188 (diff)
First attempt at finding the screen pixel sizes. Can't test Xinerame, MSWindows, or X11 yet.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8204 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_cocoa.mm3
-rw-r--r--src/screen_xywh.cxx67
2 files changed, 66 insertions, 4 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 4dedbcf3e..a61efb0a2 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -2715,7 +2715,7 @@ void Fl_X::set_cursor(Fl_Cursor c)
cursor = icrsr;
}
-int Fl_X::screen_init(XRectangle screens[])
+int Fl_X::screen_init(XRectangle screens[], float dpi[])
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
NSArray *a = [NSScreen screens];
@@ -2728,6 +2728,7 @@ int Fl_X::screen_init(XRectangle screens[])
screens[num_screens].y = int(r.size.height - (r.origin.y + r.size.height));
screens[num_screens].width = int(r.size.width);
screens[num_screens].height = int(r.size.height);
+ dpi[num_screens] = float([[a objectAtIndex:i] userSpaceScaleFactor])*72.0f;
num_screens ++;
if (num_screens >= 16) break;
}
diff --git a/src/screen_xywh.cxx b/src/screen_xywh.cxx
index da219d9c0..e7c48c22d 100644
--- a/src/screen_xywh.cxx
+++ b/src/screen_xywh.cxx
@@ -56,17 +56,29 @@ typedef BOOL (WINAPI* fl_gmi_func)(HMONITOR, LPMONITORINFO);
static fl_gmi_func fl_gmi = NULL; // used to get a proc pointer for GetMonitorInfoA
static RECT screens[16];
+static int dpi[16][2] = { { 0.0f, 0.0f } };
static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM) {
if (num_screens >= 16) return TRUE;
- MONITORINFO mi;
+ MONITORINFOEX mi;
mi.cbSize = sizeof(mi);
// GetMonitorInfo(mon, &mi);
// (but we use our self-aquired function pointer instead)
if (fl_gmi(mon, &mi)) {
screens[num_screens] = mi.rcWork;
+
+ // find the pixel size
+ if (mi.cbSize == sizeof(mi)) {
+ HDC screen = CreateDC(mi.szDevice, NULL, NULL, NULL);
+ if (screen) {
+ dpi[num_screens][0] = (float)GetDeviceCaps(screen, LOGPIXELSX);
+ dpi[num_screens][1] = (float)GetDeviceCaps(screen, LOGPIXELSY);
+ }
+ ReleaseDC();
+ }
+
num_screens ++;
}
return TRUE;
@@ -105,16 +117,18 @@ static void screen_init() {
num_screens = 1;
}
#elif defined(__APPLE__)
-XRectangle screens[16];
+static XRectangle screens[16];
+static float dpi[16];
static void screen_init() {
- num_screens = Fl_X::screen_init(screens);
+ num_screens = Fl_X::screen_init(screens, dpi);
}
#elif HAVE_XINERAMA
# include <X11/extensions/Xinerama.h>
// Screen data...
static XineramaScreenInfo *screens;
+static float dpi[2];
static void screen_init() {
if (!fl_display) fl_open_display();
@@ -122,10 +136,22 @@ static void screen_init() {
if (XineramaIsActive(fl_display)) {
screens = XineramaQueryScreens(fl_display, &num_screens);
} else num_screens = 1;
+
+ int mm = DisplayWidthMM(fl_display, fl_screen);
+ dpi[0] = mm ? monitor.w()*25.4f/mm : 0.0f;
+ mm = DisplayHeightMM(fl_display, fl_screen);
+ dpi[1] = mm ? monitor.h()*25.4f/mm : dpi[0];
}
#else
+static XRectangle screen;
+static float dpi[2];
static void screen_init() {
num_screens = 1;
+ if (!fl_display) fl_open_display();
+ int mm = DisplayWidthMM(fl_display, fl_screen);
+ dpi[0] = mm ? monitor.w()*25.4f/mm : 0.0f;
+ mm = DisplayHeightMM(fl_display, fl_screen);
+ dpi[1] = mm ? monitor.h()*25.4f/mm : dpi[0];
}
#endif // WIN32
@@ -252,6 +278,41 @@ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n) {
}
+/**
+ Gets the screen resolution in dots-per-inch for the given screen.
+ \param[out] h, v horizontal and vertical resolution
+ \param[in] n the screen number (0 to Fl::screen_count() - 1)
+ \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
+ */
+void Fl::screen_dpi(float &h, float &v, int n)
+{
+ if (!num_screens) screen_init();
+ h = v = 0.0f;
+
+#ifdef WIN32
+ if (n >= 0 && n < num_screens) {
+ h = float(dpi[n][0]);
+ v = float(dpi[n][1]);
+ }
+#elif defined(__APPLE__)
+ if (n >= 0 && n < num_screens) {
+ h = v = dpi[n];
+ }
+#elif HAVE_XINERAMA
+ if (n >= 0 && n < num_screens) {
+ h = dpi[0];
+ v = dpi[1];
+ }
+#else
+ if (n >= 0 && n < num_screens) {
+ h = dpi[0];
+ v = dpi[1];
+ }
+#endif // WIN32
+}
+
+
+
//
// End of "$Id$".
//