show state dialog when selected from menu

This commit is contained in:
Matthew Laux 2022-06-29 01:19:35 -05:00
parent 698cc17030
commit e00b998024
2 changed files with 171 additions and 142 deletions

View File

@ -28,185 +28,212 @@ emu_state theState;
void InitEverything(void) void InitEverything(void)
{ {
Handle mbar; Handle mbar;
InitGraf(&qd.thePort); InitGraf(&qd.thePort);
InitFonts(); InitFonts();
InitWindows(); InitWindows();
InitMenus(); InitMenus();
TEInit(); TEInit();
InitDialogs(0L); InitDialogs(0L);
InitCursor(); InitCursor();
mbar = GetNewMBar(MBAR_DEFAULT); mbar = GetNewMBar(MBAR_DEFAULT);
SetMenuBar(mbar); SetMenuBar(mbar);
DrawMenuBar(); DrawMenuBar();
g_running = 1; g_running = 1;
} }
void Render(void) void Render(void)
{ {
MoveTo(10, 10); MoveTo(10, 10);
DrawString("\pTest 123"); DrawString("\pTest 123");
} }
void StartEmulation(void) void StartEmulation(void)
{ {
g_wp = NewWindow(0, &windowBounds, WINDOW_TITLE, true, g_wp = NewWindow(0, &windowBounds, WINDOW_TITLE, true,
noGrowDocProc, (WindowPtr) -1, true, 0); noGrowDocProc, (WindowPtr) -1, true, 0);
SetPort(g_wp); SetPort(g_wp);
} }
bool LoadRom(StrFileName fileName, short vRefNum) bool LoadRom(StrFileName fileName, short vRefNum)
{ {
int err; int err;
short fileNo; short fileNo;
long amtRead; long amtRead;
if(theState.rom != NULL) { if(theState.rom != NULL) {
// unload existing ROM // unload existing ROM
free((char *) theState.rom); free((char *) theState.rom);
theState.romLength = 0; theState.romLength = 0;
} }
err = FSOpen(fileName, vRefNum, &fileNo); err = FSOpen(fileName, vRefNum, &fileNo);
if(err != noErr) { if(err != noErr) {
return false; return false;
} }
GetEOF(fileNo, (long *) &theState.romLength); GetEOF(fileNo, (long *) &theState.romLength);
theState.rom = (unsigned char *) malloc(theState.romLength); theState.rom = (unsigned char *) malloc(theState.romLength);
if(theState.rom == NULL) { if(theState.rom == NULL) {
Alert(ALRT_NOT_ENOUGH_RAM, NULL); Alert(ALRT_NOT_ENOUGH_RAM, NULL);
return false; return false;
} }
amtRead = theState.romLength; amtRead = theState.romLength;
FSRead(fileNo, &amtRead, theState.rom); FSRead(fileNo, &amtRead, theState.rom);
return true; return true;
} }
// -- DIALOG BOX FUNCTIONS -- // -- DIALOG BOX FUNCTIONS --
bool ShowOpenBox(void) bool ShowOpenBox(void)
{ {
SFReply reply; SFReply reply;
Point pt = { 0, 0 }; Point pt = { 0, 0 };
const int stdWidth = 348; const int stdWidth = 348;
Rect rect; Rect rect;
pt.h = qd.screenBits.bounds.right / 2 - stdWidth / 2; pt.h = qd.screenBits.bounds.right / 2 - stdWidth / 2;
SFGetFile(pt, NULL, NULL, -1, NULL, NULL, &reply); SFGetFile(pt, NULL, NULL, -1, NULL, NULL, &reply);
if(reply.good) { if(reply.good) {
return LoadRom(reply.fName, reply.vRefNum); return LoadRom(reply.fName, reply.vRefNum);
} }
return false; return false;
}
DialogPtr stateDialog;
void ShowStateDialog(void)
{
DialogPtr dp;
if (!stateDialog) {
stateDialog = GetNewDialog(DLOG_STATE, 0L, (WindowPtr) -1L);
}
ShowWindow(stateDialog);
SelectWindow(stateDialog);
} }
void ShowAboutBox(void) void ShowAboutBox(void)
{ {
DialogPtr dp; DialogPtr dp;
EventRecord e; EventRecord e;
DialogItemIndex hitItem;
dp = GetNewDialog(DLOG_ABOUT, 0L, (WindowPtr) -1L);
dp = GetNewDialog(DLOG_ABOUT, 0L, (WindowPtr) -1L);
DrawDialog(dp);
ModalDialog(NULL, &hitItem);
while(!GetNextEvent(mDownMask, &e));
while(WaitMouseUp()); // DrawDialog(dp);
// while(!GetNextEvent(mDownMask, &e));
DisposeDialog(dp); // while(WaitMouseUp());
DisposeDialog(dp);
} }
// -- EVENT FUNCTIONS -- // -- EVENT FUNCTIONS --
void OnMenuAction(long action) void OnMenuAction(long action)
{ {
short menu, item; short menu, item;
if(action <= 0) if(action <= 0)
return; return;
HiliteMenu(0); HiliteMenu(0);
menu = HiWord(action); menu = HiWord(action);
item = LoWord(action); item = LoWord(action);
if(menu == MENU_APPLE) { if(menu == MENU_APPLE) {
if(item == APPLE_ABOUT) { if(item == APPLE_ABOUT) {
ShowAboutBox(); ShowAboutBox();
} }
} }
else if(menu == MENU_FILE) { else if(menu == MENU_FILE) {
if(item == FILE_OPEN) { if(item == FILE_OPEN) {
if(ShowOpenBox()) if(ShowOpenBox())
StartEmulation(); StartEmulation();
} }
else if(item == FILE_QUIT) { else if(item == FILE_QUIT) {
g_running = 0; g_running = 0;
} }
} }
else if (menu == MENU_EMULATION) {
if (item == EMULATION_STATE) {
ShowStateDialog();
}
}
} }
void OnMouseDown(EventRecord *pEvt) void OnMouseDown(EventRecord *pEvt)
{ {
short part; short part;
WindowPtr clicked; WindowPtr clicked;
long action; long action;
part = FindWindow(pEvt->where, &clicked); part = FindWindow(pEvt->where, &clicked);
switch(part) { switch(part) {
case inDrag: case inDrag:
DragWindow(clicked, pEvt->where, &qd.screenBits.bounds); DragWindow(clicked, pEvt->where, &qd.screenBits.bounds);
break; break;
case inGoAway: case inGoAway:
if(TrackGoAway(clicked, pEvt->where)) if(TrackGoAway(clicked, pEvt->where))
DisposeWindow(clicked); DisposeWindow(clicked);
break; break;
case inContent: case inContent:
if(clicked != FrontWindow()) if(clicked != FrontWindow())
SelectWindow(clicked); SelectWindow(clicked);
break; break;
case inMenuBar: case inMenuBar:
action = MenuSelect(pEvt->where); action = MenuSelect(pEvt->where);
OnMenuAction(action); OnMenuAction(action);
break; break;
} }
} }
// -- ENTRY POINT -- // -- ENTRY POINT --
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
EventRecord evt; EventRecord evt;
InitEverything(); InitEverything();
while(g_running) { while(g_running) {
if(WaitNextEvent(everyEvent, &evt, 10, 0) != nullEvent) { if(WaitNextEvent(everyEvent, &evt, 10, 0) != nullEvent) {
switch(evt.what) { if (IsDialogEvent(&evt)) {
case mouseDown: DialogRef hitBox;
OnMouseDown(&evt); DialogItemIndex hitItem;
break; if (DialogSelect(&evt, &hitBox, &hitItem)) {
case updateEvt: stateDialog = NULL;
BeginUpdate((WindowPtr) evt.message); }
Render(); } else switch(evt.what) {
EndUpdate((WindowPtr) evt.message); case mouseDown:
break; OnMouseDown(&evt);
} break;
} case updateEvt:
} BeginUpdate((WindowPtr) evt.message);
Render();
return 0; EndUpdate((WindowPtr) evt.message);
break;
}
}
}
return 0;
} }

View File

@ -21,6 +21,7 @@
#define ALRT_4_LINE 129 #define ALRT_4_LINE 129
#define DLOG_ABOUT 128 #define DLOG_ABOUT 128
#define DLOG_STATE 129
#define MBAR_DEFAULT 128 #define MBAR_DEFAULT 128
@ -35,8 +36,9 @@
#define FILE_QUIT 4 #define FILE_QUIT 4
#define EMULATION_PAUSE 1 #define EMULATION_PAUSE 1
#define EMULATION_PREFERENCES 3 #define EMULATION_STATE 2
#define EMULATION_KEY_MAPPINGS 4 #define EMULATION_PREFERENCES 4
#define EMULATION_KEY_MAPPINGS 5
typedef unsigned char bool; typedef unsigned char bool;
#define true 1 #define true 1