API  1.0.0
CPGraphicsContext.j
Go to the documentation of this file.
1 /*
2  * CPGraphicsContext.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 
28 
33 @implementation CPGraphicsContext : CPObject
34 {
35  CGContext _graphicsPort;
36 }
37 
41 + (CPGraphicsContext)currentContext
42 {
44 }
45 
49 + (void)setCurrentContext:(CPGraphicsContext)aGraphicsContext
50 {
51  CPGraphicsContextCurrent = aGraphicsContext;
52 }
53 
54 + (void)saveGraphicsState
55 {
57  return;
58 
61 
62  [CPGraphicsContextThreadStack addObject:CPGraphicsContextCurrent];
63  [CPGraphicsContextCurrent saveGraphicsState];
64 }
65 
66 + (void)restoreGraphicsState
67 {
68  var lastContext = [CPGraphicsContextThreadStack lastObject];
69 
70  if (lastContext)
71  {
72  [lastContext restoreGraphicsState];
73  [CPGraphicsContextThreadStack removeLastObject];
74  }
75 }
76 
83 + (CPGraphicsContext)graphicsContextWithGraphicsPort:(CGContext)aContext flipped:(BOOL)aFlag
84 {
85  return [[self alloc] initWithGraphicsPort:aContext];
86 }
87 
93 - (id)initWithGraphicsPort:(CPContext)aGraphicsPort
94 {
95  self = [super init];
96 
97  if (self)
98  _graphicsPort = aGraphicsPort;
99 
100  return self;
101 }
102 
106 - (CGContext)graphicsPort
107 {
108  return _graphicsPort;
109 }
110 
119 - (BOOL)isFlipped
120 {
121  return YES;
122 }
123 
124 - (void)saveGraphicsState
125 {
126  CGContextSaveGState(_graphicsPort);
127 }
128 
129 - (void)restoreGraphicsState
130 {
131  CGContextRestoreGState(_graphicsPort);
132 }
133 
134 @end
function CGContextRestoreGState(aContext)
Definition: CGContext.j:156
var CPGraphicsContextCurrent
id initWithGraphicsPort:(CPContext aGraphicsPort)
var CPGraphicsContextThreadStack
function CGContextSaveGState(aContext)
Definition: CGContext.j:146
id init()
Definition: CPObject.j:145
id alloc()
Definition: CPObject.j:130