--- np2/macosx/np2opening.cpp 2003/10/31 16:55:06 1.1 +++ np2/macosx/np2opening.cpp 2003/11/03 10:19:43 1.2 @@ -11,38 +11,63 @@ #include "np2.h" #include "np2opening.h" -void openingNP2(void) { - Rect srt; - GrafPtr port; - CFURLRef openingURL; - char buffer[1024]; - FSRef fsr; - FSSpec fsc; - PicHandle pict; + + +static PicHandle getbmp(FSSpec fsc, Rect* srt) { + PicHandle pict = NULL; GraphicsImportComponent gi; - GetPort(&port); - SetPortWindowPort(hWndMain); + if (!GetGraphicsImporterForFile(&fsc, &gi)) { + if (!GraphicsImportGetNaturalBounds(gi, srt)) { + OffsetRect( srt, -(*srt).left, -(*srt).top); + GraphicsImportSetBoundsRect(gi, srt); + GraphicsImportGetAsPicture(gi, &pict); + } + CloseComponent(gi); + } + return pict; +} - openingURL=CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("nekop2"), CFSTR("bmp"), NULL); - if (openingURL) { - if (CFURLGetFSRef(openingURL, &fsr)) { - FSPathMakeRef((const UInt8*)buffer, &fsr, NULL); +PicHandle getBMPfromPath(char* path, Rect* srt) { + + Str255 fname; + FSSpec fsc; + + mkstr255(fname, path); + FSMakeFSSpec(0, 0, fname, &fsc); + return(getbmp(fsc, srt)); +} + +PicHandle getBMPfromResource(const char* name, Rect* srt) { + CFURLRef url = NULL; + FSRef fsr; + FSSpec fsc; + PicHandle pict = NULL; + + url=CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTRj(name), CFSTR("bmp"), NULL); + if (url) { + if (CFURLGetFSRef(url, &fsr)) { FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, &fsc, NULL); - if (!GetGraphicsImporterForFile(&fsc, &gi)) { - if (!GraphicsImportGetNaturalBounds(gi, &srt)) { - OffsetRect( &srt, -srt.left, -srt.top); - GraphicsImportSetBoundsRect(gi, &srt); - GraphicsImportGetAsPicture(gi, &pict); - OffsetRect(&srt, (640-srt.right)/2, (400-srt.bottom)/2); - DrawPicture(pict,&srt); - QDFlushPortBuffer(GetWindowPort(hWndMain), NULL); - KillPicture(pict); - } - CloseComponent(gi); - } + pict = getbmp(fsc, srt); } - CFRelease(openingURL); + CFRelease(url); + } + return(pict); +} + +void openingNP2(void) { + Rect srt; + GrafPtr port; + PicHandle pict = NULL; + + pict = getBMPfromResource("nekop2", &srt); + if (pict) { + GetPort(&port); + SetPortWindowPort(hWndMain); + OffsetRect(&srt, (640-srt.right)/2, (400-srt.bottom)/2); + DrawPicture(pict,&srt); + QDFlushPortBuffer(GetWindowPort(hWndMain), NULL); + SetPort(port); + KillPicture(pict); } - SetPort(port); }