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