API  0.9.6
 All Classes Files Functions Variables Macros Groups Pages
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  if (lastContext)
70  {
71  [lastContext restoreGraphicsState];
72  [CPGraphicsContextThreadStack removeLastObject];
73  }
74 }
75 
82 + (CPGraphicsContext)graphicsContextWithGraphicsPort:(CGContext)aContext flipped:(BOOL)aFlag
83 {
84  return [[self alloc] initWithGraphicsPort:aContext];
85 }
86 
92 - (id)initWithGraphicsPort:(CPContext)aGraphicsPort
93 {
94  self = [super init];
95 
96  if (self)
97  _graphicsPort = aGraphicsPort;
98 
99  return self;
100 }
101 
105 - (CGContext)graphicsPort
106 {
107  return _graphicsPort;
108 }
109 
118 - (BOOL)isFlipped
119 {
120  return YES;
121 }
122 
123 - (void)saveGraphicsState
124 {
125  CGContextSaveGState(_graphicsPort);
126 }
127 
128 - (void)restoreGraphicsState
129 {
130  CGContextRestoreGState(_graphicsPort);
131 }
132 
133 @end