PATH  Documentation > Mac OS X > Application Kit Reference: Objective-C

Table of Contents

NSGraphicsContext


Inherits from:
NSObject
Conforms to:
NSObject
(NSObject)
Declared in:
AppKit/NSGraphicsContext.h




Class Description


The NSGraphicsContext class is the programmatic interface to objects that represent graphics contexts. A context can be thought of as a destination to which drawing and graphics state operations are sent for execution. Each graphics context contains its own graphics environment and state.

At any time there is the notion of the current context. The current context for the current thread may be set using setCurrentContext:.

The NSGraphicsContext class is an superclass for destination-specific graphics contexts.

Graphics contexts are maintained on a stack. You push a graphics context onto the stack by sending it a saveGraphicsState message, and push it off the stack by sending it a restoreGraphicsState message. By sending restoreGraphicsState to an NSGraphicsContext object you remove it from the stack and the next graphics context on stack becomes the current graphics context.




Method Types


Creating a graphics context
+ graphicsContextWithAttributes:
+ graphicsContextWithWindow:
Testing the drawing destination
+ currentContextDrawingToScreen
- isDrawingToScreen
Setting and identifying the current context
+ currentContext
+ restoreGraphicsState
+ setCurrentContext:
+ saveGraphicsState
- graphicsPort
Getting information about a context
- attributes
Controlling the context -flush
- flushGraphics
- restoreGraphicsState
- saveGraphicsState
+ setGraphicsState:
Focus Stack support
- focusStack
- setFocusStack:


Class Methods



currentContext

+ (NSGraphicsContext *)currentContext

Returns the current graphics context of the current thread. Returns a concrete subclass of NSGraphicsContext.

currentContextDrawingToScreen

+ (BOOL)currentContextDrawingToScreen

Convenience method equivalent to sending isDrawingToScreen to the result of currentContext.

graphicsContextWithAttributes:

+ (NSGraphicsContext *)graphicsContextWithAttributes:(NSDictionary *)attributes

Instantiates from an appropriate concrete subclass depending on attributes.

graphicsContextWithWindow:

+ (NSGraphicsContext *)graphicsContextWithWindow:(NSWindow *)aWindow

Description forthcoming.

restoreGraphicsState

+ (void)restoreGraphicsState

Pops a graphics context from the per-thread stack, makes it current, and calls restoreGraphicsState . It's the functional equivalent of PSgrestore.

saveGraphicsState

+ (void)saveGraphicsState

Calls saveGraphicsState, and pushes the current graphics context on the per-thread stack. It's the functional equivalent of PSgsave.

setCurrentContext:

+ (void)setCurrentContext:(NSGraphicsContext *)context

Sets the current graphics context of the current thread to context. context must be a concrete subclass of NSGraphicsContext.

setGraphicsState:

+ (void)setGraphicsState:(int)graphicsState

Makes graphicState's context current, and resets graphics state. The graphicState must be created in the calling thread


Instance Methods



attributes

- (NSDictionary *)attributes

Returns the receiver's attributes.

flushGraphics

- (void)flushGraphics

Description forthcoming.

focusStack

- (void *)focusStack

Description forthcoming.

graphicsPort

- (void *)graphicsPort

Description forthcoming.

isDrawingToScreen

- (BOOL)isDrawingToScreen

Returns YES if the drawing destination is the screen, NO otherwise.

The default implementation of this method raises NSInvalidArgumentException to indicate that the method must be overridden in a concrete subclass.



restoreGraphicsState

- (void)restoreGraphicsState

Removes the receiver's graphics state from the top of the graphics state stack and makes the next graphics state the current graphics state. This method must have been proceeded with a saveGraphicsState message to add the graphics state to the stack. Invocations of saveGraphicsState and restoreGraphicsState methods may be nested.

Restoring the graphics state restores such attributes as the current drawing style, transformation matrix, color, and font of the original graphics state.

The default implementation of this method raises NSInvalidArgumentException to indicate that the method must be overridden in a concrete subclass.



saveGraphicsState

- (void)saveGraphicsState

Saves the current graphics state and creates a new graphics state on the top of the stack. The new graphics state is a copy of the previous state that can be modified to handle new drawing operations.

Saving the graphics state saves such attributes as the current drawing style, transformation matrix, color, and font. To set drawing style attributes, use the methods of NSBezierPath. Other attributes are accessed through appropriate objects such as NSAffineTransform, NSColor, and NSFont.

The default implementation of this method raises NSInvalidArgumentException to indicate that the method must be overridden in a concrete subclass.



setFocusStack:

- (void)setFocusStack:(void *)stack

Description forthcoming.


Table of Contents