From f723903b6990655c12fb1747a816ed62b01e87c0 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Tue, 25 Jan 2011 14:50:17 +0100 Subject: Add utility functions for using Core Graphics contexts. These snippets are often used while managing Core Graphics contexts. Putting them in inlined functions makes code easier to read. Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qt_cocoa_helpers_mac_p.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h index 25dcdc3..b177210 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h +++ b/src/gui/kernel/qt_cocoa_helpers_mac_p.h @@ -232,6 +232,34 @@ void qt_mac_display(QWidget *widget); void qt_mac_setneedsdisplay(QWidget *widget); #endif // QT_MAC_USE_COCOA + +// Utility functions to ease the use of Core Graphics contexts. + +inline void qt_mac_retain_graphics_context(CGContextRef context) +{ + CGContextRetain(context); + CGContextSaveGState(context); +} + +inline void qt_mac_release_graphics_context(CGContextRef context) +{ + CGContextRestoreGState(context); + CGContextRelease(context); +} + +inline void qt_mac_draw_image(CGContextRef context, CGContextRef imageContext, CGRect area, CGRect drawingArea) +{ + CGImageRef image = CGBitmapContextCreateImage(imageContext); + CGImageRef subImage = CGImageCreateWithImageInRect(image, area); + + CGContextTranslateCTM (context, 0, drawingArea.origin.y + CGRectGetMaxY(drawingArea)); + CGContextScaleCTM(context, 1, -1); + CGContextDrawImage(context, drawingArea, subImage); + + CGImageRelease(subImage); + CGImageRelease(image); +} + QT_END_NAMESPACE #endif // QT_COCOA_HELPERS_MAC_P_H -- cgit v0.12