Graphics Reference
In-Depth Information
LISTING 9-2
Obtain Movie Path Using NSOpenPanel
- (
IBAction
)setMovie1Location:(
id
)sender;
{
NSOpenPanel *openPanel;
openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:
NO
];
[openPanel setAllowsMultipleSelection:
NO
];
[openPanel setResolvesAliases:
YES
];
[openPanel setCanChooseFiles:
YES
];
if
([openPanel runModalForTypes:
nil
] == NSOKButton)
{
[qcLayer setValue:[openPanel filename]
forInputKey:
@”movie1_location”
];
}
}
You can duplicate this code in a second
IBAction
method called
-setMovie2Location
and
simply change the input key to
movie2_location
.
The Quartz Composition layer provides the method
-setValue:forInputKey
through the
QCCompositionRenderer
protocol specifically for setting the value of a published input
inside of your composition. What is interesting, though, is that we could also set the
movie location field using Key-Value Coding with a call to
-setValue:forKeyPath
. You
can simply change the
-setValue
to use the following instead:
[qcLayer
setValue
:[openPanel filename]
forKeyPath
:
@”patch.movie1_location.value”
];
Prior to the availability of
QCCompositionLayer
, you had to use a
QCView
object to display
Quartz Compositions in a Cocoa application. If you wanted to control patches using
bindings, you also had to instantiate a
QCPatchController
. The keypath,
patch.movie1_
location.value
is the keypath you need if you use a
QCPatchController
because “patch”
refers to the root level patch in the composition. This mechanism is preserved in a
QCCompositionLayer,
so you can access the value directly using bindings. This is espe-
cially useful for when you want to bind a value for one of your Cocoa controls using
Interface Builder.
Getting Image Data from the Composition
In the same way that we published the inputs for our movie locations, we can publish
outputs as well, but first let's change our composition to add a filter to the image output.
Then we can capture that image output back in our Cocoa application.