commit f27ffe0014f33bf3b1f901743cb413c02af4068c Author: James Robert Perih Date: Sun Mar 10 14:36:08 2019 -0600 Initial Commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97da048 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +**.xSYM +MacBoilerplate Data/ + + diff --git a/MacBoilerplate.c b/MacBoilerplate.c new file mode 100644 index 0000000..af70ae6 --- /dev/null +++ b/MacBoilerplate.c @@ -0,0 +1 @@ +/** * (c) 2019, James Robert Perih * Yes, two-thousand-and-nineteen. Not even kidding. * * This is just a boilerplate Mac Toolbox C Structure. Needed for basically any Mac app starter. * */ #include // Main Methods void InitToolbox(void); void InitWindow(void); void DoHandleEvent(EventRecord*); void DoRunLoop(void); // Handler Methods void HandleKeyDown(EventRecord*); void HandleMouseDown(EventRecord*); void HandleUpdate(EventRecord*); void HandleOSEvent(EventRecord*); // Globals Boolean endProgram; // if we can should exit the run loop and end the program /** * Handle Window (needs) Update events */ void HandleUpdate(EventRecord* theEvent) { BeginUpdate((WindowPtr)theEvent->message); EndUpdate((WindowPtr)theEvent->message); } /** * Handle Keydown Events */ void HandleKeyDown(EventRecord* theEvent) { switch (theEvent->what) { default: MoveTo(10, 20); DrawString("\pKey pressed."); } } /** * Handle Mousedown events */ void HandleMouseDown(EventRecord* theEvent) { WindowPtr whichWindow; WindowPartCode theWindowPart; theWindowPart = FindWindow(theEvent->where, &whichWindow); switch (theWindowPart) { case inDrag: DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds); break; case inGoAway: if (TrackGoAway(whichWindow, theEvent->where)) { DisposeWindow(whichWindow); endProgram = true; } break; case inSysWindow: SystemClick(theEvent, whichWindow); break; } } void HandleOSEvent(EventRecord* theEvent) { WindowRef window; SInt16 osMessage; Boolean isNowActive; osMessage = (theEvent->message & osEvtMessageMask) >> 24; switch (osMessage) { case suspendResumeMessage: HandleUpdate(theEvent); MoveTo(10, 60); if ((window = FrontWindow()) != NULL) { isNowActive = (theEvent->message & resumeFlag) != 0; if (isNowActive) { DrawString("\pWelcome back!"); } else { DrawString("\pWait... where did you go?"); } } else { // not our window, but how would this ever happen?! } break; case mouseMovedMessage: break; default: MoveTo(10, 90); DrawString("\pI don't know what happened..."); break; } } /** * Standard Mac Toolbox Init */ void InitToolbox(void) { InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(0L); FlushEvents(everyEvent, 0); InitCursor(); } /** * Sets up our main window. */ void InitWindow(void) { WindowPtr theWindow; theWindow = GetNewWindow(128, nil, (WindowPtr)-1L); SetPort(theWindow); } /** * Main event handler */ void DoHandleEvent(EventRecord* theEvent) { switch (theEvent->what) { case keyDown: HandleKeyDown(theEvent); // TODO: probably follow with the keycode... break; case mouseDown: HandleMouseDown(theEvent); break; case osEvt: HandleOSEvent(theEvent); break; case updateEvt: HandleUpdate(theEvent); break; } } /** * Main Runloop */ void DoRunLoop(void) { EventRecord theEvent; endProgram = false; while (endProgram != true) { if (WaitNextEvent(everyEvent, &theEvent, 30L, nil)) { DoHandleEvent(&theEvent); } else { if (FrontWindow()) { // IdleControls(FrontWindow()); } } } } /** * MAIN */ void main(void) { InitToolbox(); InitWindow(); DoRunLoop(); } \ No newline at end of file diff --git a/MacBoilerplate.rsrc b/MacBoilerplate.rsrc new file mode 100644 index 0000000..e69de29 diff --git a/MacBoilerplate.µ b/MacBoilerplate.µ new file mode 100644 index 0000000..fafa171 Binary files /dev/null and b/MacBoilerplate.µ differ