diff options
| author | Manolo Gouy <Manolo> | 2016-02-12 11:49:32 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-02-12 11:49:32 +0000 |
| commit | bc83464b642caad491c70e3b54677dd50f6324b2 (patch) | |
| tree | 8bf8b6c7701423c40ba6e2290c89879600c8676a /src/Fl_cocoa.mm | |
| parent | 50ee3bcd66c4baa6bb3388f5b955d726bfc6bdd8 (diff) | |
Add Fl_Shared_Image *Fl_Image_Surface::highres_image() to draw into high-resolution bitmap.
This new member function returns a high resolution bitmap image scaled to the adequate
drawing size. This allows to create a bitmap image able to fill all pixels of a high resolution
display. This is functional only for the Mac OS platform. On other platforms,
the new member function returns an unscaled bitmap.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11158 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_cocoa.mm')
| -rw-r--r-- | src/Fl_cocoa.mm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 8c36dee58..30e32d780 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -3345,9 +3345,31 @@ void Fl_X::q_begin_image(CGRect &rect, int cx, int cy, int w, int h) { r2.origin.x -= 0.5f; r2.origin.y -= 0.5f; CGContextClipToRect(fl_gc, r2); - // move graphics context to origin of vertically reversed image + // move graphics context to origin of vertically reversed image + // The 0.5 here cancels the 0.5 offset present in Quartz graphics contexts. + // Thus, image and surface pixels are in phase if there's no scaling. + // Below, we handle x2 and /2 scalings that occur when drawing to + // a double-resolution bitmap, and when drawing a double-resolution bitmap to display. CGContextTranslateCTM(fl_gc, rect.origin.x - cx - 0.5, rect.origin.y - cy + h - 0.5); CGContextScaleCTM(fl_gc, 1, -1); + CGAffineTransform at = CGContextGetCTM(fl_gc); + if (at.a == at.d && at.b == 0 && at.c == 0) { // proportional scaling, no rotation + // phase image with display pixels + CGFloat deltax = 0, deltay = 0; + if (at.a == 2) { // make .tx and .ty have even values + deltax = (at.tx/2 - round(at.tx/2)); + deltay = (at.ty/2 - round(at.ty/2)); + } else if (at.a == 0.5) { + if (Fl_Display_Device::high_resolution()) { // make .tx and .ty have int or half-int values + deltax = (at.tx*2 - round(at.tx*2)); + deltay = (at.ty*2 - round(at.ty*2)); + } else { // make .tx and .ty have integral values + deltax = (at.tx - round(at.tx))*2; + deltay = (at.ty - round(at.ty))*2; + } + } + CGContextTranslateCTM(fl_gc, -deltax, -deltay); + } rect.origin.x = rect.origin.y = 0; rect.size.width = w; rect.size.height = h; @@ -4368,6 +4390,7 @@ static void draw_layer_to_context(CALayer *layer, CGContextRef gc, int w, int h) Fl_X::clip_to_rounded_corners(gc, w, h); CGContextSetRGBFillColor(gc, .79, .79, .79, 1.); // equiv. to FL_DARK1 CGContextFillRect(gc, CGRectMake(0, 0, w, h)); + CGContextSetShouldAntialias(gc, true); [layer renderInContext:gc]; // 10.5 CGContextRestoreGState(gc); #endif |
