Q: I'm trying to use a C++ class instance method as
the Movie Drawing Complete Procedure. Is there a way to do
this or is there a recommended technique? I'd like to know
which Movie (my objects) have drawn a frame.
A: To assign a drawing-complete function to a Movie
use the SetMovieDrawingCompleteProc call. This call takes a
Movie, flags (either movieDrawingCallWhenChanged or
movieDrawingCallAlways), a UPP for your callback and a
RefCon. When installing the MovieDrawingCompleteProc, use a
MovieDrawingCompleteUPP for a static class function, not a
member function of your class. The RefCon can be used to
reference the instance of your class (this).
// Example class header file
// MyClass.h
class MyClass {
public:
MyClass() { mMovie = NULL; };
virtual ~MyClass();
protected:
void InstallMovieDrawingComplete(Movie inMovie,
long inFlags = movieDrawingCallAlways);
virtual OSErr DrawingCompleteDoSomething(Movie theMovie) { return noErr; };
private:
/* Called when movie drawing is complete.
typedef OSErr (*MovieDrawingCompleteProcPtr) (Movie theMovie, long refCon);
*/
static pascal OSErr MyClassMovieDrawingCompleteProc(Movie theMovie, long refCon);
static MovieDrawingCompleteUPP sMovieDrawingCompleteUPP;
Movie mMovie;
};
// Example class implementation
// MyClass.cpp
MovieDrawingCompleteUPP MyClass::sMovieDrawingCompleteUPP = NULL;
pascal OSErr MyClass::MyClassMovieDrawingCompleteProc(Movie theMovie, long refCon)
{
MyClass *instance = reinterpret_cast<MyClass *>(refCon);
OSErr err = noErr;
if (instance)
err = instance->DrawingCompleteDoSomething(theMovie);
return err;
}
MyClass::~MyClass()
{
if (mMovie) ::SetMovieDrawingCompleteProc(mMovie, 0, NULL, 0L);
if (sMovieDrawingCompleteUPP)
::DisposeMovieDrawingCompleteUPP(sMovieDrawingCompleteUPP);
}
/*
inFlags: movieDrawingCallWhenChanged
Specifies that the toolbox should call your drawing-complete
function only when the movie has changed.
movieDrawingCallAlways
Specifies that the toolbox should call your drawing-complete
function every time your application calls MoviesTask
*/
void MyClass::InstallMovieDrawingComplete(Movie inMovie, long inFlags)
{
if (NULL == MyClass::sMovieDrawingCompleteUPP) {
MyClass::sMovieDrawingCompleteUPP =
::NewMovieDrawingCompleteUPP(MyClass::MyClassMovieDrawingCompleteProc);
}
if (inMovie) {
if (mMovie) {
// remove the callback from previous Movie
::SetMovieDrawingCompleteProc(mMovie, 0, NULL, 0L);
}
::SetMovieDrawingCompleteProc(inMovie, inFlags,
MyClass::sMovieDrawingCompleteUPP,
long(this));
mMovie = inMovie;
}
}
|
Listing 1. Using a static member for a
MovieDrawingCompleteProc
|
[Jun 18 2002]
|