Author: manolo
Date: 2011-04-22 10:30:37 -0700 (Fri, 22 Apr 2011)
New Revision: 8619
Log:
Mac OS: exact implementation of the Fl::screen_dpi() function.

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

Modified: branches/branch-1.3/FL/mac.H
===================================================================
--- branches/branch-1.3/FL/mac.H        2011-04-22 11:00:06 UTC (rev 8618)
+++ branches/branch-1.3/FL/mac.H        2011-04-22 17:30:37 UTC (rev 8619)
@@ -143,7 +143,6 @@
   void contains_GL_subwindow(void);
   void set_key_window(void);
   void set_cursor(Fl_Cursor);
-  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-04-22 11:00:06 UTC (rev 8618)
+++ branches/branch-1.3/src/Fl_cocoa.mm 2011-04-22 17:30:37 UTC (rev 8619)
@@ -2823,37 +2823,6 @@
   cursor = icrsr;
 }
 
-int Fl_X::screen_init(XRectangle screens[], float dpi[])
-{
-  NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init]; 
-  NSArray *a = [NSScreen screens]; 
-  NSScreen *object;
-  int count = (int)[a count]; 
-  NSRect r; 
-  int i, num_screens = 0;
-  for( i = 0; i < count; i++) {
-    object = (NSScreen*)[a objectAtIndex:i];
-    r = [object frame];
-    screens[num_screens].x      = int(r.origin.x);
-    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);
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
-    if ([object respondsToSelector:@selector(userSpaceScaleFactor)]) {
-      dpi[num_screens] = float([object userSpaceScaleFactor])*72.0f;
-    } else 
-#endif
-    {
-      dpi[num_screens] = 72.0f;
-    }
-       
-    num_screens ++;
-    if (num_screens >= 16) break;
-  }
-  [localPool release];
-  return num_screens;
-}
-
 @interface FLaboutItemTarget : NSObject 
 {
 }

Modified: branches/branch-1.3/src/screen_xywh.cxx
===================================================================
--- branches/branch-1.3/src/screen_xywh.cxx     2011-04-22 11:00:06 UTC (rev 
8618)
+++ branches/branch-1.3/src/screen_xywh.cxx     2011-04-22 17:30:37 UTC (rev 
8619)
@@ -118,10 +118,25 @@
 }
 #elif defined(__APPLE__)
 static XRectangle screens[16];
-static float dpi[16];
+static float dpi_h[16];
+static float dpi_v[16];
 
 static void screen_init() {
-  num_screens = Fl_X::screen_init(screens, dpi);
+  CGDirectDisplayID displays[16];
+  CGDisplayCount count, i;
+  CGRect r;
+  CGGetActiveDisplayList(16, displays, &count);
+  for( i = 0; i < count; i++) {
+    r = CGDisplayBounds(displays[i]);
+    screens[i].x      = int(r.origin.x);
+    screens[i].y      = int(r.size.height - (r.origin.y + r.size.height));
+    screens[i].width  = int(r.size.width);
+    screens[i].height = int(r.size.height);
+    CGSize s = CGDisplayScreenSize(displays[i]);
+    dpi_h[i] = screens[i].width / (s.width/25.4);
+    dpi_v[i] = screens[i].height / (s.height/25.4);
+  }
+  num_screens = count;
 }
 #elif HAVE_XINERAMA
 #  include <X11/extensions/Xinerama.h>
@@ -338,7 +353,8 @@
   }
 #elif defined(__APPLE__)
   if (n >= 0 && n < num_screens) {
-    h = v = dpi[n];
+    h = dpi_h[n];
+    v = dpi_v[n];
   }
 #elif HAVE_XINERAMA
   if (n >= 0 && n < num_screens) {

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

Reply via email to