Mac OS: have Fl_Paged_Device::print_widget() print top-level windows with

rounded bottom corners as they appear on screen.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10916 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2015-11-19 16:33:44 +00:00
parent 0d2517331c
commit 511ec0bb3d
3 changed files with 16 additions and 8 deletions

View File

@ -211,6 +211,7 @@ public:
static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
static void clip_to_rounded_corners(CGContextRef gc, int w, int h);
private:
#if FLTK_ABI_VERSION >= 10304
CGRect* subRect_; // makes sure subwindow remains inside its parent window

View File

@ -56,7 +56,16 @@ void Fl_Paged_Device::print_widget(Fl_Widget* widget, int delta_x, int delta_y)
translate(new_x - old_x, new_y - old_y );
}
// if widget is a main window, clip all drawings to the window area
if (is_window && !widget->window()) fl_push_clip(0, 0, widget->w(), widget->h() );
if (is_window && !widget->window()) {
fl_push_clip(0, 0, widget->w(), widget->h() );
#ifdef __APPLE__ // for Mac OS X 10.6 and above, make window with rounded bottom corners
if ( fl_mac_os_version >= 100600 && driver()->class_name() == Fl_Quartz_Graphics_Driver::class_id ) {
CGContextRestoreGState(fl_gc);
Fl_X::clip_to_rounded_corners(fl_gc, widget->w(), widget->h());
CGContextSaveGState(fl_gc);
}
#endif
}
// we do some trickery to recognize OpenGL windows and draw them via a plugin
int drawn_by_plugin = 0;
if (widget->as_gl_window()) {

View File

@ -4376,10 +4376,9 @@ 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;
// clip the graphics context to rounded corners
void Fl_X::clip_to_rounded_corners(CGContextRef gc, int w, int h) {
const CGFloat radius = 5;
CGContextMoveToPoint(gc, 0, 0);
CGContextAddLineToPoint(gc, 0, h - radius);
CGContextAddArcToPoint(gc, 0, h, radius, h, radius);
@ -4388,7 +4387,6 @@ static void apply_titlebar_clipping(CGContextRef gc, int w, int h) {
CGContextAddLineToPoint(gc, w, 0);
CGContextClip(gc);
}
#endif
void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
{
@ -4408,7 +4406,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);
Fl_X::clip_to_rounded_corners(fl_gc, win->w(), bt);
[layer renderInContext:fl_gc]; // 10.5 // print all title bar
CGContextRestoreGState(fl_gc);
}
@ -4417,7 +4415,7 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
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);
Fl_X::clip_to_rounded_corners(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