From 4bedd52e162fe3a4ff51df1d65211757cb2e7f3f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 22 Oct 2012 15:03:32 +0100 Subject: [PATCH] `CPGraphicsContext saveGraphicsState` and `restoreGraphicsState`. --- AppKit/CPGraphicsContext.j | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/AppKit/CPGraphicsContext.j b/AppKit/CPGraphicsContext.j index 741cca2d0..1299fdf0b 100644 --- a/AppKit/CPGraphicsContext.j +++ b/AppKit/CPGraphicsContext.j @@ -25,7 +25,8 @@ @import "CGContext.j" -var CPGraphicsContextCurrent = nil; +var CPGraphicsContextCurrent = nil, + CPGraphicsContextThreadStack = nil; /*! @ingroup appkit @@ -52,6 +53,28 @@ var CPGraphicsContextCurrent = nil; CPGraphicsContextCurrent = aGraphicsContext; } ++ (void)saveGraphicsState +{ + if (!CPGraphicsContextCurrent) + return; + + if (!CPGraphicsContextThreadStack) + CPGraphicsContextThreadStack = [CPMutableArray array]; + + [CPGraphicsContextThreadStack addObject:CPGraphicsContextCurrent]; + [CPGraphicsContextCurrent saveGraphicsState]; +} + ++ (void)restoreGraphicsState +{ + var lastContext = [CPGraphicsContextThreadStack lastObject]; + if (lastContext) + { + [lastContext restoreGraphicsState]; + [CPGraphicsContextThreadStack removeLastObject]; + } +} + /*! Creates a graphics context with a provided port. @param aContext the context to initialize with @@ -99,4 +122,14 @@ var CPGraphicsContextCurrent = nil; return YES; } +- (void)saveGraphicsState +{ + CGContextSaveGState(_graphicsPort); +} + +- (void)restoreGraphicsState +{ + CGContextRestoreGState(_graphicsPort); +} + @end