MyComponentRoutines.c

/*
    File:       MyComponentRoutines.c
 
    Contains:   simple component sample.
 
    Written by: John Wang   
 
    Copyright:  Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                8/18/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
 
#ifdef THINK_C
#define     applec
#endif
 
#include    <Errors.h>
#include    <Components.h>
#include    <Devices.h>
#include    <Movies.h>
#include    <QuickTimeComponents.h>
#include    <LowMem.h>
 
#include    "MyComponent.h"
#include    "MyComponentRoutines.h"
#include    "FadeScreen.h"
#include    "HideMenuBar.h"
 
/* ------------------------------------------------------------------------- */
 
pascal ComponentResult MyIsPlayerEvent (PrivateGlobals **storage,
            EventRecord *e)
{
    GrafPtr     savePort;
    GDHandle    saveGD;
 
    //  Fade out for the first time.
    if ((**storage).firstTime == true) {
        SwapWindow(storage);
        (**storage).firstTime = false;
    }
    
    //  Handle events
    if (e->what == keyDown) {
        if ((e->message & charCodeMask) == '\t') {
            SwapWindow(storage);
            return(true);
        }
    } else if (e->what == updateEvt) {
        if (e->message == (long) (**storage).backWindow) {
            GetPort(&savePort);
            saveGD = GetGDevice();
            SetPort((**storage).backWindow);
            SetGDevice(GetMainDevice());
            BeginUpdate((**storage).backWindow);
            PaintRect(&(((**storage).backWindow)->portRect));
            EndUpdate((**storage).backWindow);
            SetPort(savePort);
            SetGDevice(saveGD);
            return(true);
        }
    }
    
    //  Handle other events.
    return(MCIsPlayerEvent((**storage).delegate, e));
}
 
//--------------------------------------------------------------------------
 
void SwapWindow(PrivateGlobals **storage)
{
    CGrafPtr            moviePort;
    GDHandle            myDevice;
    Rect                myDeviceRect;
    GrafPtr             savePort;
    GDHandle            saveGD;
    RgnHandle           movieRgn;
    
    //  Get variables
    GetPort(&savePort);
    saveGD = GetGDevice();
    GetMovieGWorld(MCGetMovie((**storage).delegate), &moviePort, nil);
    myDevice = GetMaxDevice(&((**LMGetGrayRgn()).rgnBBox));
    myDeviceRect = (**myDevice).gdRect;
    
    FadeInOut(myDevice, true, 60);
    if ((**storage).fadeStatus == false) {
        //  Hide the menu bar
        (**storage).handleBarStorage = MyHideMenuBar();
 
        //  Modify movie controller.
        (**storage).mcVisible = MCGetVisible((**storage).delegate);
        (**storage).mcAttached = MCIsControllerAttached((**storage).delegate);
        MCSetVisible((**storage).delegate, false);
//      MCSetControllerAttached((**storage).delegate, false);
        movieRgn = MCGetWindowRgn((**storage).delegate, (WindowPtr) moviePort);
        SizeWindow((WindowPtr) moviePort, ((**movieRgn).rgnBBox).right - ((**movieRgn).rgnBBox).left,
                        ((**movieRgn).rgnBBox).bottom - ((**movieRgn).rgnBBox).top, true);
        DisposeRgn(movieRgn);
        
        //  Create back window.
        (**storage).backWindow = NewCWindow(0L, &myDeviceRect, "\pBlack Background", 1, noGrowDocProc, (WindowPtr) -1, false, 0L);
        SelectWindow((**storage).backWindow);
        SetPort((**storage).backWindow);
        SetGDevice(GetMainDevice());
        PaintRect(&(((**storage).backWindow)->portRect));
        
        //  Modify movie window.
        SetPort((GrafPtr) moviePort);
        SetGDevice(GetMainDevice());
        SelectWindow((WindowPtr) moviePort);
        (**storage).fadeStatus = true;
    } else {
        //  Restore menu bar.
        RestoreMenuBar((**storage).handleBarStorage);
 
        //  Restore movie controller.
        MCSetVisible((**storage).delegate, (**storage).mcVisible);
        MCSetControllerAttached((**storage).delegate, (**storage).mcAttached);
        movieRgn = MCGetWindowRgn((**storage).delegate, (WindowPtr) moviePort);
        SizeWindow((WindowPtr) moviePort, ((**movieRgn).rgnBBox).right - ((**movieRgn).rgnBBox).left,
                        ((**movieRgn).rgnBBox).bottom - ((**movieRgn).rgnBBox).top, true);
        DisposeRgn(movieRgn);
 
        //  Dispose back window.
        SelectWindow((**storage).backWindow);
        DisposeWindow((**storage).backWindow);
        (**storage).fadeStatus = false;
    }
    FadeInOut(myDevice, false, 60);
 
    SetPort(savePort);
    SetGDevice(saveGD);
}