home *** CD-ROM | disk | FTP | other *** search
- /**************************************************
- *
- * Sample Digitizing Application
- *
- * This sample program demonstrates the basic interfaces
- * to a video digitizer. Note that an application will
- * typically be using the sequence grabber rather than
- * accessing the video digitizer directly.
- *
- ***************************************************/
-
- /**************************************************
- *
- * General Info
- *
- ***************************************************/
- #include <QuickDraw.h>
- #include "Mini Player.h"
- #include "Components.h"
- #include "video digitizer.h"
- #include "RO364.h"
- #include "DIGIUtils.h"
- #include "Matrix.h"
-
-
- /* MacHeaders Included */
- VideoDigitizerThing gti;
- Component gt;
- Boolean ghFlipState = FALSE;
- Boolean gvFlipState = FALSE;
- extern VideoDigitizerThing gti;
- extern Component gt;
- extern Boolean ghFlipState, gvFlipState;
- /* prototypes */
-
- void InitMacintosh(void);
- void SetUpMenus(void);
- void SetUpWindows(void);
- void AdjustMenus(void);
- void enable(MenuHandle menu, short item, Boolean ok);
- void HandleMenu (long mSelect);
- void CloseEm(WindowPtr w);
- void DoAboutBox(void);
- void DoOpen(void);
- Boolean IsMyWindow(WindowPtr w);
- void HandleMouseDown(EventRecord *theEvent);
- void HandleMouseUp(EventRecord *theEvent);
- void HandleEvent(void);
-
- /**************************************************
- ***************************************************
- *
- * Initialization Routines
- *
- * All of the stuff we call to get things started
- *
- ***************************************************
- ***************************************************/
-
- /**************************************************
- *
- * InitMacintosh() Initialize all the managers & memory
- *
- ***************************************************/
- void InitMacintosh()
-
- {
- MaxApplZone();
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- }
-
- /**************************************************
- *
- * SetUpMenus()
- *
- * Reads in the menu resources and installs them
- *
- *
- ***************************************************/
- void SetUpMenus()
-
- {
- InsertMenu(appleMenu = GetMenu(appleID), 0);
- InsertMenu(fileMenu = GetMenu(fileID), 0);
- InsertMenu(editMenu = GetMenu(editID), 0);
- InsertMenu(optionsMenu = GetMenu(optionsID),0);
- DrawMenuBar();
- AddResMenu(appleMenu, 'DRVR');
-
- }
-
- /**************************************************
- *
- * SetUpWindows()
- *
- * Create the video window.
- *
- ***************************************************/
- void SetUpWindows()
-
- {
- /* Create the window for the picture */
- dragRect = screenBits.bounds;
- vdigWindow = GetNewVWindow(128,(Ptr)0L,(WindowPtr)-1L); /* Make a new window */
- SetPort(vdigWindow);
- ShowWindow(vdigWindow);
-
- }
-
- /**************************************************
- ***************************************************
- *
- * Routines for handling menus.
- *
- ***************************************************
- ***************************************************/
-
- /**************************************************
- *
- * AdjustMenus()
- *
- * Enable or disable the items in the Edit menu if a DA window
- * comes up or goes away. Our application doesn't do anything with
- * the Edit menu.
- *
- ***************************************************/
- void AdjustMenus()
- {
- register WindowPeek wp = (WindowPeek) FrontWindow();
- short kind = wp ? wp->windowKind : 0;
- Boolean DA = kind < 0, mainVis = ((WindowPeek) vdigWindow)->visible;
-
- enable(editMenu, 1, DA);
- enable(editMenu, 3, DA);
- enable(editMenu, 4, DA);
- enable(editMenu, 5, DA);
- enable(editMenu, 6, DA);
-
- enable(fileMenu, openItem, !((WindowPeek) vdigWindow)->visible);
- enable(fileMenu, closeItem, DA || ((WindowPeek) vdigWindow)->visible);
-
- }
-
- static
- void enable(MenuHandle menu, short item, Boolean ok)
- {
- if (ok)
- EnableItem((MenuHandle)menu, item);
- else
- DisableItem((MenuHandle)menu, item);
- }
-
- /**************************************************
- *
- * HandleMenu (mSelect)
- *
- * Handle the menu selection. mSelect is what MenuSelect() and
- * MenuKey() return: the high word is the menu ID, the low word
- * is the menu item
- *
- ***************************************************/
- void HandleMenu (mSelect)
-
- long mSelect;
-
- {
- int menuID = HiWord(mSelect);
- int menuItem = LoWord(mSelect);
- Str255 name;
- GrafPtr savePort;
- WindowPeek frontWindow;
-
- Ptr bAddr;
- short rowBytes;
- short pixelSize;
- short tx;
- short ty;
- short straddle;
- MatrixRecord aMatrix;
- long result = 0;
-
- switch (menuID)
- {
- case appleID: /* The Apple menu */
- switch (menuItem)
- {
- case aboutItem:
- DoAboutBox(); /* Display the About Box */
- break;
-
- default: /* It's a DA */
- GetPort(&savePort);
- GetItem(appleMenu, menuItem, name);
- OpenDeskAcc(name);
- SetPort(savePort);
- break;
- }
- break;
-
- case fileID: /* The file menu */
- switch (menuItem)
- {
- case openItem:
- break;
-
- case closeItem:
- if ((frontWindow = (WindowPeek) FrontWindow()) == 0L)
- break;
-
- if (frontWindow->windowKind < 0)
- CloseDeskAcc(frontWindow->windowKind);
- else
- /* It's the movie window ( the only one we've got ) */
- /* Close it & clean up the movie stuff */
- DisposeVideoWindow( (WindowPtr) frontWindow);
-
- break;
-
-
- case quitItem: /* Pack up and go home */
- /* Clean up if movie still there */
- if (((WindowPeek) vdigWindow)->visible)
- DisposeVideoWindow(vdigWindow);
- ExitToShell();
- break;
- }
- break;
-
- case editID:
- if (!SystemEdit(menuItem-1))
- SysBeep(5);
- break;
-
- case optionsID:
- switch (menuItem)
- {
- case kFullSize:
- /* result = VDGetDestination(gti,&bAddr, &rowBytes, &pixelSize, &aMatrix); */
- SetIdentityMatrix(&aMatrix);
- /* result = VDSetDestination(gti,bAddr, rowBytes, pixelSize, &aMatrix); */
- break;
-
- case kQuarterSize:
- break;
-
- case kSixteenthSize:
- break;
-
- case kFreeze:
- VDSetPlayThruOnOff(gti,vdPlayThruOff);
- break;
-
- case kUnFreeze:
- VDSetPlayThruOnOff(gti,vdPlayThruOn);
- break;
-
- case kGrabOneFrame:
- VDGrabOneFrame(gti);
- break;
-
- case kFlipHoriz:
- ghFlipState = ~ghFlipState;
- UpdateVDDestination(vdigWindow);
- break;
-
- case kFlipVert:
- gvFlipState = ~gvFlipState;
- UpdateVDDestination(vdigWindow);
- break;
-
- default:
- break;
- }
- break;
- }
- }
-
-
- /**************************************************
- *
- * DoAboutBox() Draws and displays the about box
- *
- ***************************************************/
- void DoAboutBox()
-
- {
- DialogPtr theDialog; /* Stuff for the about box */
- int itemHit, io;
- Handle tempHandle;
- Rect box;
-
- theDialog = GetNewDialog(aboutDlgID,0L,(WindowPtr)-1L);
-
- /* Highlight the default button */
- SetPort(theDialog);
- GetDItem(theDialog,1,&itemHit,&tempHandle,&box);
- PenSize(3,3);
- InsetRect(&box,-4,-4);
- FrameRoundRect(&box,16,16);
-
- /* Wait until the button is pressed */
- do
- ModalDialog(0l,&itemHit);
- while (itemHit != 1);
-
- /* Button pressed, go home */
- DisposDialog(theDialog);
- }
-
-
- /**************************************************
- ***************************************************
- *
- * The window routines
- *
- ****************************************************
- ***************************************************/
-
- /**************************************************
- *
- * IsMyWindow(w):Boolean
- * Checks if w is a valid window and mine
- *
- ***************************************************/
- Boolean IsMyWindow(w)
-
- WindowPtr w;
-
- {
- return( (w != 0L) &&
- (w == vdigWindow) );
- }
-
- /**************************************************
- ***************************************************
- *
- * Event handling stuff
- *
- ****************************************************
- ***************************************************/
-
- /**************************************************
- *
- * HandleMouseDown (theEvent)
- *
- * Take care of mouseDown events.
- *
- ***************************************************/
- void HandleMouseDown(theEvent)
-
- EventRecord *theEvent;
-
- {
- WindowPtr theWindow;
- int windowCode = FindWindow (theEvent->where, &theWindow);
- Rect saveRect;
- Point aPoint, bPoint;
- int ok;
- EventRecord moveEvent;
- Boolean done,equal;
- Point saveMouseLoc;
- KeyMap keyMap;
- Boolean optionKeyDown;
-
- switch (windowCode)
- {
- case inSysWindow:
- SystemClick (theEvent, theWindow);
- break;
-
- case inMenuBar:
- AdjustMenus();
- HandleMenu(MenuSelect(theEvent->where));
- break;
-
- case inDrag:
- if (IsMyWindow(theWindow)) {
- GetKeys(&keyMap);
- optionKeyDown = keyMap[1] & 0x4; /*Check for option key down */
-
- if (optionKeyDown) {
-
- done = FALSE;
- while (!done) {
- ok = GetNextEvent (everyEvent, &moveEvent);
- equal = EqualPt(moveEvent.where,saveMouseLoc);
- if (!equal)
- MoveVideoWindow(theWindow, moveEvent.where.h, moveEvent.where.v,TRUE);
- saveMouseLoc = moveEvent.where;
- if (ok)
- switch (moveEvent.what)
- {
- case mouseDown:
- break;
-
- case mouseUp:
- done = TRUE;
- break;
-
- }
- }
- }
- else {
- DragVideoWindow(theWindow, theEvent->where, &dragRect);
- }
-
- }
- break;
-
- case inContent:
- if (IsMyWindow(theWindow))
- {
- if (theWindow != FrontWindow())
- SelectWindow(theWindow);
- }
- break;
-
- case inGoAway:
- if (IsMyWindow(theWindow) && TrackGoAway(theWindow, theEvent->where))
- DisposeVideoWindow(theWindow); /* Close the appropriate windows */
- break;
-
- case inGrow:
- if (IsMyWindow(theWindow))
- GrowVideoWindow(theWindow, theEvent->where);
- break;
-
- break;
- }
- }
-
- /**************************************************
- *
- * HandleMouseUp (theEvent)
- *
- * Take care of mouseUp events for tracking the hand.
- *
- ***************************************************/
- void HandleMouseUp(theEvent)
-
- EventRecord *theEvent;
-
- {
- WindowPtr theWindow;
- int windowCode = FindWindow (theEvent->where, &theWindow);
-
- /* if( windowCode == inContent )*/
- /* MovieMouseUp(theWindow,theEvent->where);*/
-
- /* trackingHand = false;*/
- }
-
- /**************************************************
- *
- * HandleEvent()
- *
- * The main event dispatcher. This routine should be called
- * repeatedly (it handles only one event).
- *
- ***************************************************/
- void HandleEvent()
-
- {
- int ok;
- EventRecord theEvent;
- WindowPtr theWindow;
- OSErr retstat;
-
- HiliteMenu(0);
- SystemTask (); /* Handle desk accessories */
-
- ok = GetNextEvent (everyEvent, &theEvent);
- if (ok)
- switch (theEvent.what)
- {
- case mouseDown:
- HandleMouseDown(&theEvent);
- break;
-
- case mouseUp:
- HandleMouseUp(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- if ((theEvent.modifiers & cmdKey) != 0)
- {
- AdjustMenus();
- HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
- }
- break;
-
- case updateEvt:
- theWindow = (WindowPtr) theEvent.message; /* Get the window */
- BeginUpdate(theWindow);
- EndUpdate(theWindow);
- break;
-
- case activateEvt:
- /* Force an update event */
- SetPort( (WindowPtr) theEvent.message );
- InvalRect(&((WindowPtr)theEvent.message)->portRect);
- break;
- }
- }
-
- /**************************************************
- *
- * main()
- *
- * This is where everything happens
- *
- ***************************************************/
- main()
-
- {
- InitMacintosh(); /* Initialize everything */
- SetUpMenus();
- SetUpWindows();
-
- for (;;)
- HandleEvent();
- }
-