home *** CD-ROM | disk | FTP | other *** search
- #include <LowMem.h>
- #include <Menus.h>
- #include <stdlib.h>
- #include <QDOffscreen.h>
- #include <string.h>
- #include "QDUtils.h"
- #include "DefaultMDEF.h"
- #include "MenuSelect.h"
-
-
- //#define YEHUDI 1
-
-
- #ifdef YEHUDI
- #include "PlayNotes.h"
- #endif
-
- Boolean gTranslucent = true;
- GWorldPtr gScreenBuffer = nil;
- CGrafPtr gScreenPort = nil;
-
- typedef struct
- {
- Rect titleRect, menuRect;
- char menuTitle[256];
- MenuHandle menuHandle;
- short menuID;
- MenuDefProcPtr proc;
- }OurMenuInformation;
-
-
- #pragma options align=mac68k
- typedef struct
- {
- MenuHandle menuOH; //handle to menu's menu record}
- short menuLeft; // pixel location of left edge }
- // of this menu}
- }MenuRec;
-
-
- typedef struct
- {
- short lastMenu; // offset to last pull-down menu}
- short lastRight; // pixel location of right edge }
- // of rightmost menu in menu bar}
- short mbResID; // upper 13 bits are the resource ID of menu}
- MenuRec menuArray[1];
- }HackMListTop;
-
- #pragma options align=reset
-
- OSErr ShowMenu( OurMenuInformation *info, GWorldPtr screenBuffer, MenuFX showFX);
-
- OSErr HideMenu( OurMenuInformation *info, short chosenItem,
- GWorldPtr screenBuffer, MenuFX hideFX);
- OSErr TrackMenu( OurMenuInformation *info, Point where, short *inItem);
- void InvertMenuTitle(OurMenuInformation *info);
-
- void EraseMenuRect(Rect *r)
- {
- if (gTranslucent)
- {
- Rect r2 = *r;
- OffsetRect(&r2, 1, 1);
- QDNormal();
- SetRGBForeColor(0x7777, 0x7777,0x7777);
- SetRGBBackColor(0xEEEE, 0xEEEE,0xEEEE);
- CopyBits( (BitMap*)*gScreenBuffer->portPixMap,
- (BitMap*)*gScreenPort->portPixMap, &r2, r, srcCopy, nil);
- QDNormal();
- }
- else
- EraseRect(r);
- }
-
-
- static int RangedRdm(int min, int max)
- {
- return ((Random() * ((max + 1) - min)) >> 15) + min;
- }
-
- static Boolean PointInMenuTitle( Point where, OurMenuInformation* info,
- int menuCount, int *which)
- {
- int x;
-
-
- for(x = 0 ; x < menuCount ; x++)
- if (PtInRect(where, &info[x].titleRect))
- {
- *which = x;
- return true;
- }
-
- return false;
- }
-
-
-
- long AltMenuSelect(Point where, MenuFX showFX, MenuFX hideFX)
- {
- OSErr result = noErr;
- HackMListTop **menuList = (HackMListTop**) LMGetMenuList();
- int menuCount = 0;
- int x;
- OurMenuInformation *menuInfo = nil;
- Rect menuBarRect, screenRect;
- short chosenMenu = 0, chosenItem = 0;
- long returnValue = 0;
- short menuBarHeight = LMGetMBarHeight();
- CGrafPtr savePort, menuPort;
- GDHandle saveGD;
- int pulledDownMenu = -1;
- GWorldPtr screenBuffer = nil;
- PixMapHandle screenPix = GetMainDevice()[0]->gdPMap;
- /*Handle mdef = GetResource('MDEF', 0);
-
- DetachResource(mdef);
- HLockHi(mdef);*/
-
- GetGWorld(&savePort, &saveGD);
-
- screenRect = GetMainDevice()[0]->gdRect;
-
- #ifdef YEHUDI
- SetupPlaying();
- #endif
-
- if (result = NewGWorld( &screenBuffer, screenPix[0]->pixelSize,
- &screenRect, screenPix[0]->pmTable, nil, useTempMem))
- {
- if (result = NewGWorld( &screenBuffer, screenPix[0]->pixelSize,
- &screenRect, screenPix[0]->pmTable, nil, 0))
- goto bail;
- }
-
-
-
- LockPixels(screenBuffer->portPixMap);
- SetGWorld(screenBuffer, nil);
- ForeColor(blackColor);
- BackColor(whiteColor);
- CopyBits( (BitMap*)*screenPix, (BitMap*)*screenBuffer->portPixMap,
- &screenRect, &screenRect, srcCopy, nil);
-
-
- GetCWMgrPort(&menuPort);
-
- gScreenBuffer = screenBuffer;
- gScreenPort = menuPort;
-
- SetGWorld(menuPort, GetMainDevice());
- ClipRect(&menuPort->portRect);
-
- menuBarRect = GetMainDevice()[0]->gdRect;
- menuBarRect.bottom = menuBarRect.top + menuBarHeight;
-
- menuCount = (menuList[0]->lastMenu /*-12*/) / 6;
-
- menuInfo = (OurMenuInformation *) NewPtrClear(sizeof(OurMenuInformation)*menuCount);
-
- TextFont(0);
- TextSize(0);
-
- for(x = 0 ; x < menuCount ; x++)
- {
- Rect r;
- Str255 menuName;
- MenuHandle thisMenuHandle = menuList[0]->menuArray[x].menuOH;
-
- BlockMoveData( &thisMenuHandle[0]->menuData[0], &menuName[0],
- thisMenuHandle[0]->menuData[0] + 1);
-
- p2cstr(menuName);
-
- r.top = 0;
- r.bottom = 20;
- r.left = menuList[0]->menuArray[x].menuLeft;
- r.right = r.left + stringwidth((char*)menuName) + 13;
-
- menuInfo[x].titleRect = r;
- strcpy((char*)menuInfo[x].menuTitle, (char*)menuName);
- menuInfo[x].menuHandle = thisMenuHandle;
- menuInfo[x].menuID = thisMenuHandle[0]->menuID;
-
-
- menuInfo[x].proc = DefaultMDEF;
- //menuInfo[x].proc = (MenuDefProcPtr)*mdef;
- }
-
- while(Button())
- {
- int foundMenu;
- Boolean inMenuBar = false, inMenuTitle = false;
-
- GetMouse(&where);
-
- #ifdef YEHUDI
- PlayANote(where.v);
- #endif
-
- inMenuBar = PtInRect(where, &menuBarRect);
-
- if (inMenuBar)
- {
- inMenuTitle = PointInMenuTitle(where, menuInfo, menuCount, &foundMenu);
-
- if ((pulledDownMenu != -1) && (inMenuBar == true && inMenuTitle == false)
- || (inMenuTitle == true) && (foundMenu != pulledDownMenu))
- { // remove pulled down menu
- InvertMenuTitle(&menuInfo[pulledDownMenu]);
- HideMenu(&menuInfo[pulledDownMenu], 0, screenBuffer, kFXNone/*hideFX*/);
- pulledDownMenu = -1;
- }
-
- if ((pulledDownMenu == -1) && (inMenuTitle == true)) // put up a new menu
- {
- pulledDownMenu = foundMenu;
- InvertMenuTitle(&menuInfo[pulledDownMenu]);
- ShowMenu(&menuInfo[pulledDownMenu], screenBuffer, showFX);
- }
- }
-
- if (pulledDownMenu != -1) // there is a menu, so track it
- {
- TrackMenu(&menuInfo[pulledDownMenu], where, &chosenItem);
-
- if (chosenItem)
- chosenMenu = pulledDownMenu;
- }
- }
-
- if (pulledDownMenu != -1)
- {
- HideMenu(&menuInfo[pulledDownMenu], chosenItem, screenBuffer, hideFX);
-
- InvertMenuTitle(&menuInfo[pulledDownMenu]);
- }
-
- if (chosenItem)
- {
- returnValue = menuInfo[pulledDownMenu].menuID;
- returnValue = (returnValue << 16) | chosenItem;
- }
-
- bail:
- #ifdef YEHUDI
- StopPlaying();
- #endif
-
- if (screenBuffer != nil)
- DisposeGWorld(screenBuffer);
-
- if (menuInfo != nil)
- DisposePtr((Ptr)menuInfo);
-
- SetGWorld(savePort, saveGD);
-
- return returnValue;
- }
-
- void InvertMenuTitle(OurMenuInformation *info)
- {
- Rect r = info->titleRect;
-
- r.bottom--;
- InvertRect(&r);
- }
-
- static void UpdateMenuRect(OurMenuInformation *info)
- {
-
- Rect r = {0,0,0,0}, screenRect;
- short inItem = 0;
- MenuHandle menuHandle = info->menuHandle;
-
- r.top = 20;
- r.left = info->titleRect.left + 1;
- r.bottom = r.top + menuHandle[0]->menuHeight;
- r.right = r.left + menuHandle[0]->menuWidth;
-
- screenRect = GetMainDevice()[0]->gdRect;
-
- if (r.right > screenRect.right)
- OffsetRect(&r, screenRect.right - r.right, 0);
-
- info->menuRect = r;
-
- }
-
- static void DrawMenuBackground(OurMenuInformation *info, Rect r)
- {
-
- ForeColor(blackColor);
- BackColor(whiteColor);
-
- EraseMenuRect(&r);
- InsetRect(&r, -1,-1);
- FrameRect(&r);
-
- /*
- MoveTo(r.right, r.top + 2);
- LineTo(r.right, r.bottom);
- LineTo(r.left + 2, r.bottom);*/
- }
-
- OSErr ShowMenu(OurMenuInformation *info, GWorldPtr screenBuffer, MenuFX showFX)
- {
- OSErr result = noErr;
- Rect r = {0,0,0,0};
- short inItem = 0;
- Point where = {0,0};
- MenuHandle menuHandle = info->menuHandle;
- CGrafPtr savePort;
- GDHandle saveGD;
-
- GetGWorld(&savePort, &saveGD);
-
-
- (info->proc)(mSizeMsg, menuHandle,
- &r, where, &inItem);
-
- UpdateMenuRect(info);
-
-
- switch(showFX)
- {
- default:
- case kFXNone:
- DrawMenuBackground(info, info->menuRect);
-
- (info->proc) (mDrawMsg, menuHandle, &info->menuRect, where, &inItem);
- break;
-
- /*case kFXIrisOpen:
-
- break;*/
- case kFXSlide:
- {
- GWorldPtr fxGW = nil;
- Rect mRect = info->menuRect;
- int x;
- int iterations = 18;
- int xDelta = - 16;//RangedRdm(0, 64) - 32;
- int yDelta = -16;//RangedRdm(0, 64) - 32;
- Boolean clipped = false;
- Rect nonMenubarRect = GetMainDevice()[0]->gdRect;
-
- nonMenubarRect.top = 20;
- ClipRect(&nonMenubarRect);
-
- OffsetRect(&mRect, -xDelta * iterations, -yDelta * iterations);
- for(x = 0 ; x <= iterations ; x++)
- {
- QDNormal();
-
- DrawMenuBackground(info, mRect);
-
- (info->proc) (mDrawMsg, menuHandle, &mRect, where, &inItem);
- OffsetRect(&mRect, xDelta, yDelta);
- }
-
- QDNormal();
- SetGWorld(savePort, saveGD);
- CopyBits((BitMap*)*screenBuffer->portPixMap,
- (BitMap*)*savePort->portPixMap,
- &screenBuffer->portRect,&screenBuffer->portRect,
- srcCopy, nil);
- DrawMenuBackground(info, info->menuRect);
- (info->proc) (mDrawMsg, menuHandle, &info->menuRect, where, &inItem);
-
- ClipRect(&savePort->portRect);
- }
- break;
- }
-
- ForeColor(blackColor);
- BackColor(whiteColor);
-
- SetGWorld(savePort, saveGD);
- return result;
- }
-
-
- OSErr HideMenu( OurMenuInformation *info, short chosenItem,
- GWorldPtr screenBuffer, MenuFX hideFX)
- {
- OSErr result = noErr;
- Rect menuRect;
- int x;
- Rect r = screenBuffer->portRect;
- GWorldPtr fxGW = nil;
- Rect fxRect;
- CGrafPtr savePort;
- GDHandle saveGD;
-
- GetGWorld(&savePort, &saveGD);
-
- menuRect = info->menuRect;
- menuRect.right += 3;
- menuRect.left -= 2;
- menuRect.bottom += 2;
-
- QDNormal();
-
- if (chosenItem == 0)
- hideFX = kFXNone;
-
- switch(hideFX)
- {
- default:
- case kFXNone:
- CopyBits((BitMap*)*screenBuffer->portPixMap, (BitMap*)*GetMainDevice()[0]->gdPMap,
- &menuRect, &menuRect, srcCopy, nil);
- break;
- case kFXZoomIn:
- case kFXZoomOut:
- {
- fxRect = menuRect;
- ZeroRect(&fxRect);
- if (result = NewGWorld( &fxGW, screenBuffer->portPixMap[0]->pixelSize,
- &fxRect, nil, nil, useTempMem))
- if (result = NewGWorld( &fxGW, screenBuffer->portPixMap[0]->pixelSize,
- &fxRect, nil, nil, useTempMem))
- goto bail;
-
-
- QDNormal();
-
- CopyBits((BitMap*)*savePort->portPixMap,(BitMap*)*fxGW->portPixMap,
- &menuRect, &fxRect, srcCopy, nil);
-
- if (hideFX == kFXZoomOut)
- for (x = 0 ; x < 20 ; x++)
- {
- InsetRect(&menuRect, 8, 4 );
- CopyBits((BitMap*)*fxGW->portPixMap,(BitMap*)*savePort->portPixMap,
- &fxRect, &menuRect,ditherCopy, nil);
- }
- else
- for (x = 0 ; x < 10 ; x++)
- {
- InsetRect(&menuRect, -(x + 1) * 88, -(x + 1) * 44);
- CopyBits((BitMap*)*fxGW->portPixMap,(BitMap*)*savePort->portPixMap,
- &fxRect, &menuRect,srcCopy, nil);
- }
-
-
- CopyBits((BitMap*)*screenBuffer->portPixMap, (BitMap*)*GetMainDevice()[0]->gdPMap,
- &r, &r, srcCopy, nil);
- break;
- }
-
- }
-
-
- bail:
-
- if (fxGW)
- DisposeGWorld(fxGW);
-
- SetGWorld(savePort, saveGD);
-
- return result;
- }
-
-
- OSErr TrackMenu( OurMenuInformation *info, Point where, short *inItem)
- {
- OSErr result = noErr;
-
- (info->proc) (mChooseMsg, info->menuHandle, &info->menuRect, where, inItem);
-
- return result;
- }
-