[master] 8ba68dd - macOS: increase resolution when drawing window titlebars to PostScript

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 8ba68dd - macOS: increase resolution when drawing window titlebars to PostScript "ManoloFLTK" 06:32 Sep 19 top right image
 
commit 8ba68dd27556fcc72afefc117e00139b186a5b80
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Sat Sep 19 15:25:50 2020 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Sat Sep 19 15:26:02 2020 +0200

    macOS: increase resolution when drawing window titlebars to PostScript

 src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
index 97ff298..e17c983 100644
--- src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
+++ src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx
@@ -320,17 +320,19 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl
   CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
   float s = Fl::screen_driver()->scale(screen_num());
   int scaled_w = int(w() * s);
-  uchar *rgba = new uchar[4 * scaled_w * htop * 4];
-  CGContextRef auxgc = CGBitmapContextCreate(rgba, 2 * scaled_w, 2 * htop, 8, 8 * scaled_w, cspace, kCGImageAlphaPremultipliedLast);
+  const int factor = (layer ? 4 : 2); // resolution level for the titlebar (2 == retina's)
+  int data_w = factor * scaled_w, data_h = factor * htop;
+  uchar *rgba = new uchar[4 * data_w * data_h];
+  CGContextRef auxgc = CGBitmapContextCreate(rgba, data_w, data_h, 8, 4 * data_w, cspace, kCGImageAlphaPremultipliedLast);
   CGColorSpaceRelease(cspace);
-  CGContextClearRect(auxgc, CGRectMake(0,0,2*scaled_w,2*htop));
-  CGContextScaleCTM(auxgc, 2, 2);
+  CGContextClearRect(auxgc, CGRectMake(0,0,data_w,data_h));
+  CGContextScaleCTM(auxgc, factor, factor);
   if (layer) {
     Fl_Cocoa_Window_Driver::draw_layer_to_context(layer, auxgc, scaled_w, htop);
     if (fl_mac_os_version >= 101300) {
       // drawn layer is left transparent and alpha-premultiplied: demultiply it and set it opaque.
       uchar *p = rgba;
-      uchar *last = rgba + 4 * scaled_w * htop * 4;
+      uchar *last = rgba + data_w * data_h * 4;
       while (p < last) {
         uchar q = *(p+3);
         if (q && q != 0xff) {
@@ -352,7 +354,7 @@ void Fl_Cocoa_Window_Driver::capture_titlebar_and_borders(Fl_RGB_Image*& top, Fl
     CGContextRestoreGState(auxgc);
     CFRelease(img);
   }
-  top = new Fl_RGB_Image(rgba, 2 * scaled_w, 2 * htop, 4);
+  top = new Fl_RGB_Image(rgba, data_w, data_h, 4);
   top->alloc_array = 1;
   top->scale(w(),htop, s <1 ? 0 : 1, 1);
   CGContextRelease(auxgc);
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2020 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.