summaryrefslogtreecommitdiff
path: root/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-10-12 21:05:27 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-10-12 21:05:38 +0200
commit0d8385a652441440d8fa2db15bd40d4d5cf4e734 (patch)
tree07001b71b6bd5940f300bc8fbdeca5af831a72f4 /src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
parent5830226aab4428e77e7aa4078e0f544aef92f326 (diff)
Simpler macOS implementation of capture of window titlebars.
Diffstat (limited to 'src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm83
1 files changed, 0 insertions, 83 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
index 9cf95a24a..1f7511c9e 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
+++ b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm
@@ -68,7 +68,6 @@ private:
void untranslate(void);
int end_page (void);
void end_job (void);
- void draw_decorated_window(Fl_Window *win, int x_offset, int y_offset);
~Fl_Cocoa_Printer_Driver(void);
};
@@ -388,85 +387,3 @@ void Fl_Cocoa_Printer_Driver::origin(int *x, int *y)
{
Fl_Paged_Device::origin(x, y);
}
-
-void Fl_Cocoa_Printer_Driver::draw_decorated_window(Fl_Window *win, int x_offset, int y_offset)
-{
- if (!win->shown() || win->parent() || !win->border() || !win->visible()) {
- this->print_widget(win, x_offset, y_offset);
- return;
- }
- int bt, hleft, hright, hbottom;
- Fl_Cocoa_Window_Driver::driver(win)->decoration_sizes(&bt, &hleft, &hright, &hbottom);
- float s = Fl::screen_scale(win->screen_num());
- if (s < 1) y_offset += bt*(1/s-1);
- CALayer *layer = Fl_Cocoa_Window_Driver::driver(win)->get_titlebar_layer();
- if (layer) { // if title bar uses a layer
- CGContextRef gc = (CGContextRef)driver()->gc();
- CGContextSaveGState(gc);
- CGContextTranslateCTM(gc, x_offset - 0.5, y_offset + bt - 0.5);
- CGContextScaleCTM(gc, 1/s, -1/s);
- Fl_Cocoa_Window_Driver::driver(win)->draw_layer_to_context(layer, gc, win->w() * s, bt);
- CGContextRestoreGState(gc);
- bool clip_corners = fl_mac_os_version >= 100600 && !win->parent();
- if (clip_corners) {
- CGContextRef gc = (CGContextRef)driver()->gc();
- CGContextSaveGState(gc);
- CGContextTranslateCTM(gc, x_offset, y_offset + bt );
- Fl_Cocoa_Window_Driver::clip_to_rounded_corners(gc, win->w(), win->h());
- CGContextTranslateCTM(gc, -x_offset, -y_offset - bt);
- }
- this->print_widget(win, x_offset, y_offset + bt);
- if (clip_corners) {
- CGContextRestoreGState((CGContextRef)driver()->gc());
- }
- return;
- }
- Fl_Display_Device::display_device()->set_current(); // send win to front and make it current
- NSString *title = [(NSWindow*)fl_xid(win) title];
- [title retain];
- [(NSWindow*)fl_xid(win) setTitle:@""]; // temporarily set a void window title
- win->show();
- Fl::check();
- // capture the window title bar with no title
- Fl_RGB_Image *top, *left, *bottom, *right;
- Fl_Window_Driver::driver(win)->capture_titlebar_and_borders(top, left, bottom, right);
- [(NSWindow*)fl_xid(win) setTitle:title]; // put back the window title
- this->set_current(); // back to the Fl_Paged_Device
- top->scale(win->w(), bt/s, 0, 1);
- top->draw(x_offset, y_offset + bt - bt/s); // print the title bar
- delete top;
- if (win->label()) { // print the window title
- const int skip = 65; // approx width of the zone of the 3 window control buttons
- float fs = [NSFont systemFontSize]/s;
- int text_y = y_offset+bt*(1-1/(2*s))+fs/3;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( fl_mac_os_version >= 100400 ) { // use Cocoa string drawing with exact title bar font
- // the exact font is LucidaGrande 13 pts (and HelveticaNeueDeskInterface-Regular with 10.10)
- NSGraphicsContext *current = [NSGraphicsContext currentContext];
- [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:driver()->gc() flipped:YES]];//10.4
- NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSFont titleBarFontOfSize:fs]
- forKey:NSFontAttributeName];
- NSSize size = [title sizeWithAttributes:attr];
- int x = x_offset + win->w()/2 - size.width/2;
- if (x < x_offset+skip) x = x_offset+skip;
- NSRect r = NSMakeRect(x, text_y , win->w() - skip, bt);
- [[NSGraphicsContext currentContext] setShouldAntialias:YES];
- [title drawWithRect:r options:(NSStringDrawingOptions)0 attributes:attr]; // 10.4
- [[NSGraphicsContext currentContext] setShouldAntialias:NO];
- [NSGraphicsContext setCurrentContext:current];
- }
- else
-#endif
- {
- fl_font(FL_HELVETICA, fs);
- fl_color(FL_BLACK);
- int x = x_offset + win->w()/2 - fl_width(win->label())/2;
- if (x < x_offset+skip) x = x_offset+skip;
- fl_push_clip(x_offset, y_offset + bt - bt/s, win->w(), bt/s);
- fl_draw(win->label(), x, text_y);
- fl_pop_clip();
- }
- }
- [title release];
- this->print_widget(win, x_offset, y_offset + bt); // print the window inner part
-}