2021-10-11 18:11:48 +00:00
|
|
|
// Copyright (c) Jon Thysell <http://jonthysell.com>
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
2021-10-15 16:43:09 +00:00
|
|
|
#include "GameWindow.h"
|
2021-10-14 00:44:08 +00:00
|
|
|
#include "MacLO.h"
|
2021-10-11 18:11:48 +00:00
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
#define AppleMenuResID BaseResID
|
|
|
|
#define AboutMenuItemID 1
|
|
|
|
|
|
|
|
#define GameMenuResID BaseResID+1
|
2021-10-31 22:13:51 +00:00
|
|
|
#define NewMenuItemID 1
|
|
|
|
#define QuitMenuItemID 3
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
#define AboutDialogResID BaseResID
|
|
|
|
#define AboutDialogOKID 1
|
|
|
|
|
2021-10-15 16:43:09 +00:00
|
|
|
GameWindow gGameWindow;
|
2021-10-16 00:29:07 +00:00
|
|
|
Boolean gExitApp;
|
|
|
|
|
|
|
|
void MacLO_HandleUpdate(const EventRecord *pEvent);
|
|
|
|
void MacLO_HandleMouseDown(const EventRecord *pEvent);
|
2021-10-20 23:13:31 +00:00
|
|
|
void MacLO_HandleMouseUp(const EventRecord *pEvent);
|
2021-10-16 00:29:07 +00:00
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_HandleMenuChoice(const int32_t menuChoice);
|
|
|
|
void MacLO_HandleAppleMenuChoice(const int16_t item);
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
void MacLO_ShowAboutDialog();
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_LaunchAppleMenuItem(const int16_t item);
|
2021-10-16 00:29:07 +00:00
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_HandleGameMenuChoice(const int16_t item);
|
2021-10-15 16:43:09 +00:00
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
void MacLO_ToolBoxInit()
|
2021-10-11 18:11:48 +00:00
|
|
|
{
|
2021-10-16 00:29:07 +00:00
|
|
|
MaxApplZone();
|
|
|
|
|
2021-10-11 18:11:48 +00:00
|
|
|
InitGraf(&thePort);
|
|
|
|
InitFonts();
|
|
|
|
InitWindows();
|
|
|
|
InitMenus();
|
|
|
|
TEInit();
|
2021-10-14 00:44:08 +00:00
|
|
|
InitDialogs(nil);
|
2021-10-11 18:11:48 +00:00
|
|
|
FlushEvents(everyEvent, 0);
|
|
|
|
InitCursor();
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
void MacLO_AppInit()
|
2021-10-11 18:11:48 +00:00
|
|
|
{
|
2021-10-16 00:29:07 +00:00
|
|
|
Handle menuBar;
|
|
|
|
MenuHandle appleMenu;
|
|
|
|
|
|
|
|
// Add the menu bar
|
|
|
|
menuBar = GetNewMBar(BaseResID);
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
// Populate the apple menu
|
|
|
|
appleMenu = GetMHandle(AppleMenuResID);
|
|
|
|
AddResMenu(appleMenu, 'DRVR');
|
|
|
|
|
|
|
|
DrawMenuBar();
|
|
|
|
|
|
|
|
// Setup the game window
|
2021-10-15 16:43:09 +00:00
|
|
|
GameWindow_Init(&gGameWindow);
|
2021-10-16 00:29:07 +00:00
|
|
|
GameWindow_Show(&gGameWindow);
|
2021-10-11 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 16:43:09 +00:00
|
|
|
void MacLO_MainLoop()
|
2021-10-11 18:11:48 +00:00
|
|
|
{
|
2021-10-16 00:29:07 +00:00
|
|
|
EventRecord event;
|
|
|
|
char cmdChar;
|
|
|
|
|
|
|
|
while (!gExitApp)
|
|
|
|
{
|
|
|
|
if (WaitNextEvent(everyEvent, &event, LONG_MAX, nil))
|
|
|
|
{
|
|
|
|
switch (event.what)
|
|
|
|
{
|
|
|
|
case updateEvt:
|
|
|
|
MacLO_HandleUpdate(&event);
|
|
|
|
break;
|
|
|
|
case mouseDown:
|
|
|
|
MacLO_HandleMouseDown(&event);
|
|
|
|
break;
|
2021-10-20 23:13:31 +00:00
|
|
|
case mouseUp:
|
|
|
|
MacLO_HandleMouseUp(&event);
|
|
|
|
break;
|
2021-10-16 00:29:07 +00:00
|
|
|
case keyDown:
|
|
|
|
case autoKey:
|
|
|
|
// Translate command key combos to menu items
|
|
|
|
cmdChar = event.message & charCodeMask;
|
|
|
|
if ((event.modifiers & cmdKey) != 0)
|
|
|
|
{
|
|
|
|
MacLO_HandleMenuChoice(MenuKey(cmdChar));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-11 18:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
void MacLO_HandleUpdate(const EventRecord *pEvent)
|
|
|
|
{
|
|
|
|
WindowPtr window;
|
|
|
|
|
|
|
|
window = (WindowPtr)pEvent->message;
|
|
|
|
|
|
|
|
BeginUpdate(window);
|
|
|
|
|
|
|
|
if (window == gGameWindow.Window)
|
|
|
|
{
|
2021-10-20 16:34:31 +00:00
|
|
|
GameWindow_Draw(&gGameWindow, true);
|
2021-10-16 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EndUpdate(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacLO_HandleMouseDown(const EventRecord *pEvent)
|
|
|
|
{
|
|
|
|
WindowPtr window;
|
2021-11-05 02:54:28 +00:00
|
|
|
int32_t windowPart;
|
|
|
|
int32_t menuChoice;
|
2021-10-20 16:34:31 +00:00
|
|
|
Point mousePosition;
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
windowPart = FindWindow(pEvent->where, &window);
|
2021-10-20 16:34:31 +00:00
|
|
|
mousePosition = pEvent->where;
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
switch (windowPart)
|
|
|
|
{
|
|
|
|
case inMenuBar:
|
2021-10-20 16:34:31 +00:00
|
|
|
menuChoice = MenuSelect(mousePosition);
|
2021-10-16 00:29:07 +00:00
|
|
|
MacLO_HandleMenuChoice(menuChoice);
|
|
|
|
case inSysWindow:
|
|
|
|
SystemClick(pEvent, window);
|
|
|
|
break;
|
|
|
|
case inDrag:
|
2021-10-20 16:34:31 +00:00
|
|
|
DragWindow(window, mousePosition, &((*GetGrayRgn())->rgnBBox));
|
|
|
|
break;
|
2021-10-20 23:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacLO_HandleMouseUp(const EventRecord *pEvent)
|
|
|
|
{
|
|
|
|
WindowPtr window;
|
2021-11-05 02:54:28 +00:00
|
|
|
int32_t windowPart;
|
2021-10-20 23:13:31 +00:00
|
|
|
Point mousePosition;
|
|
|
|
|
|
|
|
windowPart = FindWindow(pEvent->where, &window);
|
|
|
|
mousePosition = pEvent->where;
|
|
|
|
|
|
|
|
switch (windowPart)
|
|
|
|
{
|
2021-10-20 16:34:31 +00:00
|
|
|
case inContent:
|
|
|
|
GlobalToLocal(&mousePosition);
|
|
|
|
GameWindow_Click(&gGameWindow, &mousePosition);
|
2021-10-16 00:29:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_HandleMenuChoice(const int32_t menuChoice)
|
2021-10-16 00:29:07 +00:00
|
|
|
{
|
2021-11-05 02:54:28 +00:00
|
|
|
int16_t menu;
|
|
|
|
int16_t item;
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
if (menuChoice != 0)
|
|
|
|
{
|
|
|
|
menu = HiWord(menuChoice);
|
|
|
|
item = LoWord(menuChoice);
|
|
|
|
|
|
|
|
switch (menu)
|
|
|
|
{
|
|
|
|
case AppleMenuResID:
|
|
|
|
MacLO_HandleAppleMenuChoice(item);
|
|
|
|
break;
|
|
|
|
case GameMenuResID:
|
|
|
|
MacLO_HandleGameMenuChoice(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
HiliteMenu(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_HandleAppleMenuChoice(const int16_t item)
|
2021-10-16 00:29:07 +00:00
|
|
|
{
|
|
|
|
MenuHandle appleMenu;
|
|
|
|
Str255 accName;
|
2021-11-05 02:54:28 +00:00
|
|
|
int16_t accNumber;
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
switch (item)
|
|
|
|
{
|
|
|
|
case AboutMenuItemID:
|
|
|
|
MacLO_ShowAboutDialog();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MacLO_LaunchAppleMenuItem(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MacLO_ShowAboutDialog()
|
|
|
|
{
|
|
|
|
DialogPtr dialog;
|
2021-11-10 01:01:34 +00:00
|
|
|
int32_t itemHit;
|
2021-10-16 00:29:07 +00:00
|
|
|
|
|
|
|
dialog = GetNewDialog(AboutDialogResID, nil, MoveToFront);
|
|
|
|
|
|
|
|
SetPort(dialog);
|
2021-10-16 22:38:43 +00:00
|
|
|
|
|
|
|
SetDialogDefaultItem(dialog, AboutDialogOKID);
|
|
|
|
|
2021-10-16 00:29:07 +00:00
|
|
|
ShowWindow(dialog);
|
|
|
|
|
|
|
|
ModalDialog(nil, &itemHit);
|
|
|
|
|
|
|
|
DisposDialog(dialog);
|
|
|
|
}
|
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_LaunchAppleMenuItem(const int16_t item)
|
2021-10-16 00:29:07 +00:00
|
|
|
{
|
|
|
|
MenuHandle appleMenu;
|
|
|
|
Str255 accName;
|
|
|
|
|
|
|
|
appleMenu = GetMHandle(AppleMenuResID);
|
|
|
|
GetItem(appleMenu, item, accName);
|
|
|
|
OpenDeskAcc(accName);
|
|
|
|
}
|
|
|
|
|
2021-11-05 02:54:28 +00:00
|
|
|
void MacLO_HandleGameMenuChoice(const int16_t item)
|
2021-10-16 00:29:07 +00:00
|
|
|
{
|
|
|
|
switch (item)
|
|
|
|
{
|
2021-10-31 22:13:51 +00:00
|
|
|
case NewMenuItemID:
|
|
|
|
GameWindow_SetScene(&gGameWindow, Title);
|
|
|
|
break;
|
2021-10-16 00:29:07 +00:00
|
|
|
case QuitMenuItemID:
|
|
|
|
gExitApp = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|