Remove small duplication of code

This commit is contained in:
ManoloFLTK 2019-05-20 13:16:31 +02:00
parent 357dad1e51
commit 159572785d
3 changed files with 7 additions and 11 deletions

View File

@ -4228,9 +4228,9 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep_layer(Fl_Window *win, int x, i
CGContextRef gc = ((FLViewLayer*)[fl_xid(win) contentView])->layer_data;
if (!gc) return nil;
CGImageRef cgimg = CGBitmapContextCreateImage(gc); // requires 10.4
float s = Fl::screen_driver()->scale(0);
int resolution = Fl_Cocoa_Window_Driver::driver(win->top_window())->mapped_to_retina() ? 2 : 1;
if (x || y || w != win->w() || h != win->h()) {
float s = Fl::screen_driver()->scale(0);
CGRect rect = CGRectMake(x * s * resolution, y * s * resolution, w * s * resolution, h * s * resolution);
CGImageRef cgimg2 = CGImageCreateWithImageInRect(cgimg, rect);
CGImageRelease(cgimg);
@ -4356,11 +4356,11 @@ int Fl_Cocoa_Window_Driver::decorated_h()
return h() + bt + by;
}
static CALayer *get_titlebar_layer(Fl_Window *win)
CALayer *Fl_Cocoa_Window_Driver::get_titlebar_layer()
{
// a compilation warning appears with SDK 10.5, so we require SDK 10.6 instead
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
return fl_mac_os_version >= 101000 ? [[[fl_xid(win) standardWindowButton:NSWindowCloseButton] superview] layer] : nil; // 10.5
return fl_mac_os_version >= 101000 ? [[[fl_xid(pWindow) standardWindowButton:NSWindowCloseButton] superview] layer] : nil; // 10.5
#else
return nil;
#endif
@ -4387,7 +4387,7 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl
{
left = bottom = right = NULL;
int htop = pWindow->decorated_h() - h();
CALayer *layer = get_titlebar_layer(pWindow);
CALayer *layer = get_titlebar_layer();
CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
float s = Fl::screen_driver()->scale(screen_num());
int scaled_w = int(w() * s);

View File

@ -374,11 +374,7 @@ void Fl_Cocoa_Printer_Driver::draw_decorated_window(Fl_Window *win, int x_offset
}
int bt = win->decorated_h() - win->h();
BOOL to_quartz = (this->driver()->has_feature(Fl_Graphics_Driver::NATIVE));
CALayer *layer = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
if (fl_mac_os_version >= 101000) layer = [[[fl_xid(win) standardWindowButton:NSWindowCloseButton] superview] layer];
#endif
CALayer *layer = Fl_Cocoa_Window_Driver::driver(win)->get_titlebar_layer();
if (layer) { // if title bar uses a layer
if (to_quartz) { // to Quartz printer
CGContextRef gc = (CGContextRef)driver()->gc();

View File

@ -136,10 +136,10 @@ public:
virtual int set_cursor(const Fl_RGB_Image*, int, int);
virtual void shape(const Fl_Image* img);
// that one is implemented in Fl_Cocoa.mm because it uses Objective-c
// next 4 are in Fl_cocoa.mm because they use Objective-c
virtual void capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl_RGB_Image*& left, Fl_RGB_Image*& bottom, Fl_RGB_Image*& right);
//this one is in Fl_cocoa.mm because it uses Objective-c
virtual void wait_for_expose();
CALayer *get_titlebar_layer();
static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h);
virtual int scroll(int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, void (*draw_area)(void*, int,int,int,int), void* data);