Author: matt
Date: 2011-01-06 17:01:04 -0800 (Thu, 06 Jan 2011)
New Revision: 8204
Log:
First attempt at finding the screen pixel sizes. Can't test Xinerame, 
MSWindows, or X11 yet.

Modified:
   branches/branch-1.3/FL/Fl.H
   branches/branch-1.3/FL/mac.H
   branches/branch-1.3/src/Fl_cocoa.mm
   branches/branch-1.3/src/screen_xywh.cxx
   branches/branch-1.3/test/hello.cxx

Modified: branches/branch-1.3/FL/Fl.H
===================================================================
--- branches/branch-1.3/FL/Fl.H 2011-01-06 21:48:37 UTC (rev 8203)
+++ branches/branch-1.3/FL/Fl.H 2011-01-07 01:01:04 UTC (rev 8204)
@@ -773,7 +773,8 @@
     screen_xywh(X, Y, W, H, e_x_root, e_y_root);
   }
   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
-  static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
+  static void screen_xywh(int &X, int &Y, int &W, int &H, int n);  
+  static void screen_dpi(float &h, float &v, int n=0);
 
   /**   @} */
 

Modified: branches/branch-1.3/FL/mac.H
===================================================================
--- branches/branch-1.3/FL/mac.H        2011-01-06 21:48:37 UTC (rev 8203)
+++ branches/branch-1.3/FL/mac.H        2011-01-07 01:01:04 UTC (rev 8204)
@@ -145,7 +145,7 @@
   void contains_GL_subwindow(void);
   void set_key_window(void);
   void set_cursor(Fl_Cursor);
-  static int screen_init(XRectangle screens[]);
+  static int screen_init(XRectangle screens[], float dpi[]);
   static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int 
w, int h);
   static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, 
int w, int h, int *bytesPerPixel);
   static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int 
y,int w, int h);

Modified: branches/branch-1.3/src/Fl_cocoa.mm
===================================================================
--- branches/branch-1.3/src/Fl_cocoa.mm 2011-01-06 21:48:37 UTC (rev 8203)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2011-01-07 01:01:04 UTC (rev 8204)
@@ -2715,7 +2715,7 @@
   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 @@
     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;
   }

Modified: branches/branch-1.3/src/screen_xywh.cxx
===================================================================
--- branches/branch-1.3/src/screen_xywh.cxx     2011-01-06 21:48:37 UTC (rev 
8203)
+++ branches/branch-1.3/src/screen_xywh.cxx     2011-01-07 01:01:04 UTC (rev 
8204)
@@ -56,17 +56,29 @@
 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 @@
   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 @@
   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 @@
 }
 
 
+/**
+ 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$".
 //

Modified: branches/branch-1.3/test/hello.cxx
===================================================================
--- branches/branch-1.3/test/hello.cxx  2011-01-06 21:48:37 UTC (rev 8203)
+++ branches/branch-1.3/test/hello.cxx  2011-01-07 01:01:04 UTC (rev 8204)
@@ -30,6 +30,9 @@
 #include <FL/Fl_Box.H>
 
 int main(int argc, char **argv) {
+  float h, v;
+  Fl::screen_dpi(h, v);
+  printf("Screen res is %g x %g ppi\n", h, v);
   Fl_Window *window = new Fl_Window(340,180);
   Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
   box->box(FL_UP_BOX);

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to