diff options
author | Fabien Freling <fabien.freling@nokia.com> | 2011-01-25 13:50:17 (GMT) |
---|---|---|
committer | Fabien Freling <fabien.freling@nokia.com> | 2011-01-25 13:54:20 (GMT) |
commit | f723903b6990655c12fb1747a816ed62b01e87c0 (patch) | |
tree | 038d920d0bf4f3d67914dbb45302a5a55553d0eb /src | |
parent | b595c2fbe0fa354190b713ef09dd1f348e22e2b6 (diff) | |
download | Qt-f723903b6990655c12fb1747a816ed62b01e87c0.zip Qt-f723903b6990655c12fb1747a816ed62b01e87c0.tar.gz Qt-f723903b6990655c12fb1747a816ed62b01e87c0.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac_p.h | 28 |
1 files changed, 28 insertions, 0 deletions
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 |