X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fmain-mac.c;h=b278bc001c1598629f86a76343b8e1ceda20d2cf;hb=8a1422ffd9d4ab98d0a9ed846cb74011a7ec6264;hp=9bb974bf0b880425fb47dc9a6af4b1f0bc6597c3;hpb=978ee3dbb1204308e39392cd7ee8a2b188d31e65;p=hengband%2Fhengband.git diff --git a/src/main-mac.c b/src/main-mac.c index 9bb974bf0..b278bc001 100644 --- a/src/main-mac.c +++ b/src/main-mac.c @@ -154,6 +154,14 @@ #include #include #include +#if TARGET_API_MAC_CARBON +#include +#include +#include +# ifdef MAC_MPW +# include +# endif +#endif #ifdef JP @@ -176,6 +184,12 @@ /* #define USE_MALLOC */ +/* Default creator signature */ +#ifndef ANGBAND_CREATOR +# define ANGBAND_CREATOR 'Heng' +#endif + + #if defined(powerc) || defined(__powerc) /* @@ -224,11 +238,13 @@ /* * Globals for MPW compilation */ -#ifdef MAC_MPW +#if defined(MACH_O_CARBON) || defined(MAC_MPW) /* Globals needed */ +#if !TARGET_API_MAC_CARBON QDGlobals qd; - u32b _ftype; - u32b _fcreator; +#endif + OSType _ftype; + OSType _fcreator; #endif @@ -306,10 +322,6 @@ struct term_data #endif /* ANGBAND_LITE_MAC */ - GWorldPtr bufferPort; - PixMapHandle bufferPixHndl; - PixMapPtr bufferPix; - Str15 title; s16b oops; @@ -399,6 +411,10 @@ static term_data data[MAX_TERM_DATA]; */ static bool initialized = FALSE; +/* + * Version of Mac OS - for version specific bug workarounds (; ;) + */ +static long mac_os_version; /* @@ -500,8 +516,9 @@ static int soundchoice[] = { SND_TRAP, }; -static int soundmode[8]; +static short soundmode[8]; +static int ext_graf = 0; @@ -510,6 +527,55 @@ static int soundmode[8]; * Store this filename in 'buf' (make sure it is long enough) * Note that 'fname' looks to be a "pascal" string */ +#if TARGET_API_MAC_CARBON +static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname) +{ + CInfoPBRec pb; + Str255 name; + int err; + int i, j; + + char res[1000]; + + FSSpec spec; + short vref; + long dirID; + + i=999; + + res[i]=0; i--; + for (j=1; j<=fname[0]; j++) + { + res[i-fname[0]+j] = fname[j]; + } + i-=fname[0]; + + vref = vrefnum; + dirID = refnum; + + while (1) + { + pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID; + err = FSMakeFSSpec( vref, dirID, "\p", &spec ); + + if( err != noErr ) + break; + + res[i] = ':'; i--; + for (j=1; j<=spec.name[0]; j++) + { + res[i-spec.name[0]+j] = spec.name[j]; + } + i -= spec.name[0]; + + dirID = spec.parID; + } + + /* Extract the result */ + for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i]; + buf[j] = 0; +} +#else static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname) { DirInfo pb; @@ -552,7 +618,39 @@ static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname) for (j = 0, i++; res[i]; j++, i++) buf[j] = res[i]; buf[j] = 0; } +#endif +#if TARGET_API_MAC_CARBON +pascal OSErr FSpLocationFromFullPath(short fullPathLength, + const void *fullPath, + FSSpec *spec) +{ + AliasHandle alias; + OSErr result; + Boolean wasChanged; + Str32 nullString; + + /* Create a minimal alias from the full pathname */ + nullString[0] = 0; /* null string to indicate no zone or server name */ + result = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString, nullString, &alias); + if ( result == noErr ) + { + /* Let the Alias Manager resolve the alias. */ + result = ResolveAlias(NULL, alias, spec, &wasChanged); + + /* work around Alias Mgr sloppy volume matching bug */ + if ( spec->vRefNum == 0 ) + { + /* invalidate wrong FSSpec */ + spec->parID = 0; + spec->name[0] = 0; + result = nsvErr; + } + DisposeHandle((Handle)alias); /* Free up memory used */ + } + return ( result ); +} +#endif #if 0 @@ -598,7 +696,164 @@ static bool askfor_file(char *buf, int len) #endif +static void local_to_global( Rect *r ) +{ + Point temp; + + temp.h = r->left; + temp.v = r->top; + + LocalToGlobal( &temp ); + + r->left = temp.h; + r->top = temp.v; + + temp.h = r->right; + temp.v = r->bottom; + + LocalToGlobal( &temp ); + + r->right = temp.h; + r->bottom = temp.v; +} + +static void global_to_local( Rect *r ) +{ + Point temp; + + temp.h = r->left; + temp.v = r->top; + + GlobalToLocal( &temp ); + + r->left = temp.h; + r->top = temp.v; + + temp.h = r->right; + temp.v = r->bottom; + + GlobalToLocal( &temp ); + + r->right = temp.h; + r->bottom = temp.v; +} + + +#ifdef MAC_MPW + +/* + * Convert pathname to an appropriate format, because MPW's + * CarbonStdCLib chose to use system's native path format, + * making our lives harder to create binaries that run on + * OS 8/9 and OS X :( -- pelpel + */ +void convert_pathname(char* path) +{ + char buf[1024]; + + /* Nothing has to be done for CarbonLib on Classic */ + if (mac_os_version >= 0x1000) + { + /* Convert to POSIX style */ + ConvertHFSPathToUnixPath(path, buf); + + /* Copy the result back */ + strcpy(path, buf); + } + + /* Done. */ + return; +} + +# ifdef CHECK_MODIFICATION_TIME + +/* + * Although there is no easy way to emulate fstat in the old interface, + * we still can do stat-like things, because Mac OS is an OS. + */ +static int get_modification_time(cptr path, u32b *mod_time) +{ + CInfoPBRec pb; + Str255 pathname; + int i; + + /* Paranoia - make sure the pathname fits in Str255 */ + i = strlen(path); + if (i > 255) return (-1); + + /* Convert pathname to a Pascal string */ + strncpy((char *)pathname + 1, path, 255); + pathname[0] = i; + + /* Set up parameter block */ + pb.hFileInfo.ioNamePtr = pathname; + pb.hFileInfo.ioFDirIndex = 0; + pb.hFileInfo.ioVRefNum = app_vol; + pb.hFileInfo.ioDirID = 0; + + /* Get catalog information of the file */ + if (PBGetCatInfoSync(&pb) != noErr) return (-1); + + /* Set modification date and time */ + *mod_time = pb.hFileInfo.ioFlMdDat; + + /* Success */ + return (0); +} + + +/* + * A (non-Mach-O) Mac OS version of check_modification_time, for those + * compilers without good enough POSIX-compatibility libraries XXX XXX + */ +errr check_modification_date(int fd, cptr template_file) +{ +#pragma unused(fd) + u32b txt_stat, raw_stat; + char *p; + char fname[32]; + char buf[1024]; + + /* Build the file name */ + path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file); + + /* XXX XXX XXX */ + convert_pathname(buf); + + /* Obtain modification time */ + if (get_modification_time(buf, &txt_stat)) return (-1); + + /* XXX Build filename of the corresponding *.raw file */ + strnfmt(fname, sizeof(fname), "%s", template_file); + + /* Find last '.' */ + p = strrchr(fname, '.'); + + /* Can't happen */ + if (p == NULL) return (-1); + + /* Substitute ".raw" for ".txt" */ + strcpy(p, ".raw"); + + /* Build the file name of the raw file */ + path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, fname); + /* XXX XXX XXX */ + convert_pathname(buf); + + /* Obtain modification time */ + if (get_modification_time(buf, &raw_stat)) return (-1); + + /* Ensure the text file is not newer than the raw file */ + if (txt_stat > raw_stat) return (-1); + + /* Keep using the current .raw file */ + return (0); +} + +# endif /* CHECK_MODIFICATION_TIME */ + +#endif /* MAC_MPW */ /* * Center a rectangle inside another rectangle @@ -700,7 +955,54 @@ static void PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName) #endif +#if TARGET_API_MAC_CARBON + +static OSErr ChooseFile( StringPtr filename, FSSpec selfld ) +{ + NavReplyRecord reply; + NavDialogOptions dialogOptions; + NavTypeListHandle navTypeList = NULL; + OSErr err; + AEDesc deffld; + + AECreateDesc( typeFSS, &selfld, sizeof(FSSpec), &deffld ); + + err = NavGetDefaultDialogOptions( &dialogOptions ); + + if( err == noErr ){ + + err = NavChooseFile( &deffld, &reply, &dialogOptions, NULL, NULL, NULL, navTypeList, NULL ); + + if ( reply.validRecord && err == noErr ){ + // grab the target FSSpec from the AEDesc: + FSSpec finalFSSpec; + AEKeyword keyWord; + DescType typeCode; + Size actualSize = 0; + + // retrieve the returned selection: + // there is only one selection here we get only the first AEDescList: + if (( err = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyWord, &typeCode, &finalFSSpec, sizeof( FSSpec ), &actualSize )) == noErr ) + { + refnum_to_name( (char *)filename, finalFSSpec.parID, finalFSSpec.vRefNum, (char *)finalFSSpec.name ); + // 'finalFSSpec' is the chosen file¥Î + } + + err = NavDisposeReply( &reply ); + } + if( navTypeList != NULL ) + { + DisposeHandle( (Handle)navTypeList ); + navTypeList = NULL; + } + } + + AEDisposeDesc( &deffld ); + + return err; +} +#endif /* * Activate a given window, if necessary @@ -711,7 +1013,11 @@ static void activate(WindowPtr w) if (active != w) { /* Activate */ +#if TARGET_API_MAC_CARBON + if (w) SetPortWindowPort(w); +#else if (w) SetPort(w); +#endif /* Remember */ active = w; @@ -849,9 +1155,27 @@ static void term_data_check_font(term_data *td) */ static void term_data_check_size(term_data *td) { + BitMap screen; + +#if TARGET_API_MAC_CARBON + GetQDGlobalsScreenBits( &screen ); +#else + screen = qd.screenBits; +#endif /* Minimal window size */ - if (td->cols < 1) td->cols = 1; - if (td->rows < 1) td->rows = 1; + if (td == &data[0]) + { + /* Enforce minimal size */ + if (td->cols < 80) td->cols = 80; + if (td->rows < 24) td->rows = 24; + } + + /* Allow small windows for the rest */ + else + { + if (td->cols < 1) td->cols = 1; + if (td->rows < 1) td->rows = 1; + } /* Minimal tile size */ if (td->tile_wid < 4) td->tile_wid = 4; @@ -874,27 +1198,27 @@ static void term_data_check_size(term_data *td) td->size_hgt = td->rows * td->tile_hgt + td->size_oh1 + td->size_oh2; /* Verify the top */ - if (td->r.top > qd.screenBits.bounds.bottom - td->size_hgt) + if (td->r.top > screen.bounds.bottom - td->size_hgt) { - td->r.top = qd.screenBits.bounds.bottom - td->size_hgt; + td->r.top = screen.bounds.bottom - td->size_hgt; } /* Verify the top */ - if (td->r.top < qd.screenBits.bounds.top + 30) + if (td->r.top < screen.bounds.top + 30) { - td->r.top = qd.screenBits.bounds.top + 30; + td->r.top = screen.bounds.top + 30; } /* Verify the left */ - if (td->r.left > qd.screenBits.bounds.right - td->size_wid) + if (td->r.left > screen.bounds.right - td->size_wid) { - td->r.left = qd.screenBits.bounds.right - td->size_wid; + td->r.left = screen.bounds.right - td->size_wid; } /* Verify the left */ - if (td->r.left < qd.screenBits.bounds.left) + if (td->r.left < screen.bounds.left) { - td->r.left = qd.screenBits.bounds.left; + td->r.left = screen.bounds.left; } /* Calculate bottom right corner */ @@ -902,6 +1226,7 @@ static void term_data_check_size(term_data *td) td->r.bottom = td->r.top + td->size_hgt; /* Assume no graphics */ + td->t->higher_pict = FALSE; td->t->always_pict = FALSE; #ifdef ANGBAND_LITE_MAC @@ -911,9 +1236,13 @@ static void term_data_check_size(term_data *td) #else /* ANGBAND_LITE_MAC */ /* Handle graphics */ - if (use_graphics && (td == &data[0])) + if (use_graphics) { - td->t->always_pict = TRUE; + /* Use higher_pict whenever possible */ + if (td->font_mono) td->t->higher_pict = TRUE; + + /* Use always_pict only when necessary */ + else td->t->always_pict = TRUE; } #endif /* ANGBAND_LITE_MAC */ @@ -921,14 +1250,14 @@ static void term_data_check_size(term_data *td) /* Fake mono-space */ if (!td->font_mono || (td->font_wid != td->tile_wid) || - (td->font_hgt != td->tile_hgt)) + (td->font_hgt != td->tile_hgt)) { - /* Handle fake monospace */ + /* Handle fake monospace -- this is SLOW */ + if (td->t->higher_pict) td->t->higher_pict = FALSE; td->t->always_pict = TRUE; } } -static OSErr XDDSWUpDateGWorldFromPict( term_data *td ); /* * Hack -- resize a term_data * @@ -938,8 +1267,6 @@ static void term_data_resize(term_data *td) { /* Actually resize the window */ SizeWindow(td->w, td->size_wid, td->size_hgt, 0); - - XDDSWUpDateGWorldFromPict( td ); } @@ -964,9 +1291,19 @@ static void term_data_redraw(term_data *td) /* Restore the old term */ Term_activate(old); - + /* No need to redraw */ +#if TARGET_API_MAC_CARBON + { + RgnHandle theRgn = NewRgn(); + GetWindowRegion( td->w, kWindowContentRgn, theRgn ); + ValidWindowRgn( (WindowRef)(td->w), theRgn ); + DisposeRgn( theRgn ); + } +#else ValidRect(&td->w->portRect); +#endif + } @@ -983,12 +1320,13 @@ static void term_data_redraw(term_data *td) * Constants */ -#define kPictID 1001 /* Graf 'pict' resource */ - -#define kGrafWidth 8 /* Graf Size (X) */ -#define kGrafHeight 8 /* Graf Size (Y) */ +static int pictID = 1001; /* 8x8 tiles; 16x16 tiles are 1002 */ +static int grafWidth = 8; /* Always equal to grafHeight */ +static int grafHeight = 8; /* Either 8 or 16 */ +static bool arg_newstyle_graphics; +static bool use_newstyle_graphics; /* * Forward Declare @@ -1028,24 +1366,14 @@ static void BenSWLockFrame(FrameRec *srcFrameP) (void)LockPixels(pixMapH); HLockHi((Handle)pixMapH); srcFrameP->framePixHndl = pixMapH; +#if TARGET_API_MAC_CARBON + srcFrameP->framePix = (PixMapPtr)*(Handle)pixMapH; +#else srcFrameP->framePix = (PixMapPtr)StripAddress(*(Handle)pixMapH); +#endif } -/* - * Lock a frame - */ -static void XDDSWLockFrame( term_data *td ) -{ - PixMapHandle pixMapH; - - pixMapH = GetGWorldPixMap(td->bufferPort); - (void)LockPixels(pixMapH); - HLockHi((Handle)pixMapH); - td->bufferPixHndl = pixMapH; - td->bufferPix = (PixMapPtr)*(Handle)pixMapH; -} - /* * Unlock a frame @@ -1062,20 +1390,6 @@ static void BenSWUnlockFrame(FrameRec *srcFrameP) } -/* - * Unlock a frame - */ -static void XDDSWUnlockFrame( term_data *td ) -{ - if (td->bufferPort != NULL) - { - HUnlock((Handle)td->bufferPixHndl); - UnlockPixels(td->bufferPixHndl); - } - - td->bufferPix = NULL; -} - static OSErr BenSWCreateGWorldFromPict( GWorldPtr *pictGWorld, PicHandle pictH) @@ -1134,117 +1448,7 @@ static OSErr BenSWCreateGWorldFromPict( } -static OSErr XDDSWCreateGWorldFromPict( - GWorldPtr *pictGWorld, - term_data *td ) -{ - OSErr err; -/* GWorldPtr saveGWorld; - GDHandle saveGDevice;*/ - GWorldPtr tempGWorld; - Rect pictRect; -/* short depth; */ -/* GDHandle theGDH; */ - - tempGWorld = NULL; - - /* Reset */ - *pictGWorld = NULL; - - /* Get depth */ -/* depth = td->pixelDepth; */ - - /* Get GDH */ -/* theGDH = td->theGDH; */ - - /* Obtain size rectangle */ - pictRect.left = 0; - pictRect.right = td->size_wid; - pictRect.top = 0; - pictRect.bottom = td->tile_hgt; - - /* Create a GWorld */ - err = NewGWorld(&tempGWorld, 0, &pictRect, 0, 0, 0); - - /* Success */ - if (err != noErr) - { - return (err); - } - - /* Save pointer */ - *pictGWorld = tempGWorld; - - /* Save GWorld */ -/* GetGWorld(&saveGWorld, &saveGDevice); */ - - /* Activate */ -/* SetGWorld(tempGWorld, nil); */ - - /* Dump the pict into the GWorld */ -/* (void)LockPixels(GetGWorldPixMap(tempGWorld)); */ -/* EraseRect(&pictRect); */ -/* DrawPicture(pictH, &pictRect); */ -/* UnlockPixels(GetGWorldPixMap(tempGWorld)); */ - - /* Restore GWorld */ -/* SetGWorld(saveGWorld, saveGDevice); */ - - return (0); -} - - -static OSErr XDDSWUpDateGWorldFromPict( term_data *td ) -{ -/* GWorldPtr saveGWorld; */ -/* GDHandle saveGDevice; */ - Rect pictRect; -/* short depth; */ -/* GDHandle theGDH; */ - - GWorldFlags errflag; - - /* */ - - if( td->bufferPort == NULL ) - return; - /* Get depth */ -/* depth = td->pixelDepth; */ - - /* Get GDH */ -/* theGDH = td->theGDH; */ - - /* Obtain size rectangle */ - pictRect.top = 0; - pictRect.left = 0; - pictRect.right = td->size_wid; - pictRect.bottom = td->tile_hgt; - - XDDSWUnlockFrame(td); - - errflag = UpdateGWorld( &td->bufferPort, 0, &pictRect, 0, 0, 0); - XDDSWLockFrame(td); - if( errflag & gwFlagErr ){ - //SysBeep(0); - return; - } - - /* Save GWorld */ -/* GetGWorld(&saveGWorld, &saveGDevice); */ - - /* Activate */ -/* SetGWorld(td->bufferPort, nil); */ - - /* Dump the pict into the GWorld */ -/* (void)LockPixels(GetGWorldPixMap(td->bufferPort)); */ -/* EraseRect(&td->bufferPort->portRect); */ - -/* UnlockPixels(GetGWorldPixMap(td->bufferPort)); */ - /* Restore GWorld */ -/* SetGWorld(saveGWorld, saveGDevice); */ - -} /* * Init the global "frameP" @@ -1259,11 +1463,15 @@ static errr globe_init(void) PicHandle newPictH; /* Use window XXX XXX XXX */ +#if TARGET_API_MAC_CARBON + SetPortWindowPort(data[0].w); +#else SetPort(data[0].w); +#endif /* Get the pict resource */ - newPictH = GetPicture(kPictID); + newPictH = GetPicture(pictID); /* Analyze result */ err = (newPictH ? 0 : -1); @@ -1402,12 +1610,13 @@ static void Term_init_mac(term *t) PixMapHandle basePixMap; /* Obtain the rect */ - tempRect = td->w->portRect; - - /* Obtain the global rect */ - globalRect = tempRect; +#if TARGET_API_MAC_CARBON + GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &globalRect ); +#else + globalRect = td->w->portRect; LocalToGlobal((Point*)&globalRect.top); LocalToGlobal((Point*)&globalRect.bottom); +#endif /* Obtain the proper GDH */ mainGDH = GetMaxDevice(&globalRect); @@ -1433,26 +1642,37 @@ static void Term_init_mac(term *t) #endif /* ANGBAND_LITE_MAC */ - /* Clip to the window */ - ClipRect(&td->w->portRect); + { + Rect portRect; - /* Erase the window */ - EraseRect(&td->w->portRect); +#if TARGET_API_MAC_CARBON + GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect ); + global_to_local( &portRect ); +#else + portRect = td->w->portRect; +#endif + /* Clip to the window */ + ClipRect(&portRect); - /* Invalidate the window */ - InvalRect(&td->w->portRect); + /* Erase the window */ + EraseRect(&portRect); - /* Display the window if needed */ - if (td->mapped) ShowWindow(td->w); + /* Invalidate the window */ +#if TARGET_API_MAC_CARBON + InvalWindowRect((WindowRef)(td->w), (const Rect *)(&portRect)); +#else + InvalRect(&portRect); +#endif - /* Hack -- set "mapped" flag */ - t->mapped_flag = td->mapped; + /* Display the window if needed */ + if (td->mapped) ShowWindow(td->w); - /* Forget color */ - td->last = -1; - XDDSWCreateGWorldFromPict( &td->bufferPort, td ); - - XDDSWLockFrame( td ); + /* Hack -- set "mapped" flag */ + t->mapped_flag = td->mapped; + + /* Forget color */ + td->last = -1; + } /* Oops */ /* if (err == noErr) { @@ -1513,18 +1733,44 @@ static errr Term_xtra_mac_react(void) use_sound = arg_sound; } + + /* Handle transparency */ + if (use_newstyle_graphics != arg_newstyle_graphics) + { + globe_nuke(); + + if (globe_init() != 0) + { + plog("Cannot initialize graphics!"); + arg_graphics = FALSE; + arg_newstyle_graphics = FALSE; + } + + /* Apply request */ + use_newstyle_graphics = arg_newstyle_graphics; + + /* Apply and Verify */ + term_data_check_size(td); + + /* Resize the window */ + term_data_resize(td); + + /* Reset visuals */ + reset_visuals(); + } + /* Handle graphics */ - if ((td == &data[0]) && (use_graphics != arg_graphics)) + if (use_graphics != arg_graphics) { /* Initialize graphics */ if (!use_graphics && !frameP && (globe_init() != 0)) { - #ifdef JP +#ifdef JP plog("¥°¥é¥Õ¥£¥Ã¥¯¤Î½é´ü²½¤Ï½ÐÍè¤Þ¤»¤ó¤Ç¤·¤¿."); - #else +#else plog("Cannot initialize graphics!"); - #endif +#endif arg_graphics = FALSE; } @@ -1629,7 +1875,7 @@ static errr Term_xtra_mac(int n, int v) case TERM_XTRA_BORED: { /* Process an event */ - (void)CheckEvents(0); + (void)CheckEvents(FALSE); /* Success */ return (0); @@ -1668,11 +1914,20 @@ static errr Term_xtra_mac(int n, int v) /* Clear the screen */ case TERM_XTRA_CLEAR: { + Rect portRect; + +#if TARGET_API_MAC_CARBON + GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect ); + global_to_local( &portRect ); +#else + portRect = td->w->portRect; +#endif + /* No clipping XXX XXX XXX */ - ClipRect(&td->w->portRect); + ClipRect(&portRect); /* Erase the window */ - EraseRect(&td->w->portRect); + EraseRect(&portRect); /* Set the color */ term_data_color(td, TERM_WHITE); @@ -1684,10 +1939,10 @@ static errr Term_xtra_mac(int n, int v) LineTo(td->size_wid-1, 0); /* Clip to the new size */ - r.left = td->w->portRect.left + td->size_ow1; - r.top = td->w->portRect.top + td->size_oh1; - r.right = td->w->portRect.right - td->size_ow2; - r.bottom = td->w->portRect.bottom - td->size_oh2; + r.left = portRect.left + td->size_ow1; + r.top = portRect.top + td->size_oh1; + r.right = portRect.right - td->size_ow2; + r.bottom = portRect.bottom - td->size_oh2; ClipRect(&r); /* Success */ @@ -1707,10 +1962,27 @@ static errr Term_xtra_mac(int n, int v) /* If needed */ if (v > 0) { +#if TARGET_API_MAC_CARBON + EventRecord tmp; + UInt32 ticks; + + /* Convert millisecs to ticks */ + ticks = (v * 60L) / 1000; + + /* + * Hack? - Put the programme into sleep. + * No events match ~everyEvent, so nothing + * should be lost in Angband's event queue. + * Even if ticks are 0, it's worth calling for + * the above mentioned reasons. + */ + WaitNextEvent(~everyEvent, &tmp, ticks, nil); +#else long m = TickCount() + (v * 60L) / 1000; /* Wait for it */ while (TickCount() < m) /* loop */; +#endif } /* Success */ @@ -1744,6 +2016,35 @@ static errr Term_curs_mac(int x, int y) r.right = r.left + td->tile_wid; r.top = y * td->tile_hgt + td->size_oh1; r.bottom = r.top + td->tile_hgt; + + FrameRect(&r); + + /* Success */ + return (0); +} + + +/* + * Low level graphics (Assumes valid input). + * Draw a "big cursor" at (x,y), using a "yellow box". + * We are allowed to use "Term_grab()" to determine + * the current screen contents (for inverting, etc). + */ +static errr Term_bigcurs_mac(int x, int y) +{ + Rect r; + + term_data *td = (term_data*)(Term->data); + + /* Set the color */ + term_data_color(td, TERM_YELLOW); + + /* Frame the grid */ + r.left = x * td->tile_wid + td->size_ow1; + r.right = r.left + 2 * td->tile_wid; + r.top = y * td->tile_hgt + td->size_oh1; + r.bottom = r.top + td->tile_hgt; + FrameRect(&r); /* Success */ @@ -1811,34 +2112,27 @@ static errr Term_text_mac(int x, int y, int n, byte a, const char *cp) * * Erase "n" characters starting at (x,y) */ -static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp) +static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp, + const byte *tap, const char *tcp) { int i; Rect r2; - bool use_buffer = false; term_data *td = (term_data*)(Term->data); GDHandle saveGDevice; GWorldPtr saveGWorld; PixMapHandle PortPix; - /* Save GWorld */ GetGWorld(&saveGWorld, &saveGDevice); - if( n > 0 ) - { - /* Destination rectangle */ - r2.left = x * td->tile_wid + td->size_ow1; - r2.right = r2.left + td->tile_wid; - r2.top = 0; - r2.bottom = r2.top + td->tile_hgt; + r2.left = x * td->tile_wid + td->size_ow1; + r2.right = r2.left + td->tile_wid; + r2.top = y * td->tile_hgt + td->size_oh1; + r2.bottom = r2.top + td->tile_hgt; - /* Activate */ - SetGWorld(td->bufferPort, nil); - PortPix = GetGWorldPixMap(td->bufferPort ); - LockPixels( PortPix ); - + if( n > 1 ) + { /* Instantiate font */ TextFont(td->font_id); TextSize(td->font_size); @@ -1847,23 +2141,14 @@ static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp) /* Restore colors */ BackColor(blackColor); ForeColor(whiteColor); - - /* Erase */ - EraseRect(&td->bufferPort->portRect); - - use_buffer = true; } else { /* Destination rectangle */ - r2.left = x * td->tile_wid + td->size_ow1; - r2.right = r2.left + td->tile_wid; +/* r2.left = x * td->tile_wid + td->size_ow1; r2.top = y * td->tile_hgt + td->size_oh1; - r2.bottom = r2.top + td->tile_hgt; - - /* no buffering, so we use the normal current port */ + r2.bottom = r2.top + td->tile_hgt;*/ - use_buffer = false; } /* Scan the input */ @@ -1874,52 +2159,120 @@ static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp) byte a = ap[i]; char c = cp[i]; + /* Second byte of bigtile */ + if (use_bigtile && a == 255) + { + /* Advance */ + r2.left += td->tile_wid; + + continue; + } + + /* Prepare right of rectangle now */ + r2.right = r2.left + td->tile_wid; + #ifdef ANGBAND_LITE_MAC - /* Nothing */ + /* No graphics */ #else /* ANGBAND_LITE_MAC */ /* Graphics -- if Available and Needed */ - if (use_graphics && ((td == &data[0]) || (td == &data[6])) && - ((byte)a & 0x80) && ((byte)c & 0x80)) + if (use_graphics && ((byte)a & 0x80) && ((byte)c & 0x80)) { +#if TARGET_API_MAC_CARBON + PixMapHandle srcBitMap = GetGWorldPixMap(frameP->framePort); + PixMapHandle destBitMap; +#else + BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix); + BitMapPtr destBitMap; +#endif + int col, row; Rect r1; + Rect terrain_r; + bool terrain_flag = FALSE; + byte ta = tap[i]; + char tc = tcp[i]; + + if ((a != ta || c != tc) && + ((byte)ta & 0x80) && ((byte)tc & 0x80)) + { + /* Row and Col */ + row = ((byte)ta & 0x7F); + col = ((byte)tc & 0x7F); + + /* Terrain Source rectangle */ + terrain_r.left = col * grafWidth; + terrain_r.top = row * grafHeight; + terrain_r.right = terrain_r.left + grafWidth; + terrain_r.bottom = terrain_r.top + grafHeight; + + terrain_flag = TRUE; + } + /* Row and Col */ row = ((byte)a & 0x7F); col = ((byte)c & 0x7F); /* Source rectangle */ - r1.left = col * kGrafWidth; - r1.top = row * kGrafHeight; - r1.right = r1.left + kGrafWidth; - r1.bottom = r1.top + kGrafHeight; + r1.left = col * grafWidth; + r1.top = row * grafHeight; + r1.right = r1.left + grafWidth; + r1.bottom = r1.top + grafHeight; /* Hardwire CopyBits */ BackColor(whiteColor); ForeColor(blackColor); /* Draw the picture */ +#if TARGET_API_MAC_CARBON + destBitMap = GetPortPixMap(GetWindowPort( td->w )); +#else + destBitMap = (BitMapPtr)&(td->w->portBits); +#endif + if (use_bigtile) r2.right += td->tile_wid; + + if (terrain_flag) { - BitMapPtr srcBitMap = (BitMapPtr)(frameP->framePix); - BitMapPtr destBitMap; - - if( use_buffer ) - { - destBitMap = (BitMapPtr)(td->bufferPix); - } - else - { - destBitMap = (BitMapPtr)&(td->w->portBits); - } - - /* draw transparent tile */ - /* BackColor is ignored and the destination is left untouched */ + /* + * Source mode const = srcCopy: + * + * determine how close the color of the source + * pixel is to black, and assign this relative + * amount of foreground color to the + * destination pixel; determine how close the + * color of the source pixel is to white, and + * assign this relative amount of background + * color to the destination pixel + */ +#if TARGET_API_MAC_CARBON + CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &terrain_r, &r2, srcCopy, NULL); +#else + CopyBits( srcBitMap, destBitMap, &terrain_r, &r2, srcCopy, NULL ); +#endif + /* + * Draw transparent tile + * BackColor is ignored and the destination is + * left untouched + */ BackColor(blackColor); +#if TARGET_API_MAC_CARBON + CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, transparent, NULL); +#else CopyBits( srcBitMap, destBitMap, &r1, &r2, transparent, NULL ); +#endif } + else + { +#if TARGET_API_MAC_CARBON + CopyBits( (BitMap *) *srcBitMap, (BitMap *) *destBitMap, &r1, &r2, srcCopy, NULL); +#else + CopyBits( srcBitMap, destBitMap, &r1, &r2, srcCopy, NULL ); +#endif + } + /* Restore colors */ BackColor(blackColor); ForeColor(whiteColor); @@ -1937,101 +2290,53 @@ static errr Term_pict_mac(int x, int y, int n, const byte *ap, const char *cp) if (!done) { int xp, yp; -#ifndef JP - /* Erase */ - EraseRect(&r2); /* Set the color */ term_data_color(td, (a & 0x0F)); - - /* Starting pixel */ - xp = r2.left + td->tile_o_x; - yp = r2.top + td->tile_o_y; - - /* Move to the correct location */ - MoveTo(xp, yp); - - /* Draw the character */ - DrawChar(c); -#else - /* Set the color */ - term_data_color(td, (a & 0x0F)); /* Starting pixel */ xp = r2.left + td->tile_o_x; - yp = td->tile_o_y; + yp = r2.top + td->tile_o_y; /* Move to the correct location */ MoveTo(xp, yp); - if(iskanji(c)){ +#ifdef JP + if (iskanji(c)) + { + /* Double width rectangle */ + r2.right += td->tile_wid; + + /* Erase */ + EraseRect(&r2); + /* Draw the character */ DrawText(cp, i, 2); i++; r2.left += td->tile_wid; - r2.right += td->tile_wid; - } else { + } + else +#endif + { + /* Erase */ + EraseRect(&r2); + /* Draw the character */ DrawChar(c); } -#endif } /* Advance */ r2.left += td->tile_wid; - r2.right += td->tile_wid; } - - if( use_buffer ) - { - /* Now we blast the buffer pixmap onto the screen in the right place */ - BitMapPtr srcBitMap = (BitMapPtr)(td->bufferPix); - - BitMapPtr destBitMap = (BitMapPtr)&(td->w->portBits); - - Rect srcRect; - Rect destRect; - - - srcRect.left = x * td->tile_wid + td->size_ow1; - srcRect.top = 0; - srcRect.right = srcRect.left + (td->tile_wid * n); - srcRect.bottom = td->tile_hgt; - destRect.left = x * td->tile_wid + td->size_ow1; - destRect.right = destRect.left + (td->tile_wid * n); - destRect.top = y * td->tile_hgt + td->size_oh1; - destRect.bottom = destRect.top + td->tile_hgt; - - UnlockPixels( PortPix ); - - /* Restore GWorld */ - SetGWorld(saveGWorld, saveGDevice); - - /* Hardwire CopyBits */ - BackColor(whiteColor); - ForeColor(blackColor); - - //CopyBits( srcBitMap, destBitMap, &srcRect, &destRect, srcCopy, NULL ); - CopyBits( (BitMapPtr)(td->bufferPix) - , &(td->w->portBits), &srcRect, &destRect, srcCopy, NULL ); - - /* Restore colors */ - BackColor(blackColor); - ForeColor(whiteColor); - } - /* Success */ return (0); } - - - - /* * Create and initialize window number "i" */ @@ -2069,6 +2374,7 @@ static void term_data_link(int i) td->t->xtra_hook = Term_xtra_mac; td->t->wipe_hook = Term_wipe_mac; td->t->curs_hook = Term_curs_mac; + td->t->bigcurs_hook = Term_bigcurs_mac; td->t->text_hook = Term_text_mac; td->t->pict_hook = Term_pict_mac; @@ -2102,45 +2408,338 @@ static void SetupAppDir(void) OSErr err = noErr; char errString[100]; - /* Get the location of the Angband executable */ - fcbBlock.ioCompletion = NULL; - fcbBlock.ioNamePtr = NULL; - fcbBlock.ioVRefNum = 0; - fcbBlock.ioRefNum = CurResFile(); - fcbBlock.ioFCBIndx = 0; - err = PBGetFCBInfo(&fcbBlock, FALSE); - if (err != noErr) + /* Get the location of the Angband executable */ + fcbBlock.ioCompletion = NULL; + fcbBlock.ioNamePtr = NULL; + fcbBlock.ioVRefNum = 0; + fcbBlock.ioRefNum = CurResFile(); + fcbBlock.ioFCBIndx = 0; + err = PBGetFCBInfo(&fcbBlock, FALSE); + if (err != noErr) + { +#ifdef JP + sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err); +#else + sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err); +#endif + mac_warning(errString); + ExitToShell(); + } + + /* Extract the Vol and Dir */ + app_vol = fcbBlock.ioFCBVRefNum; + app_dir = fcbBlock.ioFCBParID; + + /* Set the current working directory to that location */ + err = HSetVol(NULL, app_vol, app_dir); + if (err != noErr) + { +#ifdef JP + sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err); +#else + sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err); +#endif + mac_warning(errString); + ExitToShell(); + } +} + + + +#if TARGET_API_MAC_CARBON +/* + * Using Core Foundation's Preferences services -- pelpel + * + * Requires OS 8.6 or greater with CarbonLib 1.1 or greater. Or OS X, + * of course. + * + * Without this, we can support older versions of OS 8 as well + * (with CarbonLib 1.0.4). + * + * Frequent allocation/deallocation of small chunks of data is + * far from my liking, but since this is only called at the + * beginning and the end of a session, I hope this hardly matters. + */ + + +/* + * Store "value" as the value for preferences item name + * pointed by key + */ +static void save_pref_short(const char *key, short value) +{ + CFStringRef cf_key; + CFNumberRef cf_value; + + /* allocate and initialise the key */ + cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII); + + /* allocate and initialise the value */ + cf_value = CFNumberCreate(NULL, kCFNumberShortType, &value); + + if ((cf_key != NULL) && (cf_value != NULL)) + { + /* Store the key-value pair in the applications preferences */ + CFPreferencesSetAppValue( + cf_key, + cf_value, + kCFPreferencesCurrentApplication); + } + + /* + * Free CF data - the reverse order is a vain attempt to + * minimise memory fragmentation. + */ + if (cf_value) CFRelease(cf_value); + if (cf_key) CFRelease(cf_key); +} + + +/* + * Load preference value for key, returns TRUE if it succeeds with + * vptr updated appropriately, FALSE otherwise. + */ +static bool query_load_pref_short(const char *key, short *vptr) +{ + CFStringRef cf_key; + CFNumberRef cf_value; + + /* allocate and initialise the key */ + cf_key = CFStringCreateWithCString(NULL, key, kTextEncodingUS_ASCII); + + /* Oops */ + if (cf_key == NULL) return (FALSE); + + /* Retrieve value for the key */ + cf_value = CFPreferencesCopyAppValue( + cf_key, + kCFPreferencesCurrentApplication); + + /* Value not found */ + if (cf_value == NULL) + { + CFRelease(cf_key); + return (FALSE); + } + + /* Convert the value to short */ + CFNumberGetValue( + cf_value, + kCFNumberShortType, + vptr); + + /* Free CF data */ + CFRelease(cf_value); + CFRelease(cf_key); + + /* Success */ + return (TRUE); +} + + +/* + * Update short data pointed by vptr only if preferences + * value for key is located. + */ +static void load_pref_short(const char *key, short *vptr) +{ + short tmp; + + if (query_load_pref_short(key, &tmp)) *vptr = tmp; + return; +} + + +/* + * Save preferences to preferences file for current host+current user+ + * current application. + */ +static void cf_save_prefs() +{ + int i; + + /* Version stamp */ + save_pref_short("version.major", FAKE_VERSION); + save_pref_short("version.minor", FAKE_VER_MAJOR); + save_pref_short("version.patch", FAKE_VER_MINOR); + save_pref_short("version.extra", FAKE_VER_PATCH); + + /* Gfx settings */ + save_pref_short("arg.arg_sound", arg_sound); + save_pref_short("arg.arg_graphics", arg_graphics); + save_pref_short("arg.arg_newstyle_graphics", arg_newstyle_graphics); + save_pref_short("arg.arg_bigtile", arg_bigtile); + + /* SoundMode */ + for( i = 0 ; i < 7 ; i++ ) + save_pref_short(format("sound%d.on", i), soundmode[i]); + + /* Windows */ + for (i = 0; i < MAX_TERM_DATA; i++) + { + term_data *td = &data[i]; + + save_pref_short(format("term%d.mapped", i), td->mapped); + + save_pref_short(format("term%d.font_id", i), td->font_id); + save_pref_short(format("term%d.font_size", i), td->font_size); + save_pref_short(format("term%d.font_face", i), td->font_face); + + save_pref_short(format("term%d.tile_wid", i), td->tile_wid); + save_pref_short(format("term%d.tile_hgt", i), td->tile_hgt); + + save_pref_short(format("term%d.cols", i), td->cols); + save_pref_short(format("term%d.rows", i), td->rows); + save_pref_short(format("term%d.left", i), td->r.left); + save_pref_short(format("term%d.top", i), td->r.top); + } + + /* + * Make sure preferences are persistent + */ + CFPreferencesAppSynchronize( + kCFPreferencesCurrentApplication); +} + + +/* + * Load preferences from preferences file for current host+current user+ + * current application. + */ +static void cf_load_prefs() +{ + bool ok; + short pref_major, pref_minor, pref_patch, pref_extra; + int i; + + MenuHandle m; + + /* Assume nothing is wrong, yet */ + ok = TRUE; + + /* Load version information */ + ok &= query_load_pref_short("version.major", &pref_major); + ok &= query_load_pref_short("version.minor", &pref_minor); + ok &= query_load_pref_short("version.patch", &pref_patch); + ok &= query_load_pref_short("version.extra", &pref_extra); + + /* Any of the above failed */ + if (!ok) + { + /* This may be the first run */ +#ifdef JP + mac_warning("½é´üÀßÄê¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£"); +#else + mac_warning("Preferences are not found."); +#endif + + /* Ignore the rest */ + return; + } + +#if 0 + + /* Check version */ + if ((pref_major != PREF_VER_MAJOR) || + (pref_minor != PREF_VER_MINOR) || + (pref_patch != PREF_VER_PATCH) || + (pref_extra != PREF_VER_EXTRA)) + { + /* Message */ + mac_warning( + format("Ignoring %d.%d.%d.%d preferences.", + pref_major, pref_minor, pref_patch, pref_extra)); + + /* Ignore */ + return; + } + +#endif + + /* Gfx settings */ + { + short pref_tmp; + + /* sound */ + if (query_load_pref_short("arg.arg_sound", &pref_tmp)) + arg_sound = pref_tmp; + + /* graphics */ + if (query_load_pref_short("arg.arg_graphics", &pref_tmp)) + arg_graphics = pref_tmp; + + /*newstyle graphics*/ + if (query_load_pref_short("arg.arg_newstyle_graphics", &pref_tmp)) + { + use_newstyle_graphics = pref_tmp; + } + + if (use_newstyle_graphics == true) + { + ANGBAND_GRAF = "new"; + arg_newstyle_graphics = true; + grafWidth = grafHeight = 16; + pictID = 1002; + } + else + { + ANGBAND_GRAF = "old"; + arg_newstyle_graphics = false; + grafWidth = grafHeight = 8; + pictID = 1001; + } + + /* double-width tiles */ + if (query_load_pref_short("arg.arg_bigtile", &pref_tmp)) + { + use_bigtile = pref_tmp; + } + + } + + /* SoundMode */ + for( i = 0 ; i < 7 ; i++ ) { -#ifdef JP - sprintf(errString, "PBGetFCBInfo ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err); -#else - sprintf(errString, "Fatal PBGetFCBInfo Error #%d.\r Exiting.", err); -#endif - mac_warning(errString); - ExitToShell(); + query_load_pref_short(format("sound%d.on", i), &soundmode[i]); } - /* Extract the Vol and Dir */ - app_vol = fcbBlock.ioFCBVRefNum; - app_dir = fcbBlock.ioFCBParID; + /* Special menu */ + m = GetMenuHandle(134); - /* Set the current working directory to that location */ - err = HSetVol(NULL, app_vol, app_dir); - if (err != noErr) + /* Item "arg_sound" */ + CheckMenuItem(m, 1, arg_sound); + + /* Item "arg_graphics" */ + CheckMenuItem(m, 2, arg_graphics); + + /* Item "arg_newstyle_graphics"*/ + CheckMenuItem(m, 8, arg_newstyle_graphics); + + /* Item "arg_bigtile"*/ + CheckMenuItem(m, 9, arg_bigtile); + + /* Windows */ + for (i = 0; i < MAX_TERM_DATA; i++) { -#ifdef JP - sprintf(errString, "HSetVol ¥¨¥é¡¼ #%d.\r ½ªÎ»¤·¤Þ¤¹.", err); -#else - sprintf(errString, "Fatal HSetVol Error #%d.\r Exiting.", err); -#endif - mac_warning(errString); - ExitToShell(); - } -} + term_data *td = &data[i]; + + load_pref_short(format("term%d.mapped", i), &td->mapped); + load_pref_short(format("term%d.font_id", i), &td->font_id); + load_pref_short(format("term%d.font_size", i), &td->font_size); + load_pref_short(format("term%d.font_face", i), &td->font_face); + load_pref_short(format("term%d.tile_wid", i), &td->tile_wid); + load_pref_short(format("term%d.tile_hgt", i), &td->tile_hgt); + load_pref_short(format("term%d.cols", i), &td->cols); + load_pref_short(format("term%d.rows", i), &td->rows); + load_pref_short(format("term%d.left", i), &td->r.left); + load_pref_short(format("term%d.top", i), &td->r.top); + } +} +#else /* * Global "preference" file pointer */ @@ -2153,7 +2752,7 @@ static int getshort(void) { int x = 0; char buf[256]; - if (0 == my_fgets(fff, buf, 256)) x = atoi(buf); + if (0 == my_fgets(fff, buf, sizeof(buf))) x = atoi(buf); return (x); } @@ -2179,13 +2778,15 @@ static void save_prefs(void) /*** The current version ***/ - putshort(VERSION_MAJOR); - putshort(VERSION_MINOR); - putshort(VERSION_PATCH); - putshort(VERSION_EXTRA); + putshort(FAKE_VERSION); + putshort(FAKE_VER_MAJOR); + putshort(FAKE_VER_MINOR); + putshort(FAKE_VER_PATCH); putshort(arg_sound); putshort(arg_graphics); + putshort(arg_newstyle_graphics); + putshort(arg_bigtile); /* SoundMode */ for( i = 0 ; i < 7 ; i++ ) @@ -2225,7 +2826,7 @@ static void load_prefs(void) { int i; - int old_major, old_minor, old_patch, old_extra; + int old_version, old_major, old_minor, old_patch; term_data *td; MenuHandle m; @@ -2233,16 +2834,16 @@ static void load_prefs(void) /*** Version information ***/ /* Preferences version */ + old_version = getshort(); old_major = getshort(); old_minor = getshort(); old_patch = getshort(); - old_extra = getshort(); /* Hack -- Verify or ignore */ - if ((old_major != VERSION_MAJOR) || - (old_minor != VERSION_MINOR) || - (old_patch != VERSION_PATCH) || - (old_extra != VERSION_EXTRA)) + if ((old_version != FAKE_VERSION) || + (old_major != FAKE_VER_MAJOR) || + (old_minor != FAKE_VER_MINOR) || + (old_patch != FAKE_VER_PATCH)) { /* Message */ #ifdef JP @@ -2256,19 +2857,45 @@ static void load_prefs(void) arg_sound = getshort(); arg_graphics = getshort(); + arg_newstyle_graphics = getshort(); + use_newstyle_graphics = arg_newstyle_graphics; + + if (use_newstyle_graphics == true) + { + ANGBAND_GRAF = "new"; + arg_newstyle_graphics = true; + grafWidth = grafHeight = 16; + pictID = 1002; + } + else + { + ANGBAND_GRAF = "old"; + arg_newstyle_graphics = false; + grafWidth = grafHeight = 8; + pictID = 1001; + } + + arg_bigtile = getshort(); + use_bigtile = arg_bigtile; /* SoundMode */ for( i = 0 ; i < 7 ; i++ ) soundmode[i] = getshort(); /* Special menu */ - m = GetMenuHandle(134); //m = GetMHandle(134); - + m = GetMenuHandle(134); + /* Item "arg_sound" */ CheckItem(m, 1, arg_sound); /* Item "arg_graphics" */ CheckItem(m, 2, arg_graphics); + + /* Item "arg_newstyle_graphics"*/ + CheckItem(m, 8, arg_newstyle_graphics); + + /* Item "arg_bigtile"*/ + CheckItem(m, 9, arg_bigtile); /* Windows */ for (i = 0; i < MAX_TERM_DATA; i++) @@ -2295,7 +2922,7 @@ static void load_prefs(void) if (feof(fff)) break; } } - +#endif /* TARGET_API_MAC_CARBON */ @@ -2306,13 +2933,25 @@ static void term_data_hack(term_data *td) { short fid; - #ifdef JP - GetFNum( "\pÅùÉýÌÀÄ«", &fid); /* ¥Õ¥©¥ó¥È̾¤«¤éIDÈÖ¹æ¤òÄ´¤Ù¤ë */ +#if TARGET_API_MAC_CARBON +#ifdef JP + /* Default to Osaka font (Japanese) */ + fid = FMGetFontFamilyFromName( "\pOsaka¡ÝÅùÉý" ); +#else + /* Default to Monaco font */ + fid = FMGetFontFamilyFromName("\pmonaco"); +#endif +#else +#ifdef JP + /* Default to ÅùÉýÌÀÄ« font (Japanese) */ + GetFNum( "\pÅùÉýÌÀÄ«", &fid); SetFScaleDisable( true ); - #else +#else /* Default to Monaco font */ GetFNum("\pmonaco", &fid); - #endif +#endif +#endif + /* Wipe it */ WIPE(td, term_data); @@ -2409,7 +3048,10 @@ static void init_windows(void) /*** Load preferences ***/ - + +#if TARGET_API_MAC_CARBON + cf_load_prefs(); +#else /* Assume failure */ oops = TRUE; @@ -2428,7 +3070,7 @@ static void init_windows(void) /* Find the folder */ err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder, - &vref, &dirID); + &vref, &dirID); /* Success */ if (!err) @@ -2478,6 +3120,7 @@ static void init_windows(void) /* Close the file */ my_fclose(fff); } +#endif /* TARGET_API_MAC_CARBON */ /*** Instantiate ***/ @@ -2507,7 +3150,7 @@ static void init_windows(void) static void init_sound( void ) { int err, i; - DirInfo pb; + CInfoPBRec pb; SignedByte permission = fsRdPerm; pascal short ret; @@ -2515,45 +3158,45 @@ static void init_sound( void ) Str255 sound; /* Descend into "lib" folder */ - pb.ioCompletion = NULL; - pb.ioNamePtr = "\plib"; - pb.ioVRefNum = app_vol; - pb.ioDrDirID = app_dir; - pb.ioFDirIndex = 0; + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\plib"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = app_dir; + pb.dirInfo.ioFDirIndex = 0; /* Check for errors */ err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); /* Success */ - if ((err == noErr) && (pb.ioFlAttrib & 0x10)) + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) { /* Descend into "lib/save" folder */ - pb.ioCompletion = NULL; - pb.ioNamePtr = "\pxtra"; - pb.ioVRefNum = app_vol; - pb.ioDrDirID = pb.ioDrDirID; - pb.ioFDirIndex = 0; + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\pxtra"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID; + pb.dirInfo.ioFDirIndex = 0; /* Check for errors */ err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); /* Success */ - if ((err == noErr) && (pb.ioFlAttrib & 0x10)) + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) { /* Descend into "lib/save" folder */ - pb.ioCompletion = NULL; - pb.ioNamePtr = "\psound"; - pb.ioVRefNum = app_vol; - pb.ioDrDirID = pb.ioDrDirID; - pb.ioFDirIndex = 0; + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\psound"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID; + pb.dirInfo.ioFDirIndex = 0; /* Check for errors */ err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); /* Success */ - if ((err == noErr) && (pb.ioFlAttrib & 0x10)) + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) { - ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission ); + ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\psound.rsrc" , permission ); if( ret != -1 ){ ext_sound = 1; @@ -2580,6 +3223,70 @@ static void init_sound( void ) } } +static void init_graf( void ) +{ + int err, i; + CInfoPBRec pb; + SignedByte permission = fsRdPerm; + pascal short ret; + + Handle handle; + Str255 graf; + + /* Descend into "lib" folder */ + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\plib"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = app_dir; + pb.dirInfo.ioFDirIndex = 0; + + /* Check for errors */ + err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); + + /* Success */ + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) + { + /* Descend into "lib/xtra" folder */ + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\pxtra"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID; + pb.dirInfo.ioFDirIndex = 0; + + /* Check for errors */ + err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); + + /* Success */ + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) + { + /* Descend into "lib/xtra/graf" folder */ + pb.dirInfo.ioCompletion = NULL; + pb.dirInfo.ioNamePtr = "\pgraf"; + pb.dirInfo.ioVRefNum = app_vol; + pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID; + pb.dirInfo.ioFDirIndex = 0; + + /* Check for errors */ + err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); + + /* Success */ + if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10)) + { + ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\pgraf.rsrc" , permission ); + if (ret != -1) + { + ext_graf = 1; + + /* Obtain resource XXX XXX XXX */ + handle = Get1NamedResource('PICT', graf); + if ( handle == NULL || ext_graf ) + handle = GetNamedResource('PICT', "\pgraf.rsrc"); + } + } + } + } +} + #ifdef CHUUKEI /* @@ -2590,7 +3297,7 @@ static void init_chuukei( void ) char tmp[1024]; FILE *fp; - path_build(path, 1024, ANGBAND_DIR_XTRA, "chuukei.txt"); + path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "chuukei.txt"); fp = fopen(path, "r"); if(!fp) @@ -2692,7 +3399,7 @@ void SoundConfigDLog(void) for( i = 1 ; i < 7 ; i++ ) SetCheck( dialog, i+2 , soundmode[i] ); - ShowWindow(dialog); + /* ShowWindow(dialog); */ for( item_hit = 100 ; cancel < item_hit ; ){ ModalDialog(0, &item_hit); @@ -2715,6 +3422,12 @@ void SoundConfigDLog(void) /* * Exit the program */ +#if TARGET_API_MAC_CARBON +static void save_pref_file(void) +{ + cf_save_prefs(); +} +#else static void save_pref_file(void) { bool oops; @@ -2746,7 +3459,7 @@ static void save_pref_file(void) /* Find the folder */ err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder, - &vref, &dirID); + &vref, &dirID); /* Success */ if (!err) @@ -2799,6 +3512,7 @@ static void save_pref_file(void) my_fclose(fff); } } +#endif @@ -2830,7 +3544,7 @@ static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip) Rect r; /* Get the button */ - GetDialogItem(dialog, i, &type, (Handle*)&control, &r); //GetDItem(dialog, i, &type, (Handle*)&control, &r); + GetDialogItem(dialog, i, &type, (Handle*)&control, &r); /* Blink button for 1/10 second */ HiliteControl(control, 1); @@ -2848,6 +3562,189 @@ static pascal Boolean ynfilter(DialogPtr dialog, EventRecord *event, short *ip) } +#if TARGET_API_MAC_CARBON + + +#ifdef MACH_O_CARBON + +/* Carbon File Manager utilities by pelpel */ + +/* + * (Carbon) + * Convert a pathname to a corresponding FSSpec. + * Returns noErr on success. + */ +static OSErr path_to_spec(const char *path, FSSpec *spec) +{ + OSErr err; + FSRef ref; + + /* Convert pathname to FSRef ... */ + err = FSPathMakeRef(path, &ref, NULL); + if (err != noErr) return (err); + + /* ... then FSRef to FSSpec */ + err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, spec, NULL); + + /* Inform caller of success or failure */ + return (err); +} + + +/* + * (Carbon) + * Convert a FSSpec to a corresponding pathname. + * Returns noErr on success. + */ +static OSErr spec_to_path(const FSSpec *spec, char *buf, size_t size) +{ + OSErr err; + FSRef ref; + + /* Convert FSSpec to FSRef ... */ + err = FSpMakeFSRef(spec, &ref); + if (err != noErr) return (err); + + /* ... then FSRef to pathname */ + err = FSRefMakePath(&ref, buf, size); + + /* Inform caller of success or failure */ + return (err); +} + + +#endif /* MACH_O_CARBON */ + + +/* + * Prepare savefile dialogue and set the variable + * savefile accordingly. Returns true if it succeeds, false (or + * aborts) otherwise. If all is false, only allow files whose type + * is 'SAVE'. + * Originally written by Peter Ammon + */ +static bool select_savefile(bool all) +{ + OSErr err; + FSSpec theFolderSpec; + FSSpec savedGameSpec; + NavDialogOptions dialogOptions; + NavReplyRecord reply; + /* Used only when 'all' is true */ + NavTypeList types = {ANGBAND_CREATOR, 1, 1, {'SAVE'}}; + NavTypeListHandle myTypeList; + AEDesc defaultLocation; + +#ifdef MACH_O_CARBON + + /* Find the save folder */ + err = path_to_spec(ANGBAND_DIR_SAVE, &theFolderSpec); + +#else + + /* Find :lib:save: folder */ + err = FSMakeFSSpec(app_vol, app_dir, "\p:lib:save:", &theFolderSpec); + +#endif + + /* Oops */ + if (err != noErr) quit("Unable to find the folder :lib:save:"); + + /* Get default Navigator dialog options */ + err = NavGetDefaultDialogOptions(&dialogOptions); + + /* Clear preview option */ + dialogOptions.dialogOptionFlags &= ~kNavAllowPreviews; + + /* Disable multiple file selection */ + dialogOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles; + + /* Make descriptor for default location */ + err = AECreateDesc(typeFSS, &theFolderSpec, sizeof(FSSpec), + &defaultLocation); + + /* Oops */ + if (err != noErr) quit("Unable to allocate descriptor"); + + /* We are indifferent to signature and file types */ + if (all) + { + myTypeList = (NavTypeListHandle)nil; + } + + /* Set up type handle */ + else + { + err = PtrToHand(&types, (Handle *)&myTypeList, sizeof(NavTypeList)); + + /* Oops */ + if (err != noErr) quit("Error in PtrToHand. Try enlarging heap"); + + } + + /* Call NavGetFile() with the types list */ + err = NavChooseFile(&defaultLocation, &reply, &dialogOptions, NULL, + NULL, NULL, myTypeList, NULL); + + /* Free type list */ + if (!all) DisposeHandle((Handle)myTypeList); + + /* Error */ + if (err != noErr) + { + /* Nothing */ + } + + /* Invalid response -- allow the user to cancel */ + else if (!reply.validRecord) + { + /* Hack -- Fake error */ + err = -1; + } + + /* Retrieve FSSpec from the reply */ + else + { + AEKeyword theKeyword; + DescType actualType; + Size actualSize; + + /* Get a pointer to selected file */ + (void)AEGetNthPtr(&reply.selection, 1, typeFSS, &theKeyword, + &actualType, &savedGameSpec, sizeof(FSSpec), &actualSize); + + /* Dispose NavReplyRecord, resources and descriptors */ + (void)NavDisposeReply(&reply); + } + + /* Dispose location info */ + AEDisposeDesc(&defaultLocation); + + /* Error */ + if (err != noErr) return (FALSE); + +#ifdef MACH_O_CARBON + + /* Convert FSSpec to pathname and store it in variable savefile */ + (void)spec_to_path(&savedGameSpec, savefile, sizeof(savefile)); + +#else + + /* Convert FSSpec to pathname and store it in variable savefile */ + refnum_to_name( + savefile, + savedGameSpec.parID, + savedGameSpec.vRefNum, + (char *)savedGameSpec.name); + +#endif + + /* Success */ + return (TRUE); +} +#endif + + /* * Handle menu: "File" + "New" */ @@ -2873,6 +3770,28 @@ static void do_menu_file_new(void) /* * Handle menu: "File" + "Open" */ +#if TARGET_API_MAC_CARBON +static void do_menu_file_open(bool all) +{ + /* Let the player to choose savefile */ + if (!select_savefile(all)) return; + + /* Hack */ + HiliteMenu(0); + + /* Game is in progress */ + game_in_progress = TRUE; + + /* Flush input */ + flush(); + + /* Play a game */ + play_game(FALSE); + + /* Hack -- quit */ + quit(NULL); +} +#else static void do_menu_file_open(bool all) { int err; @@ -2967,6 +3886,7 @@ static void do_menu_file_open(bool all) /* Hack -- quit */ quit(NULL); } +#endif /* @@ -3026,7 +3946,8 @@ static void init_menubar(void) WindowPtr tmpw; MenuHandle m; - + OSErr err; + long response; /* Get the "apple" menu */ m = GetMenu(128); @@ -3035,11 +3956,22 @@ static void init_menubar(void) InsertMenu(m, 0); /* Add the DA's to the "apple" menu */ - AppendResMenu (m, 'DRVR'); //AddResMenu(m, 'DRVR'); - +#if TARGET_API_MAC_CARBON +#else + AppendResMenu (m, 'DRVR'); +#endif /* Get the "File" menu */ +#if TARGET_API_MAC_CARBON + m = GetMenu(129); + err = Gestalt( gestaltSystemVersion, &response ); + if ( (err == noErr) && (response >= 0x00000A00) ) + { + DeleteMenuItem( m, 7 ); + } +#else m = GetMenu(129); +#endif /* Insert the menu */ InsertMenu(m, 0); @@ -3078,7 +4010,11 @@ static void init_menubar(void) tmpw = NewWindow(0, &r, "\p", false, documentProc, 0, 0, 0); /* Activate the "fake" window */ +#if TARGET_API_MAC_CARBON + SetPortWindowPort(tmpw); +#else SetPort(tmpw); +#endif /* Default mode */ TextMode(0); @@ -3087,10 +4023,14 @@ static void init_menubar(void) TextSize(12); /* Add the fonts to the menu */ - AppendResMenu(m, 'FONT'); //AddResMenu(m, 'FONT'); + AppendResMenu(m, 'FONT'); /* Size of menu */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Scan the menu */ for (i = n; i >= 4; i--) @@ -3099,11 +4039,14 @@ static void init_menubar(void) short fontNum; /* Acquire the font name */ - /* GetMenuItemText(m, i, tmpName); */ - GetMenuItemText(m, i, tmpName); //GetItem(m, i, tmpName); + GetMenuItemText(m, i, tmpName); /* Acquire the font index */ +#if TARGET_API_MAC_CARBON + fontNum = FMGetFontFamilyFromName( tmpName ); +#else GetFNum(tmpName, &fontNum); +#endif /* Apply the font index */ TextFont(fontNum); @@ -3112,8 +4055,7 @@ static void init_menubar(void) if ((CharWidth('i') != CharWidth('W')) || (CharWidth('W') == 0)) { /* Delete the menu item XXX XXX XXX */ - /* DeleteMenuItem(m, i); */ - DeleteMenuItem (m, i); //DelMenuItem(m, i); + DeleteMenuItem (m, i); } } @@ -3124,7 +4066,7 @@ static void init_menubar(void) AppendMenu(m, "\p-"); /* Add the fonts to the menu */ - AppendResMenu (m, 'FONT'); //AddResMenu(m, 'FONT'); + AppendResMenu (m, 'FONT'); /* Make the "Size" menu */ @@ -3197,6 +4139,8 @@ static void init_menubar(void) AppendMenu(m, "\parg_wizard"); AppendMenu(m, "\p-"); AppendMenu(m, "\p¥µ¥¦¥ó¥ÉÀßÄê..."); + AppendMenu(m, "\p16X16¥°¥é¥Õ¥£¥Ã¥¯"); + AppendMenu(m, "\p£²ÇÜÉý¥¿¥¤¥ëɽ¼¨"); #else AppendMenu(m, "\parg_sound"); AppendMenu(m, "\parg_graphics"); @@ -3204,7 +4148,9 @@ static void init_menubar(void) AppendMenu(m, "\parg_fiddle"); AppendMenu(m, "\parg_wizard"); AppendMenu(m, "\p-"); - AppendMenu(m, "\psnd_setting"); + AppendMenu(m, "\pSound config"); + AppendMenu(m, "\pAdam Bolt tile"); + AppendMenu(m, "\pBigtile Mode"); #endif /* Make the "TileWidth" menu */ @@ -3288,84 +4234,136 @@ static void setup_menus(void) /* File menu */ - m = GetMenuHandle(129); //m = GetMHandle(129); + m = GetMenuHandle(129); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Enable "new"/"open..."/"import..." */ if (initialized && !game_in_progress) { +#if TARGET_API_MAC_CARBON + EnableMenuItem(m, 1); + EnableMenuItem(m, 2); + EnableMenuItem(m, 3); +#else EnableItem(m, 1); EnableItem(m, 2); EnableItem(m, 3); +#endif } /* Enable "close" */ if (initialized) { +#if TARGET_API_MAC_CARBON + EnableMenuItem(m, 4); +#else EnableItem(m, 4); +#endif } /* Enable "save" */ if (initialized && character_generated) { +#if TARGET_API_MAC_CARBON + EnableMenuItem(m, 5); +#else EnableItem(m, 5); +#endif } /* Enable "quit" */ if (TRUE) { +#if TARGET_API_MAC_CARBON + EnableMenuItem(m, 7); +#else EnableItem(m, 7); -/* EnableItem(m, 8); */ +#endif } /* Edit menu */ - m = GetMenuHandle(130); //m = GetMHandle(130); + m = GetMenuHandle(130); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Enable "edit" options if "needed" */ if (!td) { +#if TARGET_API_MAC_CARBON + EnableMenuItem(m, 1); + EnableMenuItem(m, 3); + EnableMenuItem(m, 4); + EnableMenuItem(m, 5); + EnableMenuItem(m, 6); +#else EnableItem(m, 1); EnableItem(m, 3); EnableItem(m, 4); EnableItem(m, 5); EnableItem(m, 6); +#endif } /* Font menu */ - m = GetMenuHandle(131); //m = GetMHandle(131); + m = GetMenuHandle(131); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Hack -- look cute XXX XXX */ @@ -3377,6 +4375,33 @@ static void setup_menus(void) /* Active window */ if (td) { +#if TARGET_API_MAC_CARBON + /* Enable "bold" */ + EnableMenuItem(m, 1); + + /* Enable "extend" */ + EnableMenuItem(m, 2); + + /* Check the appropriate "bold-ness" */ + if (td->font_face & bold) CheckMenuItem(m, 1, TRUE); + + /* Check the appropriate "wide-ness" */ + if (td->font_face & extend) CheckMenuItem(m, 2, TRUE); + + /* Analyze fonts */ + for (i = 4; i <= n; i++) + { + /* Enable it */ + EnableMenuItem(m, i); + + /* Analyze font */ + GetMenuItemText(m, i, s); + GetFNum(s, &value); + + /* Check active font */ + if (td->font_id == value) CheckMenuItem(m, i, TRUE); + } +#else /* Enable "bold" */ EnableItem(m, 1); @@ -3396,28 +4421,37 @@ static void setup_menus(void) EnableItem(m, i); /* Analyze font */ - /* GetMenuItemText(m,i,s); */ - GetMenuItemText(m, i, s); //GetItem(m, i, s); + GetMenuItemText(m, i, s); GetFNum(s, &value); /* Check active font */ if (td->font_id == value) CheckItem(m, i, TRUE); } +#endif } /* Size menu */ - m = GetMenuHandle(132); //m = GetMHandle(132); + m = GetMenuHandle(132); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Active window */ @@ -3426,9 +4460,20 @@ static void setup_menus(void) /* Analyze sizes */ for (i = 1; i <= n; i++) { +#if TARGET_API_MAC_CARBON /* Analyze size */ - /* GetMenuItemText(m,i,s); */ - GetMenuItemText(m, i, s); //GetItem(m, i, s); + GetMenuItemText(m, i, s); + s[s[0]+1] = '\0'; + value = atoi((char*)(s+1)); + + /* Enable the "real" sizes */ + if (RealFont(td->font_id, value)) EnableMenuItem(m, i); + + /* Check the current size */ + if (td->font_size == value) CheckMenuItem(m, i, TRUE); +#else + /* Analyze size */ + GetMenuItemText(m, i, s); s[s[0]+1] = '\0'; value = atoi((char*)(s+1)); @@ -3437,38 +4482,84 @@ static void setup_menus(void) /* Check the current size */ if (td->font_size == value) CheckItem(m, i, TRUE); +#endif } } /* Windows menu */ - m = GetMenuHandle(133); //m = GetMHandle(133); + m = GetMenuHandle(133); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Check active windows */ for (i = 1; i <= n; i++) { /* Check if needed */ +#if TARGET_API_MAC_CARBON + CheckMenuItem(m, i, data[i-1].mapped); +#else CheckItem(m, i, data[i-1].mapped); +#endif } /* Special menu */ - m = GetMenuHandle(134); //m = GetMHandle(134); + m = GetMenuHandle(134); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } +#if TARGET_API_MAC_CARBON + /* Item "arg_sound" */ + EnableMenuItem(m, 1); + CheckMenuItem(m, 1, arg_sound); + + /* Item "arg_graphics" */ + EnableMenuItem(m, 2); + CheckMenuItem(m, 2, arg_graphics); + + /* Item "arg_fiddle" */ + EnableMenuItem(m, 4); + CheckMenuItem(m, 4, arg_fiddle); + + /* Item "arg_wizard" */ + EnableMenuItem(m, 5); + CheckMenuItem(m, 5, arg_wizard); + + /* Item "SoundSetting" */ + EnableMenuItem(m, 7); + + /* Item NewStyle Graphics */ + EnableMenuItem(m, 8); + CheckMenuItem(m, 8, use_newstyle_graphics); + + /* Item Bigtile Mode */ + EnableMenuItem(m, 9); + CheckMenuItem(m, 9, arg_bigtile); +#else /* Item "arg_sound" */ EnableItem(m, 1); CheckItem(m, 1, arg_sound); @@ -3488,22 +4579,36 @@ static void setup_menus(void) /* Item "SoundSetting" */ EnableItem(m, 7); - /* Item "Hack" */ - /* EnableItem(m, 9); */ + /* Item NewStyle Graphics */ + EnableItem(m, 8); + CheckItem(m, 8, use_newstyle_graphics); + /* Item Bigtile Mode */ + EnableItem(m, 9); + CheckItem(m, 9, arg_bigtile); +#endif /* TileWidth menu */ - m = GetMenuHandle(135); //m = GetMHandle(135); + m = GetMenuHandle(135); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Active window */ @@ -3514,31 +4619,48 @@ static void setup_menus(void) { /* Analyze size */ /* GetMenuItemText(m,i,s); */ - GetMenuItemText(m, i, s); //GetItem(m, i, s); + GetMenuItemText(m, i, s); s[s[0]+1] = '\0'; value = atoi((char*)(s+1)); +#if TARGET_API_MAC_CARBON + /* Enable */ + EnableMenuItem(m, i); + + /* Check the current size */ + if (td->tile_wid == value) CheckMenuItem(m, i, TRUE); +#else /* Enable */ EnableItem(m, i); /* Check the current size */ if (td->tile_wid == value) CheckItem(m, i, TRUE); +#endif } } /* TileHeight menu */ - m = GetMenuHandle(136); //m = GetMHandle(136); + m = GetMenuHandle(136); /* Get menu size */ +#if TARGET_API_MAC_CARBON + n = CountMenuItems(m); +#else n = CountMItems(m); +#endif /* Reset menu */ for (i = 1; i <= n; i++) { /* Reset */ +#if TARGET_API_MAC_CARBON + DisableMenuItem(m, i); + CheckMenuItem(m, i, FALSE); +#else DisableItem(m, i); CheckItem(m, i, FALSE); +#endif } /* Active window */ @@ -3548,16 +4670,23 @@ static void setup_menus(void) for (i = 1; i <= n; i++) { /* Analyze size */ - /* GetMenuItemText(m,i,s); */ - GetMenuItemText(m, i, s); //GetItem(m, i, s); + GetMenuItemText(m, i, s); s[s[0]+1] = '\0'; value = atoi((char*)(s+1)); +#if TARGET_API_MAC_CARBON + /* Enable */ + EnableMenuItem(m, i); + + /* Check the current size */ + if (td->tile_hgt == value) CheckMenuItem(m, i, TRUE); +#else /* Enable */ EnableItem(m, i); /* Check the current size */ if (td->tile_hgt == value) CheckItem(m, i, TRUE); +#endif } } } @@ -3607,6 +4736,35 @@ static void menu(long mc) case 128: { /* About Angband... */ +#if TARGET_API_MAC_CARBON + if (selection == 1) + { + DialogPtr dialog; + short item_hit; + + /* Get the about dialogue */ + dialog=GetNewDialog(128, 0, (WindowPtr)-1); + + /* Move it to the middle of the screen */ + RepositionWindow( + GetDialogWindow(dialog), + NULL, + kWindowCenterOnMainScreen); + + /* Show the dialog */ + TransitionWindow(GetDialogWindow(dialog), + kWindowZoomTransitionEffect, + kWindowShowTransitionAction, + NULL); + + /* Wait for user to click on it */ + ModalDialog(0, &item_hit); + + /* Free the dialogue */ + DisposeDialog(dialog); + break; + } +#else if (selection == 1) { DialogPtr dialog; @@ -3615,20 +4773,21 @@ static void menu(long mc) dialog=GetNewDialog(128, 0, (WindowPtr)-1); - /* r=dialog->portRect; + r=dialog->portRect; center_rect(&r, &qd.screenBits.bounds); - MoveWindow(dialog, r.left, r.top, 1);*/ + MoveWindow(dialog, r.left, r.top, 1); ShowWindow(dialog); ModalDialog(0, &item_hit); - DisposeDialog(dialog); //DisposDialog(dialog); + DisposeDialog(dialog); break; } /* Desk accessory */ /* GetMenuItemText(GetMHandle(128),selection,s); */ - GetMenuItemText(GetMenuHandle(128), selection, s); //GetItem(GetMHandle(128), selection, s); + GetMenuItemText(GetMenuHandle(128), selection, s); OpenDeskAcc(s); break; +#endif } /* File Menu */ @@ -3714,7 +4873,11 @@ static void menu(long mc) msg_flag = FALSE; /* Save the game */ +#if 0 do_cmd_save_game(FALSE); +#endif + Term_key_push(SPECIAL_KEY_QUIT); + break; } /* Quit */ @@ -3799,8 +4962,7 @@ static void menu(long mc) } /* Get a new font name */ - /* GetMenuItemText(GetMHandle(131), selection, s); */ - GetMenuItemText(GetMenuHandle(131), selection, s); //GetItem(GetMHandle(131), selection, s); + GetMenuItemText(GetMenuHandle(131), selection, s); GetFNum(s, &fid); /* Save the new font id */ @@ -3862,8 +5024,7 @@ static void menu(long mc) /* Activate */ activate(td->w); - /* GetMenuItemText(GetMHandle(132), selection, s); */ - GetMenuItemText(GetMenuHandle(132), selection, s); //GetItem(GetMHandle(132), selection, s); + GetMenuItemText(GetMenuHandle(132), selection, s); s[s[0]+1]=0; td->font_size = atoi((char*)(s+1)); @@ -3934,6 +5095,12 @@ static void menu(long mc) { /* Toggle arg_graphics */ arg_graphics = !arg_graphics; + if( arg_graphics == true ){ + ANGBAND_GRAF = "old"; + arg_newstyle_graphics = false; + grafWidth = grafHeight = 8; + pictID = 1001; + } /* Hack -- Force redraw */ Term_key_push(KTRL('R')); @@ -3956,6 +5123,53 @@ static void menu(long mc) case 7: { SoundConfigDLog(); + break; + } + case 8: + { + if (streq(ANGBAND_GRAF, "old")) + { + ANGBAND_GRAF = "new"; + arg_newstyle_graphics = true; + grafWidth = grafHeight = 16; + pictID = 1002; + } + else + { + ANGBAND_GRAF = "old"; + arg_newstyle_graphics = false; + grafWidth = grafHeight = 8; + pictID = 1001; + } + + /* Hack -- Force redraw */ + Term_key_push(KTRL('R')); + break; + } + + case 9: /* bigtile mode */ + { + term_data *td = &data[0]; + + if (!can_save){ +#ifdef JP + plog("º£¤ÏÊѹ¹½ÐÍè¤Þ¤»¤ó¡£"); +#else + plog("You may not do that right now."); +#endif + break; + } + + /* Toggle "arg_bigtile" */ + arg_bigtile = !arg_bigtile; + + /* Activate */ + Term_activate(td->t); + + /* Resize the term */ + Term_resize(td->cols, td->rows); + + break; } } @@ -3974,8 +5188,7 @@ static void menu(long mc) /* Activate */ activate(td->w); - /* GetMenuItemText(GetMHandle(135), selection, s); */ - GetMenuItemText(GetMenuHandle(135), selection, s); //GetItem(GetMHandle(135), selection, s); + GetMenuItemText(GetMenuHandle(135), selection, s); s[s[0]+1]=0; td->tile_wid = atoi((char*)(s+1)); @@ -4003,8 +5216,7 @@ static void menu(long mc) /* Activate */ activate(td->w); - /* GetMenuItemText(GetMHandle(136), selection, s); */ - GetMenuItemText(GetMenuHandle(136), selection, s); //GetItem(GetMHandle(136), selection, s); + GetMenuItemText(GetMenuHandle(136), selection, s); s[s[0]+1]=0; td->tile_hgt = atoi((char*)(s+1)); @@ -4041,7 +5253,7 @@ static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent) Size actualSize; aeError = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, - &returnedType, NULL, 0, &actualSize); + &returnedType, NULL, 0, &actualSize); if (aeError == errAEDescNotFound) return (noErr); @@ -4055,7 +5267,7 @@ static OSErr CheckRequiredAEParams(const AppleEvent *theAppleEvent) * Apple Event Handler -- Open Application */ static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent, - const AppleEvent *reply, long handlerRefCon) + AppleEvent *reply, long handlerRefCon) { #pragma unused(reply, handlerRefCon) @@ -4067,15 +5279,42 @@ static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent, * Apple Event Handler -- Quit Application */ static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent, - const AppleEvent *reply, long handlerRefCon) + AppleEvent *reply, long handlerRefCon) { #pragma unused(reply, handlerRefCon) +#if TARGET_API_MAC_CARBON + + /* Save the game (if necessary) */ + if (game_in_progress && character_generated) + { + if (!can_save){ +#ifdef JP + plog("º£¤Ï¥»¡¼¥Ö¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£"); +#else + plog("You may not do that right now."); +#endif + return; + } + /* Hack -- Forget messages */ + msg_flag = FALSE; + + /* Save the game */ +#if 0 + do_cmd_save_game(FALSE); +#endif + Term_key_push(SPECIAL_KEY_QUIT); + return; + } + /* Quit */ + quit(NULL); +#else /* Quit later */ quit_when_ready = TRUE; /* Check arguments */ return (CheckRequiredAEParams(theAppleEvent)); +#endif } @@ -4083,7 +5322,7 @@ static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent, * Apple Event Handler -- Print Documents */ static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent, - const AppleEvent *reply, long handlerRefCon) + AppleEvent *reply, long handlerRefCon) { #pragma unused(theAppleEvent, reply, handlerRefCon) @@ -4105,8 +5344,8 @@ static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent, * snippet from Think Reference 2.0. (The prior sentence could read * "shamelessly swiped & hacked") */ -static pascal OSErr AEH_Open(AppleEvent *theAppleEvent, - AppleEvent* reply, long handlerRefCon) +static pascal OSErr AEH_Open(const AppleEvent *theAppleEvent, + AppleEvent* reply, long handlerRefCon) { #pragma unused(reply, handlerRefCon) @@ -4129,7 +5368,7 @@ static pascal OSErr AEH_Open(AppleEvent *theAppleEvent, */ err = AEGetNthPtr(&docList, 1L, typeFSS, &keywd, - &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize); + &returnedType, (Ptr) &myFSS, sizeof(myFSS), &actualSize); if (err) return err; /* Only needed to check savefile type below */ @@ -4192,11 +5431,11 @@ static pascal OSErr AEH_Open(AppleEvent *theAppleEvent, * F7: 98 * F3:99 * F8:100 - * F10:101 + * F10:109 * F11:103 * F13:105 * F14:107 - * F9:109 + * F9:101 * F12:111 * F15:113 * Help:114 @@ -4259,16 +5498,19 @@ static bool CheckEvents(bool wait) /* Timestamp last check */ lastTicks = curTicks; +#if TARGET_API_MAC_CARBON + WaitNextEvent( everyEvent, &event, 1L, nil ); +#else /* Let the "system" run */ SystemTask(); /* Get an event (or null) */ GetNextEvent(everyEvent, &event); +#endif /* Hack -- Nothing is ready yet */ if (event.what == nullEvent) return (FALSE); - /* Analyze the event */ switch (event.what) { @@ -4332,9 +5574,6 @@ static bool CheckEvents(bool wait) /* Hack -- Prepare the menus */ setup_menus(); - /* Mega-Hack -- allow easy exit if nothing to save */ -/* if (!character_generated && (ch=='Q' || ch=='q')) ch = 'e'; */ - /* Run the Menu-Handler */ menu(MenuKey(ch)); @@ -4356,19 +5595,6 @@ static bool CheckEvents(bool wait) Term_keypress(ch); } - /* Hack -- normal "keypad keys" -> special keypress */ - else if (!mc && !ms && !mo && !mx && (ck < 96)) - { - /* Hack -- "enter" is confused */ - if (ck == 76) ch = '\n'; - - /* Send control-caret as a trigger */ - Term_keypress(30); - - /* Send the "ascii" keypress */ - Term_keypress(ch); - } - /* Bizarre key -> encoded keypress */ else if (ck <= 127) { @@ -4421,20 +5647,27 @@ static bool CheckEvents(bool wait) HiliteMenu(0); break; } - +#if !TARGET_API_MAC_CARBON case inSysWindow: { SystemClick(&event, w); break; } +#endif case inDrag: { Point p; WindowPtr old_win; - - r = qd.screenBits.bounds; + BitMap screen; + Rect portRect; +#if TARGET_API_MAC_CARBON + GetQDGlobalsScreenBits( &screen ); +#else + screen = qd.screenBits; +#endif + r = screen.bounds; r.top += 20; /* GetMBarHeight() XXX XXX XXX */ InsetRect(&r, 4, 4); DragWindow(w, event.where, &r); @@ -4449,9 +5682,17 @@ static bool CheckEvents(bool wait) activate(td->w); /* Analyze */ - p.h = td->w->portRect.left; - p.v = td->w->portRect.top; +#if TARGET_API_MAC_CARBON + GetWindowBounds( (WindowRef)td->w, kWindowContentRgn, &portRect ); +#else + portRect = td->w->portRect; + local_to_global( &portRect ); +#endif + p.h = portRect.left; + p.v = portRect.top; +#if !TARGET_API_MAC_CARBON LocalToGlobal(&p); +#endif td->r.left = p.h; td->r.top = p.v; @@ -4487,18 +5728,24 @@ static bool CheckEvents(bool wait) case inGrow: { - int x, y; + s16b x, y; term *old = Term; - + BitMap screen; + +#if TARGET_API_MAC_CARBON + GetQDGlobalsScreenBits( &screen ); +#else + screen = qd.screenBits; +#endif /* Oops */ if (!td) break; /* Fake rectangle */ r.left = 20 * td->tile_wid + td->size_ow1; - r.right = 80 * td->tile_wid + td->size_ow1 + td->size_ow2 + 1; + r.right = screen.bounds.right; r.top = 1 * td->tile_hgt + td->size_oh1; - r.bottom = 24 * td->tile_hgt + td->size_oh1 + td->size_oh2 + 1; + r.bottom = screen.bounds.bottom; /* Grow the rectangle */ newsize = GrowWindow(w, event.where, &r); @@ -4516,7 +5763,6 @@ static bool CheckEvents(bool wait) /* Apply and Verify */ term_data_check_size(td); - /* Activate */ Term_activate(td->t); @@ -4547,6 +5793,9 @@ static bool CheckEvents(bool wait) /* Disk Event -- From "Maarten Hazewinkel" */ case diskEvt: { + +#if TARGET_API_MAC_CARBON +#else /* check for error when mounting the disk */ if (HiWord(event.message) != noErr) { @@ -4557,7 +5806,7 @@ static bool CheckEvents(bool wait) DIBadMount(p, event.message); DIUnload(); } - +#endif break; } @@ -4571,8 +5820,17 @@ static bool CheckEvents(bool wait) /* Resuming: activate the front window */ if (event.message & resumeFlag) { +#if TARGET_API_MAC_CARBON + Cursor arrow; + + SetPortWindowPort( FrontWindow() ); + + GetQDGlobalsArrow( &arrow ); + SetCursor(&arrow); +#else SetPort(FrontWindow()); SetCursor(&qd.arrow); +#endif } /* Suspend: deactivate the front window */ @@ -4592,6 +5850,9 @@ static bool CheckEvents(bool wait) /* From "Steve Linberg" and "Maarten Hazewinkel" */ case kHighLevelEvent: { +#if TARGET_API_MAC_CARBON + AEProcessAppleEvent(&event); +#else /* Process apple events */ if (AEProcessAppleEvent(&event) != noErr) { @@ -4617,6 +5878,7 @@ static bool CheckEvents(bool wait) /* Handle "open_when_ready" */ handle_open_when_ready(); +#endif break; } @@ -4809,7 +6071,15 @@ static void init_stuff(void) char path[1024]; + BitMap screen; + Rect screenRect; +#if TARGET_API_MAC_CARBON + OSErr err = noErr; + NavDialogOptions dialogOptions; + FSSpec theFolderSpec; + NavReplyRecord theReply; +#endif /* Fake rectangle */ r.left = 0; r.top = 0; @@ -4817,7 +6087,12 @@ static void init_stuff(void) r.bottom = 188; /* Center it */ - center_rect(&r, &qd.screenBits.bounds); +#if TARGET_API_MAC_CARBON + screenRect = GetQDGlobalsScreenBits(&screen)->bounds; +#else + screenRect = qd.screenBits.bounds; +#endif + center_rect(&r, &screenRect); /* Extract corner */ topleft.v = r.top; @@ -4835,32 +6110,104 @@ static void init_stuff(void) init_file_paths(path); /* Build the filename */ - #ifdef JP - path_build(path, 1024, ANGBAND_DIR_FILE, "news_j.txt"); - #else - path_build(path, 1024, ANGBAND_DIR_FILE, "news.txt"); - #endif +#ifdef JP + path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news_j.txt"); +#else + path_build(path, sizeof(path), ANGBAND_DIR_FILE, "news.txt"); +#endif /* Attempt to open and close that file */ if (0 == fd_close(fd_open(path, O_RDONLY))) break; /* Warning */ - #ifdef JP - plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path); - #else - plog_fmt("Unable to open the '%s' file.", path); - #endif +#ifdef JP + plog_fmt("'%s' ¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó½ÐÍè¤Þ¤»¤ó.", path); +#else + plog_fmt("Unable to open the '%s' file.", path); +#endif /* Warning */ - #ifdef JP - plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹."); - #else - plog("The Angband 'lib' folder is probably missing or misplaced."); - #endif +#ifdef JP + plog("Hengband¤Î'lib'¥Õ¥©¥ë¥À¤¬Â¸ºß¤·¤Ê¤¤¤«Àµ¤·¤¯Ìµ¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹."); +#else + plog("The Angband 'lib' folder is probably missing or misplaced."); +#endif /* Warning */ +#ifdef JP + plog("Please 'open' any file in any sub-folder of the 'lib' folder."); +#else plog("Please 'open' any file in any sub-folder of the 'lib' folder."); +#endif + +#if TARGET_API_MAC_CARBON + /* Ask the user to choose the lib folder */ + err = NavGetDefaultDialogOptions(&dialogOptions); + + /* Paranoia */ + if (err != noErr) quit(NULL); + + /* Set default location option */ + dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; + + /* Clear preview option */ + dialogOptions.dialogOptionFlags &= ~(kNavAllowPreviews); + + /* Forbit selection of multiple files */ + dialogOptions.dialogOptionFlags &= ~(kNavAllowMultipleFiles); + + /* Display location */ + dialogOptions.location = topleft; + + /* Load the message for the missing folder from the resource fork */ + GetIndString(dialogOptions.message, 128, 1); + /* Wait for the user to choose a folder */ + err = NavChooseFolder( + nil, + &theReply, + &dialogOptions, + nil, + nil, + nil); + + /* Assume the player doesn't want to go on */ + if ((err != noErr) || !theReply.validRecord) quit(NULL); + + /* Retrieve FSSpec from the reply */ + { + AEKeyword theKeyword; + DescType actualType; + Size actualSize; + + /* Get a pointer to selected folder */ + err = AEGetNthPtr( + &(theReply.selection), + 1, + typeFSS, + &theKeyword, + &actualType, + &theFolderSpec, + sizeof(FSSpec), + &actualSize); + + /* Paranoia */ + if (err != noErr) quit(NULL); + } + + /* Free navitagor reply */ + err = NavDisposeReply(&theReply); + + /* Paranoia */ + if (err != noErr) quit(NULL); + + /* Extract textual file name for given file */ + refnum_to_name( + path, + theFolderSpec.parID, + theFolderSpec.vRefNum, + (char *)theFolderSpec.name); +#else /* Allow "text" files */ types[0] = 'TEXT'; @@ -4879,6 +6226,7 @@ static void init_stuff(void) /* Extract textual file name for given file */ GetWDInfo(reply.vRefNum, &vrefnum, &drefnum, &junk); refnum_to_name(path, drefnum, vrefnum, (char*)reply.fName); +#endif /* Hack -- Remove the "filename" */ i = strlen(path) - 1; @@ -4904,15 +6252,18 @@ void main(void) EventRecord tempEvent; int numberOfMasters = 10; +#if !TARGET_API_MAC_CARBON /* Increase stack space by 64K */ SetApplLimit(GetApplLimit() - 131072L);//65536L); /* Stretch out the heap to full size */ MaxApplZone(); +#endif /* Get more Masters */ while (numberOfMasters--) MoreMasters(); +#if !TARGET_API_MAC_CARBON /* Set up the Macintosh */ InitGraf(&qd.thePort); InitFonts(); @@ -4920,6 +6271,7 @@ void main(void) InitMenus(); /* TEInit(); */ InitDialogs(NULL); +#endif InitCursor(); #ifdef JP @@ -5009,46 +6361,44 @@ void main(void) #endif /* ANGBAND_LITE_MAC */ + /* + * Remember Mac OS version, in case we have to cope with version-specific + * problems + */ + (void)Gestalt(gestaltSystemVersion, &mac_os_version); #ifdef USE_SFL_CODE - /* Obtain a "Universal Procedure Pointer" */ - AEH_Start_UPP = NewAEEventHandlerProc(AEH_Start); - + AEH_Start_UPP = NewAEEventHandlerUPP(AEH_Start); /* Install the hook (ignore error codes) */ AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEH_Start_UPP, - 0L, FALSE); + 0L, FALSE); /* Obtain a "Universal Procedure Pointer" */ - AEH_Quit_UPP = NewAEEventHandlerProc(AEH_Quit); - + AEH_Quit_UPP = NewAEEventHandlerUPP(AEH_Quit); /* Install the hook (ignore error codes) */ AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEH_Quit_UPP, - 0L, FALSE); + 0L, FALSE); /* Obtain a "Universal Procedure Pointer" */ - AEH_Print_UPP = NewAEEventHandlerProc(AEH_Print); - + AEH_Print_UPP = NewAEEventHandlerUPP(AEH_Print); /* Install the hook (ignore error codes) */ AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEH_Print_UPP, - 0L, FALSE); + 0L, FALSE); /* Obtain a "Universal Procedure Pointer" */ - AEH_Open_UPP = NewAEEventHandlerProc(AEH_Open); - + AEH_Open_UPP = NewAEEventHandlerUPP(AEH_Open); /* Install the hook (ignore error codes) */ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEH_Open_UPP, - 0L, FALSE); - + 0L, FALSE); #endif - /* Find the current application */ SetupAppDir(); /* Mark ourself as the file creator */ - _fcreator = 'Heng'; + _fcreator = ANGBAND_CREATOR; /* Default to saving a "text" file */ _ftype = 'TEXT'; @@ -5057,7 +6407,11 @@ void main(void) #if defined(__MWERKS__) /* Obtian a "Universal Procedure Pointer" */ +#if TARGET_API_MAC_CARBON + ynfilterUPP = NewModalFilterUPP(ynfilter); +#else ynfilterUPP = NewModalFilterProc(ynfilter); +#endif #endif @@ -5072,8 +6426,8 @@ void main(void) quit_aux = hook_quit; core_aux = hook_core; -BackColor(blackColor); - ForeColor(whiteColor); + BackColor(blackColor); + ForeColor(whiteColor); /* Show the "watch" cursor */ SetCursor(*(GetCursor(watchCursor))); @@ -5086,11 +6440,21 @@ BackColor(blackColor); init_sound(); + init_graf(); + /* Hack -- process all events */ while (CheckEvents(TRUE)) /* loop */; /* Reset the cursor */ - SetCursor(&qd.arrow); +#if TARGET_API_MAC_CARBON + { + Cursor arrow; + GetQDGlobalsArrow( &arrow ); + SetCursor(&arrow); + } +#else + SetCursor( &qd.arrow ); +#endif /* Mega-Hack -- Allocate a "lifeboat" */ @@ -5098,15 +6462,13 @@ BackColor(blackColor); /* Note the "system" */ ANGBAND_SYS = "mac"; -#if 0 - ANGBAND_GRAF = "new"; -#else - ANGBAND_GRAF = "old"; -#endif /* Initialize */ init_stuff(); + /* Catch nasty signals */ + signals_init(); + /* Initialize */ init_angband(); @@ -5127,11 +6489,11 @@ BackColor(blackColor); #endif /* Prompt the user */ - #ifdef JP +#ifdef JP prt("'¥Õ¥¡¥¤¥ë'¥á¥Ë¥å¡¼¤è¤ê'¿·µ¬'¤Þ¤¿¤Ï'³«¤¯...'¤òÁªÂò¤·¤Æ¤¯¤À¤µ¤¤¡£", 23, 10); - #else +#else prt("[Choose 'New' or 'Open' from the 'File' menu]", 23, 15); - #endif +#endif /* Flush the prompt */ Term_fresh();