?? macmain.c
字號:
#include "MacMain.h"#include "AICommon.h" #define kAppleID 128 #define kAppleM 0 #define kQuit 7 UniversalProcPtr MyHandleOAppUPP; UniversalProcPtr MyHandleODocUPP; UniversalProcPtr MyHandlePDocUPP; UniversalProcPtr MyHandleQuitUPP; ModalFilterUPP myGenericFilter; OSErr Error; WindowPtr Window; Boolean Done; MenuHandle myMenus[1]; extern int tbWindow; Boolean applicationSuspended; extern ai_World MainWorld; extern ai_Entity entityList[kMaxEntities]; // ----------------------------------------------------------------- //static pascal OSErr MyHandleOApp (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{ applicationSuspended=false; return noErr; }// ----------------------------------------------------------------- //static pascal OSErr MyHandleODoc (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{ return noErr; }// ----------------------------------------------------------------- //static pascal OSErr MyHandlePDoc (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{ return noErr; }// ----------------------------------------------------------------- //pascal OSErr MyHandleQuit( const AppleEvent *appleEvt, AppleEvent *reply, long refcon )// ----------------------------------------------------------------- //{ Done = true; return noErr;}// ----------------------------------------------------------------- //void OpenWindow(void)// ----------------------------------------------------------------- // { Window = GetNewCWindow(128, nil, (WindowPtr)-1L); if (Window != nil) { SetPortWindowPort(Window); ShowWindow(Window); SelectWindow(Window); tbWindow=tb_SetWindowPtr(Window); }}// ----------------------------------------------------------------- //void Initialize(void)// ----------------------------------------------------------------- //{ unsigned long randomSeed; long response=0; GetDateTime(&randomSeed); SetQDGlobalsRandomSeed(randomSeed); Error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(MyHandleOApp), 0, false); Error = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(MyHandleODoc), 0, false); Error = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerUPP(MyHandlePDoc), 0, false); Error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(MyHandleQuit), 0, false); Done = false; applicationSuspended=false; }// ----------------------------------------------------------------- //pascal TBoolean GenericFilter (DialogPtr theDialog, EventRecord *theEvent, SInt16 *itemHit)// ----------------------------------------------------------------- //{ char theChar; short kind; Handle item; TRect box; BitMap screenBits; short windowPart; Point globalPt = theEvent->where; WindowPtr wp; Pattern black; GetQDGlobalsScreenBits(&screenBits); GetQDGlobalsBlack(&black); switch (theEvent->what) { case mouseDown: windowPart = FindWindow(globalPt, &wp); if (windowPart==inDrag) { InitCursor(); SetPortWindowPort(wp); DragWindow(wp, theEvent->where, &screenBits.bounds); return (true); } if (windowPart==inGoAway) { SetPortWindowPort(wp); if (TrackGoAway(wp,globalPt)) *itemHit=kCancelButton; return (true); } break; case keyDown: theChar=(char)(theEvent->message & charCodeMask); if ((((theEvent->modifiers & cmdKey) !=0) && (theChar=='.')) || (theChar==(char)27)) { *itemHit=kCancelButton; GetDialogItem(theDialog, kCancelButton, &kind, &item, &box); HiliteControl((ControlHandle)item, 1); return true; }; if ((theChar==(char)13) || (theChar==(char)3)) { *itemHit=kOKButton; GetDialogItem(theDialog, 1, &kind, &item, &box); HiliteControl((ControlHandle)item, kOKButton); return true; }; break; case updateEvt: BeginUpdate(GetDialogWindow(theDialog)); SetPortDialogPort(theDialog); DrawDialog(theDialog); EndUpdate(GetDialogWindow(theDialog)); if (Window!=nil) { SetPortWindowPort(Window); BeginUpdate(Window); MainWorld.Redraw(); EndUpdate(Window); } SetPortDialogPort(theDialog); break; } return false; }// ----------------------------------------------------------------- //void SetUpMenus(void)// ----------------------------------------------------------------- // { short i; myMenus[kAppleM] = GetMenu(kAppleID); for (i=kAppleM; i<=kAppleM; i++) InsertMenu(myMenus[i], 0); DrawMenuBar(); }// ----------------------------------------------------------------- //void DoMenus (long menuResult)// ----------------------------------------------------------------- //{ short theMenu = (menuResult >> 16); short theItem = (menuResult & 0x0000FFFF); switch (theMenu) { case kAppleID: { if (theItem==1) tb_DoDialog(128); } break; } HiliteMenu(0); }// ----------------------------------------------------------------- //void DoMouseDown (EventRecord *theEvent)// ----------------------------------------------------------------- //{ Point globalPt = theEvent->where; short windowPart; WindowPtr wp; int match=-1; BitMap screenBits; short MenuHeight=GetMBarHeight(); GetQDGlobalsScreenBits(&screenBits); windowPart = FindWindow(globalPt, &wp); switch (windowPart) { case inMenuBar: DoMenus(MenuSelect(globalPt)); break; case inSysWindow: break; case inDrag: SetPortWindowPort(wp); DragWindow(wp, theEvent->where, &screenBits.bounds); break; case inZoomIn: case inZoomOut: break; case inGrow: break; case inGoAway: SetPortWindowPort(wp); if (TrackGoAway(wp,globalPt)) Done = true; break; case inContent: { SetPortWindowPort(wp); SelectWindow(wp); } break; } }// ----------------------------------------------------------------- //void DoKey (EventRecord *theEvent)// ----------------------------------------------------------------- //{ char keyPressed = (theEvent->message & charCodeMask); if (theEvent->modifiers & cmdKey) DoMenus(MenuKey(keyPressed)); }// ----------------------------------------------------------------- //void DoActivate (EventRecord *theEvent)// ----------------------------------------------------------------- //{ }// ----------------------------------------------------------------- //void DoSuspendResume(Boolean InForeground)// ----------------------------------------------------------------- //{ if (InForeground) { applicationSuspended=false; } else { applicationSuspended=true; }}// ----------------------------------------------------------------- //void MainLoop()// ----------------------------------------------------------------- //{ EventRecord theEvent; static long sleepTime = 1L; int match=-1; BitMap screenBits; GetQDGlobalsScreenBits(&screenBits); WaitNextEvent(everyEvent, &theEvent, sleepTime, NULL); switch (theEvent.what) { case nullEvent: MainWorld.UpdateWorld(); break; case mouseDown: DoMouseDown(&theEvent); break; case keyDown: case autoKey: DoKey(&theEvent); break; case activateEvt: DoActivate(&theEvent); break; case updateEvt: { match=tb_GetWindowMatch((WindowPtr)theEvent.message); if (match!=-1) { BeginUpdate((WindowPtr)theEvent.message); EndUpdate((WindowPtr)theEvent.message); MainWorld.Redraw(); } } break; case osEvt: if ((theEvent.message >> 24) & suspendResumeMessage ) DoSuspendResume((theEvent.message & resumeFlag)!=0); break; case kHighLevelEvent: (void)AEProcessAppleEvent(&theEvent); } }// ----------------------------------------------------------------- //void main(void)// ----------------------------------------------------------------- //{ Initialize(); SetUpMenus(); OpenWindow(); tb_FlushMouseEvents(); while (!Done) MainLoop(); tb_CloseToolbox();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -