diff options
| author | Manolo Gouy <Manolo> | 2011-04-22 17:30:37 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2011-04-22 17:30:37 +0000 |
| commit | 65b9610a9679ba00a86c64548fab7fcd8c906bbf (patch) | |
| tree | 9380959918725b573e114d1d1fd528c7f4ed449b | |
| parent | 239489c4b885eec8c58b07f4a2285f19e906c33e (diff) | |
Mac OS: exact implementation of the Fl::screen_dpi() function.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8619 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | FL/mac.H | 1 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 31 | ||||
| -rw-r--r-- | src/screen_xywh.cxx | 22 |
3 files changed, 19 insertions, 35 deletions
@@ -143,7 +143,6 @@ public: 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); diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 721831079..7ed48cc7c 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2823,37 +2823,6 @@ void Fl_X::set_cursor(Fl_Cursor c) 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 { } diff --git a/src/screen_xywh.cxx b/src/screen_xywh.cxx index 3cac43fbb..39b979e07 100644 --- a/src/screen_xywh.cxx +++ b/src/screen_xywh.cxx @@ -118,10 +118,25 @@ static void screen_init() { } #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 @@ void Fl::screen_dpi(float &h, float &v, int n) } #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) { |
