From bbd7d9cb5910448988ea3fbb6bb7b7c5bca75363 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 21 Jan 2015 12:09:50 +0000 Subject: Have Fl_Paged_Device::print_window() print window title bars with rounded angles under Yosemite also. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10529 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_cocoa.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 9cad4f3b6..e5db31868 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -4277,6 +4277,20 @@ int Fl_Window::decorated_h() return h() + bt + by; } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +// clip the graphics context to round top angles, as in window title bars +static void apply_titlebar_clipping(CGContextRef gc, int w, int h) { + const CGFloat radius = 4; + CGContextMoveToPoint(gc, 0, 0); + CGContextAddLineToPoint(gc, 0, h - radius); + CGContextAddArcToPoint(gc, 0, h, radius, h, radius); + CGContextAddLineToPoint(gc, w - radius, h); + CGContextAddArcToPoint(gc, w, h, w, h - radius, radius); + CGContextAddLineToPoint(gc, w, 0); + CGContextClip(gc); +} +#endif + void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset) { if (!win->shown() || win->parent() || !win->border() || !win->visible()) { @@ -4295,6 +4309,7 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset) CGContextSaveGState(fl_gc); CGContextTranslateCTM(fl_gc, x_offset - 0.5, y_offset + bt - 0.5); CGContextScaleCTM(fl_gc, 1, -1); + apply_titlebar_clipping(fl_gc, win->w(), bt); [layer renderInContext:fl_gc]; // 10.5 // print all title bar CGContextRestoreGState(fl_gc); } @@ -4302,6 +4317,8 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset) CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB (); CGContextRef gc = CGBitmapContextCreate(NULL, win->w(), bt, 8, 0, cspace, kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(cspace); + CGContextClearRect(gc, CGRectMake(0, 0, win->w(), bt)); + apply_titlebar_clipping(gc, win->w(), bt); [layer renderInContext:gc]; // 10.5 // draw all title bar to bitmap Fl_RGB_Image *image = new Fl_RGB_Image((const uchar*)CGBitmapContextGetData(gc), win->w(), bt, 4, CGBitmapContextGetBytesPerRow(gc)); // 10.2 -- cgit v1.2.3