Graphics Reference
In-Depth Information
and
1.0
, which is used directly by the slider. The slider value is set to this percentage,
and
-setNeedsDisplay
is called to tell the slider to update its display.
Adding Overlays
Adding an overlay to a movie is often one of the first things a new QuickTime developer
wants to do. This can be a bit of a challenge when using a
QTMovieView
, as views are
heavyweight and don't provide a simple means for adding a subview that will display
properly. If you use views, you either need to create a borderless subwindow that contains
the overlay content, or you need to provide it by drawing in an OpenGL context. Both of
those solutions add a significant amount of code and complexity to your application, so
let's see how Core Animation can simplify this task.
To add an overlay using Core Animation, create a new
CALayer
-based layer—either actual
or a derivative—and then call
-addSublayer
on
QTMovieLayer
. To demonstrate this, the
-awakeFromNib
call from Listing 7-1 has been modified in Listing 7-6 to add a
CATextLayer
to overlay the movie.
LISTING 7-6
Implementing an Overlay
- (
void
)awakeFromNib;
{
[[window
contentView
] setWantsLayer:
YES
];
NSString
*moviePath = [[
NSBundle mainBundle
]
pathForResource
:
@”stirfry”
ofType
:
@”mov”
];
movie = [QTMovie movieWithFile:moviePath error:
nil
];
if
( movie )
{
NSRect contentRect = [[window
contentView
]
bounds
];
QTMovieLayer *layer = [QTMovieLayer layerWithMovie:movie];
[layer
setFrame
:NSRectToCGRect(contentRect)];
textLayer = [CATextLayer
layer
];
[textLayer
setString
:
@”Do Not Try This At Home!”
];
[textLayer setAlignmentMode:kCAAlignmentCenter];
[textLayer
setFrame
:NSRectToCGRect(contentRect)];
[layer
addSublayer
:textLayer];
[[[window
contentView
]
layer
]
addSublayer
:layer];
[movie play];
}
}