home *** CD-ROM | disk | FTP | other *** search
- #include <BSDSoundLib.h>
- #include <AntiAliasLib.h>
-
- Handle snd;
- StringHandle fontName;
- short refNum, oldResFile, fontNum;
- StandardFileReply file;
- WindowPtr window, whichWindow;
- Boolean done = false;
- EventRecord event;
- GrafPtr oldPort;
-
- void main (void);
- Boolean OpenSndFile (StandardFileReply *reply, short *refNum);
- void SetFontSizeStyle (short fontnum, short fontsize, short fontstyle) ;
- void Ellipsize (Str255 s, short width);
- void CenterString (Rect r, Str255 s) ;
- void EventLoop (void);
-
- void Ellipsize (Str255 s, short width) {
- char len;
- short newwidth;
-
- if ((newwidth = StringWidth (s)) <= width)
- return;
- len = s [0];
- width -= CharWidth ('…');
- do {
- newwidth -= CharWidth (s [len]);
- --len;
- } while ((newwidth > width) && (len != 0));
- ++len;
- s [len] = '…';
- s [0] = (char) len;
- }
-
- void CenterString (Rect r, Str255 s) {
- GDHandle device;
- RGBColor whiteRGBColor = {0xFFFF,0xFFFF,0xFFFF}, grayRGBolor = {0x0000, 0x0000, 0x0000};
- short rh = r.bottom - r.top;
- short rw = r.right - r.left;
- short h, v;
- FontInfo fi;
-
- GetFontInfo (&fi);
- Ellipsize(s, rw);
- h = r.left + ((rw - StringWidth (s)) / 2);
- v = r.top + ((rh - (fi.ascent + fi.descent)) / 2) + fi.ascent;
- ClipRect (&r);
-
- GetGWorld(nil, &device);
- GetGray(device, &whiteRGBColor, &grayRGBolor);
-
- RGBForeColor(&grayRGBolor);
- MoveTo (h + 3, v + 3);
- DrawString (s);
-
- ForeColor(blackColor);
- MoveTo (h, v);
- ADrawString (s);
- }
-
- static void SetFontSizeStyle (short fontnum, short fontsize, short fontstyle) {
- TextFont (fontnum);
- TextSize (fontsize);
- TextFace (fontstyle);
- }
-
- Boolean OpenSndFile (StandardFileReply *reply, short *refNum) {
- SFTypeList typeList;
-
- typeList[0] = 'sfil';
- StandardGetFile(nil, 1, typeList, reply);
- if (reply->sfGood) {
- (*refNum) = FSpOpenResFile(&reply->sfFile, fsRdPerm);
- return(true);
- }
- return(false);
- }
-
- void main (void) {
- MaxApplZone();
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- FlushEvents(everyEvent, 0);
-
- oldResFile = CurResFile();
- if (!OpenSndFile(&file, &refNum)) ExitToShell();
-
- snd = GetIndResource('snd ', 1);
- HLockHi(snd);
- DetachResource(snd);
-
- CloseResFile(refNum);
- UseResFile(oldResFile);
-
- InitLoopingSounds();
-
- window = GetNewCWindow(128, nil, (WindowPtr)-1L);
- SetPort(window);
- ShowWindow(window);
-
- fontName = GetString(128);
- GetFNum((*fontName), &fontNum);
- DisposeHandle((Handle)fontName);
-
- SetFontSizeStyle(fontNum, 18, normal);
- CenterString(window->portRect, file.sfFile.name);
-
- PlayLoopingSound(snd);
-
- EventLoop();
-
- FlushEvents(everyEvent, 0);
-
- DisposeLoopingSounds();
-
- HUnlock(snd);
-
- DisposeWindow(window);
-
- ExitToShell();
- }
-
- void EventLoop (void) {
- while (!done) {
- WaitNextEvent(everyEvent, &event, 20, nil);
- switch (event.what) {
- case mouseDown:
- switch (FindWindow(event.where, &whichWindow)) {
- case inContent:
- if (whichWindow != FrontWindow()) SelectWindow(whichWindow);
- break;
- case inDrag:
- DragWindow(whichWindow, event.where, &qd.screenBits.bounds);
- break;
- case inSysWindow:
- SystemClick(&event, whichWindow);
- break;
- case inGoAway:
- if (whichWindow == window)
- if (TrackGoAway(whichWindow, event.where)) done = true;
- break;
- }
- break;
- case keyDown:
- if (event.modifiers & cmdKey)
- switch ((char)(event.message & charCodeMask)) {
- case 'Q':
- case 'q':
- case 'w':
- case 'W':
- case '.':
- done = true;
- return;
- }
- break;
- case updateEvt:
- BeginUpdate((WindowPtr)event.message);
- if ((WindowPtr)event.message == window) {
- GetPort(&oldPort);
- SetPort(window);
- CenterString(window->portRect, file.sfFile.name);
- SetPort(oldPort);
- }
- EndUpdate((WindowPtr)event.message);
- break;
- default:
- break;
- }
- }
- }