CPGraphicsContext saveGraphicsState and restoreGraphicsState.

This commit is contained in:
Alexander Ljungberg
2012-10-22 15:03:32 +01:00
parent 391701fdc7
commit 4bedd52e16
+34 -1
View File
@@ -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