home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-03 | 2.6 KB | 111 lines | [TEXT/CWIE] |
- /*
- BSD VBL Example v1.0
- Created by Scott Dunbar
- 8/3/97
- */
-
- // GWorld & Copybits routines (not included)
- #include <BSDOffscreenLib.h>
-
- // VBL routines
- #include <BSDVBLLib.h>
-
- // Menubar routines (not included)
- #include <BSDMenubarLib.h>
-
- WindowPtr window; // the main window
- GWorldPtr offscreen; // the GWorld that will hold the picture
- PicHandle pic; // a picture of the BuggySoft Development logo :)
- Rect bounds, // the GWorld bounds
- dest; // the destination rect to draw to
- short horz = 1, // move right
- vert = 1; // and down initially
-
- void main (void) {
- // initialize MacOS routines and max our app zone
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
- TEInit();
- MaxApplZone();
-
- // load our picture and lock it down
- pic = GetPicture(128);
- HLock((Handle)pic);
-
- // setup a few rects
- Rect r = bounds = (*pic)->picFrame;
- bounds.right += 2;
- bounds.bottom += 2;
- dest = bounds;
- OffsetRect(&r, 1, 1);
-
- // create the GWorld
- offscreen = CreateGWorld(0, bounds, nil, nil, 0, nil, none);
-
- // open the GWorld and draw the logo into it
- OpenGWorld(offscreen);
- PaintRect(&offscreen->portRect);
- DrawPicture(pic, &r);
- CloseGWorld();
-
- // unlock and release the pict resource
- HUnlock((Handle)pic);
- ReleaseResource((Handle)pic);
-
- // hide the cursor and menubar
- HideCursor();
- HideMenuBar();
-
- // make a full-screen window and paint it black
- window = NewCWindow(nil, &qd.screenBits.bounds, "\p", true, plainDBox, (WindowPtr)-1L, false, 0);
- SetPort(window);
- PaintRect(&window->portRect);
-
- // initialize the VBL library
- InitVBLLib();
-
- // loop until the mouse button is pressed
- while (!Button()) {
-
- // check vblUpdate
- if (vblUpdate) {
-
- // move the logo's dest rect a little bit
- OffsetRect(&dest, horz, vert);
-
- // check to see if we hit the edge of the screen and bounce back the other way
- if (dest.left <= -1) horz = -horz;
- if (dest.top <= -1) vert = -vert;
- if (dest.right >= (window->portRect.right + 1)) horz = -horz;
- if (dest.bottom >= (window->portRect.bottom + 1)) vert = -vert;
-
- // draw to the screen
- GWorld2WindowRect(offscreen, window, offscreen->portRect, dest, srcCopy);
- }
- }
-
- // wait for the user to release the mouse button (cleaner feeling :)
- while (Button());
-
- // dispose of the VBL library
- DisposeVBLLib();
-
- // show the cursor and menubar
- ShowMenuBar();
- ShowCursor();
-
- // dispose our GWorld and window
- DisposeGWorld(offscreen);
- DisposeWindow(window);
-
- // flush out those nasty little mouse clicks
- FlushEvents(mDownMask + mUpMask, 0);
-
- // quit
- ExitToShell();
- }
-