From f1c7d674d2d22cd14efb5e9a131c42bc5180cbcc Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 5 Dec 2014 17:18:19 +0000 Subject: [PATCH] Improved processing of retina displays: replace [NSWindow backingScaleFactor] that is not recommended. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10477 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/mac.H | 1 + src/Fl_cocoa.mm | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/FL/mac.H b/FL/mac.H index 3bb282905..31d23a83a 100644 --- a/FL/mac.H +++ b/FL/mac.H @@ -142,6 +142,7 @@ public: static void q_begin_image(CGRect&, int x, int y, int w, int h); static void q_end_image(); // Cocoa additions + static CGSize window_pixel_size(Fl_Window* win); void destroy(void); void map(void); void unmap(void); diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index af785d357..580310f1b 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2545,6 +2545,22 @@ static FLTextInputContext* fltextinputcontext_instance = nil; } @end +// returns the window size in pixels. +// On retina display, values are double of w() x h() +CGSize Fl_X::window_pixel_size(Fl_Window* win) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + if (fl_mac_os_version >= 100700 && win->shown()) { + NSSize s = [[win->i->xid contentView] convertSizeToBacking:NSMakeSize(win->w(), win->h())]; +#if __LP64__ + return s; +#else + return CGSizeMake(s.width, s.height); +#endif + } +#endif + return CGSizeMake(win->w(), win->h()); +} void Fl_Window::fullscreen_x() { _set_fullscreen(); @@ -2985,9 +3001,7 @@ void Fl_Window::make_current() if (make_current_counts) make_current_counts++; Fl_X::q_release_context(); fl_window = i->xid; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - Fl_X::set_high_resolution(fl_mac_os_version >= 100700 && [fl_window backingScaleFactor] > 1.0); -#endif + Fl_X::set_high_resolution( Fl_X::window_pixel_size(this).width > w() + 0.5 ); current_ = this; NSGraphicsContext *nsgc = through_drawRect ? [NSGraphicsContext currentContext] :