| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Quartz.framework/Frameworks/QuartzComposer.framework |
| Availability | Available in Mac OS X v10.4 and later.
|
| Companion guide | |
| Declared in | QCView.h |
The QCView class is a custom NSView class that loads, plays, and controls Quartz Composer compositions. It is an autonomous view that is driven by an internal timer running on the main thread.
The view can be set to render a composition automatically when it is placed onscreen. The view stops rendering when it is placed offscreen. When not rendering, the view is filled with the current erase color. The rendered composition automatically synchronizes to the vertical retrace of the monitor.
When you archive a QCView object, it saves the composition that’s loaded at the time the view is archived.
If you want to perform custom operations while a composition is rendering such as setting input parameters or drawing OpenGL content, you need to subclass QCView and implement the renderAtTime:arguments: method.
– startRendering
– isRendering
– autostartsRendering
– setAutostartsRendering:
– stopRendering
– pauseRendering
– isPausedRendering
– resumeRendering
Checks whether the view is set to start rendering automatically.
- (BOOL)autostartsRendering
Returns YES if the view is set to start rendering automatically when the view is put on screen.
QCView.hReturns the current image in the view as an image object of the provided image type.
- (id) createSnapshotImageOfType:(NSString*)type
A string that specifies any of the following image types: NSBitmapImageRep, NSImage, CIImage, CGImage, CVOpenGLBuffer, CVPixelBuffer.
The snapshot image in the provided image type. You are responsible for releasing this object when you no longer need it.
QCView.hClears the view using the current erase color.
- (void)erase
QCView.hRetrieves the current color used to erase the view.
- (NSColor *)eraseColor
The color object previously set using the setEraseColor: method.
QCView.hRetrieves the mask used to filter which types of events are forwarded from the view to the composition during rendering.
- (NSUInteger)eventForwardingMask
The event filtering mask.
QCView.hReturns whether or not the rendering in the view is paused.
- (BOOL) isPausedRendering;
YES if the rendering is paused; otherwise NO.
QCView.hChecks whether a composition is rendering in the view.
- (BOOL)isRendering
Returns YES if a composition is rendering in the view; NO otherwise.
QCView.hLoads a QCComposition object into the view.
- (BOOL) loadComposition:(QCComposition*)composition
The QCComposition object to load.
YES if successful; otherwise NO. If unsuccessful, any composition that’s already loaded in the view remains loaded.
QCView.hLoads the composition file located at the specified path.
- (BOOL)loadCompositionFromFile:(NSString *)path
A string that specifies the location of a Quartz Composer composition file.
If unsuccessful, returns NO; any composition that’s already loaded in the view remains loaded.
QCView.hReturns the composition loaded in the view.
- (QCComposition*) loadedComposition
The composition loaded in the view; otherwise nil.
QCView.hReturns the maximum frame rate for rendering.
- (float)maxRenderingFrameRate
The maximum frame rate for rendering. A value of 0.0 specifies that there is no limit.
QCView.hReturns the OpenGL context used by the view.
- (NSOpenGLContext*) openGLContext
An NSOpenGLContext object.
This context as a read-only object . Do not attempt to change any of its settings. If you subclass QCView so that you can perform custom OpenGL drawing, you’ll need to use this method to retrieve the view’s OpenGL context.
QCView.hReturns the OpenGL pixel format used by the view.
- (NSOpenGLPixelFormat*) openGLPixelFormat
An NSOpenGLPixelFormat object.
This pixel format as a read-only object. Do not attempt to change any of its settings.
QCView.hPauses rendering in the view.
- (void) pauseRendering
You can nest calls to this method.
QCView.hPlays or pauses a composition in a view.
- (IBAction) play:(id)sender
The object (such as a button or menu item) sending the message to play the composition. You need to connect the object in the interface to the action.
The message sent to the target.
This method starts rendering a composition if it is not already rendering, pauses a composition that is rendering, or resumes rendering for a composition whose rendering is paused. The method is invoked when the user clicks a button or issues a command from some other user interface element, such as a menu.
QCView.hOverrides to perform your custom operations prior to or after rendering a frame of a composition.
- (BOOL) renderAtTime:(NSTimeInterval)time arguments:(NSDictionary*)arguments
The rendering time, in seconds, of the composition frame.
An optional dictionary that can contain QCRendererEventKey or QCRendererMouseLocationKey and the associated values. (See QCRenderer Class Reference or more information.)
NO if your custom rendering fails, otherwise, YES.
Do not call this method directly. You override this method only for subclasses of the QCView class and only if you want to perform custom operations or OpenGL rendering before and/or after Quartz Composer renders a frame of the composition.
The most common reasons to override this method are to:
synchronize communication with the composition. For example, you might want to set input parameters of the composition. By overriding this method, you can set parameters only when necessary and only at a specific time.
underlay or overlay custom OpenGL rendering.
To synchronize communication between a composition and another part of the application, the implementation looks similar to the following:
- (BOOL) renderAtTime:(NSTimeInterval)time |
arguments:(NSDictionary*)arguments |
{ |
// Your code to computer the value of myParameterValue |
[self setValue:myParameterValue forInputKey:@"myInput"]; |
BOOL success = [super renderAtTime:time arguments:arguments]; |
id result = [self valueForOutputKey:@"myOutput"]; |
//Your code to perform some operation on the result |
return success; |
} |
To perform OpenGL drawing in a QCView object, follow these guidelines:
Use the OpenGL context of the QCView object to do drawing. You can retrieve the OpenGL context by calling [self openGLContext]. Note that this context won't necessarily be set as the current OpenGL context.
Use CGL macros instead of managing the current OpenGL context yourself.
OpenGL performs a global context and renderer lookup for each command it executes to ensure that all OpenGL commands are issued to the correct rendering context and renderer. There is significant overhead associated with these lookups that can measurably affect performance. CGL macros let you provide a local context variable and cache the current renderer in that variable. They are simple to use, taking only a few lines of code to set up.
Save and restore all state changes except the ones that are part of GL_CURRENT_BIT (RGBA color, color index, normal vector, texture coordinates, and so forth).
Check for OpenGL errors with glGetError.
Here’s an example implementation of this method using OpenGL to draw an overlay:
#import <OpenGL/CGLMacro.h> // Set up using macros |
- (BOOL) renderAtTime:(NSTimeInterval)time |
arguments:(NSDictionary*)arguments |
{ |
BOOL success = [super renderAtTime:time arguments:arguments]; |
// Use the OpenGL context of the view for drawing. |
CGLContextObj cgl_ctx = [[self openGLContext] CGLContextObj]; |
// Save and set OpenGL states appropriately. |
glGetIntegerv(GL_MATRIX_MODE, &saveMode); |
glMatrixMode(GL_MODELVIEW); |
glPushMatrix(); |
glRotatef(45.0, 0.0, 0.0, 1.0); |
// The code that performs OpenGL drawing goes here. |
//After drawing, restore original OpenGL states. |
glPopMatrix(); |
glMatrixMode(saveMode); |
// Check for errors. |
glGetError(); |
return success; |
} |
QCView.hResumes rendering a paused composition.
- (void) resumeRendering
You can nest calls to this method.
QCView.hSets whether the composition that is in the view starts rendering automatically when the view is put on the screen.
- (void)setAutostartsRendering:(BOOL)flag
Pass YES to enable autostart mode; NO otherwise.
QCView.hSets the color used to erase the view.
- (void)setEraseColor:(NSColor *)color
A color object.
QCView.hSets the mask used to filter which types of events are forwarded from the view to the composition during rendering.
- (void)setEventForwardingMask:(NSUInteger)mask
An event filtering mask. The mask can be a combination of any of the mask constants listed in Table 1 or the constant NSAnyEventMask.
Event |
Description |
|---|---|
|
The user pressed the left button. |
|
The user moved the mouse with the left button down. |
|
The user released the left button. |
|
The user pressed the right button. |
|
The user moved the mouse with the right button down. |
|
The user released the right button. |
|
The user pressed the middle button, or some button other than the left or right button. |
|
The user moved the mouse with the middle button down, or some button other than the left or right button. |
|
The user released the middle button, or some button other than the left or right button. |
|
The user moved the mouse without holding down a mouse button. |
|
The user moved the mouse scroll wheel. |
|
The user generated a character or characters by pressing a key. |
|
The user released a key. |
|
The user pressed or released a modifier key, or toggled the Caps Lock key. |
QCView.hSets the maximum rendering frame rate.
- (void)setMaxRenderingFrameRate:(float)maxFPS
The frame rate to set. Pass 0.0 to specify that there is no limit.
QCView.hReturns an NSImage object of the current image in the view.
- (NSImage*) snapshotImage
The snapshot image.
QCView.hStarts rendering a composition in a view.
- (IBAction)start:(id)sender
The object (such as a button or menu item) sending the message to start rendering. You need to connect the object in the interface to the action.
The message sent to the target.
The method is invoked when the user clicks a button or issues a command from some other user interface element, such as a menu. It is equivalent to the startRendering method.
QCView.hStarts rendering the composition that is in the view.
- (BOOL)startRendering
Returns NO if the composition fails to start rendering; YES otherwise.
QCView.hStops rendering a composition in a view.
- (IBAction)stop:(id)sender
The object (such as a button or menu item) sending the message to stop rendering. You need to connect the object in the interface to the action.
The message sent to the target.
The method is invoked when the user clicks a button or issues a command from some other user interface element, such as a menu. It is equivalent to the stopRendering method.
QCView.hStops rendering the composition that is in the view.
- (void)stopRendering
QCView.hUnloads the composition from the view.
- (void) unloadComposition;
If necessary, this method calls stopRendering prior to unloading the composition.
QCView.hPosted when the view starts rendering.
QCView.hPosted when the view stops rendering.
QCView.h
Last updated: 2007-05-09