home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Examples / InfoWow-0.00-MIHS / src / FlyingWindow.m < prev    next >
Encoding:
Text File  |  1994-03-21  |  2.0 KB  |  68 lines

  1.  
  2. #import "FlyingWindow.h"
  3.  
  4. static id contentImage = nil;
  5.  
  6. @implementation FlyingWindow
  7.  
  8. - initAt:(NXPoint *)thePoint
  9. { // set up window with image and put it on the screen centered at thePoint
  10.     NXRect theFrame; NXPoint zeroPoint = { 0.0, 0.0 };
  11.     if (!contentImage)
  12.         contentImage = [NXImage findImageNamed:"minienvelope.tiff"];
  13.     [contentImage getSize:&(theFrame.size)];
  14.     NX_X(&theFrame) = thePoint->x - NX_WIDTH(&theFrame) / 2;
  15.     NX_Y(&theFrame) = thePoint->y - NX_HEIGHT(&theFrame) / 2;
  16.     [self initContent:&theFrame style:NX_PLAINSTYLE
  17.             backing:NX_RETAINED buttonMask:0 defer:NO screen:NULL];
  18.     velocity.x = (random() % HORIZ_JUMPS) - HORIZ_JUMPS / 2;
  19.     velocity.y = (random() % VERT_JUMPS) + MIN_VERT;
  20.     [[self contentView] lockFocus];
  21.     [contentImage composite:NX_COPY toPoint:&zeroPoint];
  22.     [[self contentView] unlockFocus];
  23.     [self orderFront:nil];
  24.     return self;
  25. }
  26.  
  27. - reInitAt:(NXPoint *)thePoint
  28. { // re-init the window as above, but for already created window.
  29.     NXSize theSize;
  30.     [contentImage getSize:&theSize];
  31.     [self moveTo:(thePoint->x - theSize.width / 2)
  32.                 :(thePoint->y - theSize.height / 2)];
  33.     velocity.x = (random() % HORIZ_JUMPS) - HORIZ_JUMPS / 2;
  34.     velocity.y = (random() % VERT_JUMPS) + MIN_VERT;
  35.     [self orderFront:nil];
  36.     return self;
  37. }
  38.  
  39. - move
  40. {
  41.     NXRect theFrame;
  42.     [self getFrame:&theFrame];
  43.     [self moveTo:(NX_X(&theFrame) + velocity.x)
  44.                 :(NX_Y(&theFrame) + velocity.y)];
  45.     velocity.y -= GRAVITY;
  46.     return self;
  47. }
  48.  
  49. - (BOOL)onScreen
  50. {
  51.     NXRect theFrame; NXScreen *screen;
  52.     [self getFrame:&theFrame andScreen:&screen];
  53.     // consider us on screen if we're off the top since we'll be
  54.     // coming back down sometime
  55.     if (!screen) { // no screen returned?  Use standard screen size
  56.         if ((NX_MAXX(&theFrame) < 0) || (NX_MAXY(&theFrame) < 0) ||
  57.                 (NX_X(&theFrame) > 1120.0)) return NO;
  58.         return YES;
  59.     }
  60.     if ((NX_MAXX(&theFrame) < NX_X(&(screen->screenBounds))) ||
  61.             (NX_X(&theFrame) > NX_MAXX(&(screen->screenBounds))) ||
  62.             (NX_MAXY(&theFrame) < NX_Y(&(screen->screenBounds)))) {
  63.         return NO;
  64.     }
  65.     return YES;
  66. }
  67.  
  68. @end