home *** CD-ROM | disk | FTP | other *** search
- #include <SpeechSynthesis.h>
- #include "MyHeaders.h"
- //#include "MySGStuff.h"
- #include "WorkFunctions.h"
- #include "LetterFind.h"
- #include "MyUtils.h"
- #include "MyCaptureAppShell.h"
- #include <math.h>
-
- GWorldPtr gWorkGWorldPtr =0;
- long gGraphicLevel = 4;
-
- #define SIGN(x)(((x)<0)?(-1.0):(1.0))
-
- void UpdateWindow (WindowPtr inWindow)
- {
-
- // GrafPtr savePort;
- // GDHandle saveGD;
- Rect copyRect = {0,0,0,0};
-
- // GetPort(&savePort);
- // saveGD = GetGDevice();
- // SetPort((GrafPort*)gWorkGWorldPtr);
-
- LockPixels(GetGWorldPixMap(gWorkGWorldPtr));
-
- copyRect.right = gWorkGWorldPtr->portRect.right - gWorkGWorldPtr->portRect.left;
- copyRect.bottom = gWorkGWorldPtr->portRect.bottom - gWorkGWorldPtr->portRect.top;
-
- CopyBits ((BitMap*)*GetGWorldPixMap(gWorkGWorldPtr), &inWindow->portBits,
- ©Rect, ©Rect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(gWorkGWorldPtr));
-
- // SetPort(savePort);
- // SetGDevice(saveGD);
-
- }
-
- void CommonRect(Rect *toRect, Rect *fromRect)
- {
- short toWidth, toHeight, fromWidth, fromHeight;
- float temp;
-
- toWidth = toRect->right - toRect->left;
- toHeight = toRect->bottom - toRect->top;
- fromWidth = fromRect->right - fromRect->left;
- fromHeight = fromRect->bottom - fromRect->top;
-
- if (fromHeight > toHeight)
- {
- temp = (fromHeight - toHeight)/2.0;
- fromRect->top += ceil(temp);
- fromRect->bottom -= floor(temp);
- }
- else
- {
- temp = (toHeight - fromHeight)/2.0;
- toRect->top += ceil(temp);
- toRect->bottom -= floor(temp);
- }
- if (fromWidth > toWidth)
- {
- temp = (fromWidth - toWidth)/2.0;
- fromRect->left += ceil(temp);
- fromRect->right -= floor(temp);
- }
- else
- {
- temp = (toWidth - fromWidth)/2.0;
- toRect->left += ceil(temp);
- toRect->right -= floor(temp);
- }
- }
-
- void CopyGWorldToWindow (GWorldPtr inGWorld, WindowPtr inWindow)
- {
- Rect gWorldBounds;
- Rect windowBounds;
-
- RECT_EQUAL(gWorldBounds, inGWorld->portRect);
- RECT_EQUAL(windowBounds, inWindow->portRect);
-
- CommonRect(&windowBounds, &gWorldBounds);
-
- LockPixels(GetGWorldPixMap(inGWorld));
-
- CopyBits ((BitMap*)*GetGWorldPixMap(inGWorld), &inWindow->portBits,
- &gWorldBounds, &windowBounds, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(inGWorld));
- }
-
-
-
- void DrawChosenLetterFromGFonts(GWorldPtr inGWorld, LetterData *letter)
- {
- Rect letterRect = {0,0,0,0};
- Rect outRect;
- FontData *theFont;
-
- theFont = &FONT_DATA(letter->font, letter->pointSize);
-
- letterRect.left = theFont->kernelOffset[letter->letter];
- letterRect.right = letterRect.left + theFont->kernelWidth[letter->letter] - 1;
- letterRect.bottom = theFont->maxHeight;
-
- outRect.top = letter->y;
- outRect.left = letter->x;
- outRect.right = outRect.left + theFont->kernelWidth[letter->letter] - 1;
- outRect.bottom = outRect.top + theFont->maxHeight;
-
- LockPixels(GetGWorldPixMap(inGWorld));
- LockPixels(GetGWorldPixMap(theFont->kernelBitmap));
-
- CopyBits ( (BitMap*)*GetGWorldPixMap(theFont->kernelBitmap),
- (BitMap*)*GetGWorldPixMap(inGWorld),
- &letterRect, &outRect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(theFont->kernelBitmap));
- UnlockPixels(GetGWorldPixMap(inGWorld));
- }
-
- void DrawChosenLetter(GWorldPtr inGWorld, LetterData *letter)
- {
- GrafPtr savePort;
- GDHandle saveGD;
- Rect boundsRect = {0,0,0,0};
- FontInfo theFontInfo;
-
- // Save the drawing environment.
- GetPort(&savePort);
- saveGD = GetGDevice();
-
- SetPort((GrafPort*)inGWorld);
- TextFont(gFonts[letter->font]);
- TextSize(gPointSizes[letter->pointSize]);
- GetFontInfo(&theFontInfo);
- MoveTo(letter->x,letter->y+theFontInfo.ascent);
-
- ForeColor(yellowColor);
- DrawChar(gLetters[letter->letter]);
-
-
- SetPort(savePort);
- SetGDevice(saveGD);
- }
-
- void DrawChosenString(WindowPtr inWindow, WordData *inWord)
- {
- GrafPtr savePort;
- GDHandle saveGD;
- FontInfo theFontInfo;
- Str255 theString;
-
- // Save the drawing environment.
- GetPort(&savePort);
- saveGD = GetGDevice();
-
- CopyWordToPascalString(theString, inWord);
-
- SetPort((GrafPort*)inWindow);
- TextFont(gFonts[inWord->font]);
- TextSize(gPointSizes[inWord->pointSize]);
- GetFontInfo(&theFontInfo);
- MoveTo(inWord->wordBounds.left,inWord->wordBounds.top+theFontInfo.ascent);
-
- PenMode(patOr);
- DrawString(theString);
-
-
- SetPort(savePort);
- SetGDevice(saveGD);
- }
-
-
- void CopyGWorldToWork (GWorldPtr inGWorld)
- {
- Rect copyRect = {0,0,0,0};
-
- LockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- LockPixels(GetGWorldPixMap(inGWorld));
-
- copyRect.right = inGWorld->portRect.right - inGWorld->portRect.left;
- copyRect.bottom = inGWorld->portRect.bottom - inGWorld->portRect.top;
-
- CopyBits ( (BitMap*)*GetGWorldPixMap(inGWorld),
- (BitMap*)*GetGWorldPixMap(gWorkGWorldPtr),
- ©Rect, ©Rect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- UnlockPixels(GetGWorldPixMap(inGWorld));
- }
- void CopySearchedGWorldToWork (GWorldPtr inGWorld, LetterData *letter)
- {
- Rect copyRect = {0,0,0,0};
- Rect *portRect;
- short midY,midX,kernelHeight,kernelWidth;
- FontData *theFont;
-
- LockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- LockPixels(GetGWorldPixMap(inGWorld));
-
- portRect = &(inGWorld->portRect);
- midY = (portRect->bottom - portRect->top)/2;
- midX = (portRect->right - portRect->left)/2;
- theFont = &(FONT_DATA(letter->font,letter->pointSize));
- kernelHeight = theFont->maxHeight;
- kernelWidth = theFont->kernelWidth[letter->letter];
- copyRect.top = MAX(portRect->top, midY-kernelHeight);
- copyRect.bottom = MIN(portRect->bottom, midY+kernelHeight);
- copyRect.left = MAX(portRect->left, midX-kernelWidth);
- copyRect.right = MIN(portRect->right, midX+kernelWidth);
-
- CopyBits ( (BitMap*)*GetGWorldPixMap(inGWorld),
- (BitMap*)*GetGWorldPixMap(gWorkGWorldPtr),
- ©Rect, ©Rect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- UnlockPixels(GetGWorldPixMap(inGWorld));
- }
- void DrawFontsIntoWorkGWorld(void)
- {
- // first copy all the font gworlds to the window to make sure we're doing it right.
- Rect srcRect = {0,0,0,0};
- Rect destRect = {0,0,0,0};
- int right;
- short font,pointSize;
- GWorldPtr theGWorld;
-
- LockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- for(font=0; font<NUM_FONTS; font++)
- for(pointSize=0; pointSize<NUM_POINT_SIZES; pointSize++)
- {
- theGWorld = FONT_DATA(font,pointSize).kernelBitmap;
-
- LockPixels(GetGWorldPixMap(theGWorld));
-
-
- srcRect.bottom = theGWorld->portRect.bottom - theGWorld->portRect.top;
- destRect.bottom = srcRect.bottom + destRect.top;
- destRect.right = theGWorld->portRect.right - theGWorld->portRect.left;
- right = gWorkGWorldPtr->portRect.right - gWorkGWorldPtr->portRect.left;
- if (destRect.right > right) destRect.right = right;
- srcRect.right = destRect.right;
-
- CopyBits ( (BitMap*)*GetGWorldPixMap(theGWorld),
- (BitMap*)*GetGWorldPixMap(gWorkGWorldPtr),
- &srcRect, &destRect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(theGWorld));
-
- destRect.top = destRect.bottom;
- }
- UnlockPixels(GetGWorldPixMap(gWorkGWorldPtr));
- }
-
- void EraseGWorld(GWorldPtr inGWorld)
- {
- GrafPtr savePort;
- GDHandle saveGD;
-
- // Save the drawing environment.
- GetPort(&savePort);
- saveGD = GetGDevice();
-
- SetPort((GrafPort*)inGWorld);
-
- EraseRect(&(inGWorld->portRect));
-
- SetPort(savePort);
- SetGDevice(saveGD);
- }
- /*
- void HogProcessor (WindowPtr inWindow)
- {
- WindowInfoHandle myWindowInfo;
- long theStartTime, theEndTime, theNumberOfFrames, theFrameRate; // timing stuff
-
- EventRecord myEvent;
- long sleepTime = 0;
-
-
-
- if(inWindow == nil) return; // Sequencer won't be open.
-
- myWindowInfo = (WindowInfoHandle) GetWRefCon(inWindow);
-
- if ((**myWindowInfo).theSG == nil) return; // no sequence grabber
-
- theNumberOfFrames = 0;
-
- theStartTime = TickCount();
-
- while (!Button())
- {
- WaitNextEvent(everyEvent, &myEvent, sleepTime, nil);
-
- // let the Sequence grabber update
- SGIdle((**myWindowInfo).theSG);
-
- // operate on results
- DoWorkOnImageData(gWorkGWorldPtr);
-
- // copy results to window.
- if (gGraphicLevel > 1) UpdateWindow (inWindow);
-
- theNumberOfFrames++;
- }
-
- theEndTime = TickCount();
-
- theFrameRate = theNumberOfFrames / ((theEndTime - theStartTime)/60);
-
- ReportWarning("\pFrameRate = ", theFrameRate); //hack
-
- }
-
- void ProcessMovie (WindowPtr inWindow)
- {
- short movieRefNum;
- OSErr err;
- Movie movie;
- short resID;
- short pixelDepth = 16;
- Rect boundsRect = {0,0,240,320};
-
- GWorldPtr movieGWorld;
-
- // frame by frame variables.
- OSType mediaType = 'eyes';
- TimeValue currentTime, nextTime, frameDurration;
- Fixed rate;
- PicHandle framePic;
- Rect picFrame;
-
- StandardFileReply reply;
- SFTypeList typeList;
-
- GrafPtr savePort;
- GDHandle saveGD;
-
- char frame = 0;
-
- long theStartTime, theEndTime, theNumberOfFrames, theFrameRate; // timing stuff
-
-
- // Get file Spec;
- typeList[0] = 'MooV';
- StandardGetFile(nil, 1, typeList,&reply);
- if (!reply.sfGood) return; // cancel
-
- // Open Movie file
- err = OpenMovieFile (&reply.sfFile, &movieRefNum, fsRdPerm);
-
- resID = 0; // get first movie in file;
- err = NewMovieFromFile (&movie, movieRefNum, &resID, nil, 0, nil);
-
- //GetMovieNaturalBoundsRect(movie,&boundsRect);
- // or is it GetMovieBox(movie,&boundsRect)
- GetMovieBox(movie,&boundsRect);
-
- // Create GWorld for movie.
- if (gWorkGWorldPtr != nil)
- {
- // get size and bit depth from this gWorld.
- pixelDepth = gWorkGWorldPtr->portPixMap[0]->pixelSize;
- // boundsRect.right = gWorkGWorldPtr->portRect.right - gWorkGWorldPtr->portRect.left;
- // boundsRect.bottom = gWorkGWorldPtr->portRect.bottom - gWorkGWorldPtr->portRect.top;
- }
-
- err = NewGWorld(&movieGWorld, pixelDepth, &boundsRect, nil, nil, 0);
-
- SetMovieGWorld(movie, movieGWorld, nil);
-
- // Set up the drawing environment.
- GetPort(&savePort);
- saveGD = GetGDevice();
- SetPort((GrafPort*)movieGWorld);
-
-
- // Now go through the movies frames one by one.
-
- // Find first frame.
-
- rate = 1; // not sure what this value is yet.
- GoToBeginningOfMovie (movie);
- nextTime = GetMovieTime (movie, nil);
-
- // timing stuff
- theNumberOfFrames = 0;
- theStartTime = TickCount();
-
- while (nextTime != -1)
- {
- theNumberOfFrames++;
- frame++;
- currentTime = nextTime;
-
- framePic = GetMoviePict (movie, currentTime);
-
- // Draw with the pic's size to prevent scaling. Different frames can be different
- // sizes. <grin> Especially if you paste pictures into a movie.
- RECT_EQUAL(picFrame,framePic[0]->picFrame);
- DrawPicture(framePic, &picFrame);
- KillPicture(framePic);
-
-
- if (inWindow != nil)
- {
- LockPixels(GetGWorldPixMap(movieGWorld));
-
- CopyBits ((BitMap*)*GetGWorldPixMap(movieGWorld), &inWindow->portBits,
- &boundsRect, &boundsRect, srcCopy, 0);
-
- UnlockPixels(GetGWorldPixMap(movieGWorld));
- }
-
- DoWorkOnImageData (movieGWorld);
-
- UpdateWindow(inWindow);
-
- GetMovieNextInterestingTime (movie, nextTimeMediaSample, 1, &mediaType, currentTime,
- rate, &nextTime, &frameDurration);
-
- // temporary so that we can take pictures of the processing.
- // Get the event.
- //WaitNextEvent(everyEvent, &myEvent, yieldTime, nil);
-
-
- }
- theEndTime = TickCount();
- theFrameRate = theNumberOfFrames / ((theEndTime - theStartTime)/60);
- ReportWarning("\pFrameRate = ", theFrameRate); //hack
-
- // restore graphics environment.
- SetPort(savePort);
- SetGDevice(saveGD);
-
- DisposeGWorld (movieGWorld);
-
- // Close Movie file
- err = CloseMovieFile (movieRefNum);
- }
-
- */
-
-