home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / Astro / Moon / Source / MoonView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.9 KB  |  107 lines

  1. /* MoonView.m
  2.  * Part of the Moon application for the NeXT computer.
  3.  * Author:  Geoffrey S. Knauth
  4.  * Date:    January 4, 1992
  5.  *
  6.  * Permission to copy this program is hereby granted under the terms
  7.  * of the Free Software Foundation's GNU General Public License.
  8.  */
  9.  
  10. #import <appkit/Application.h>        /* NXApp */
  11. #import <appkit/NXImage.h>
  12. #import <appkit/Window.h>
  13. #import "MoonView.h"
  14. #import "HugeMoonView.h"
  15. #import "all.h"
  16.  
  17. /* These measures of the moon's edges were taken manually via:
  18.  *   - mouseDown:(NXEvent *)e
  19.  *   {   NXPoint local = e->location;
  20.  *       [self convertPoint:&local fromView:nil];
  21.  *       printf("mouseDown: view coordinates %.f, %.f\n", local.x, local.y);  
  22.  *       return self;
  23.  *   }
  24.  */
  25. struct moonInfo fullMoon = {208., 16., 50., 238.};    /* FullMoon.tiff */
  26.  
  27. @implementation MoonView
  28.  
  29. - initFrame:(const NXRect *)frameRect
  30. {
  31.   /* 288, 228 --> This is the size that IB should know about. */
  32.     NXSize rectSize = {1152/4, 912/4};
  33.  
  34.     [super initFrame:frameRect];
  35.  
  36.   /* This is for the 1/4 size MoonView in the main application window. */
  37.     image = [[NXImage alloc] initFromSection:"FullMoon.tiff"];
  38.     [[image setSize:&rectSize] setScalable:YES];
  39.  
  40.   /* This is for the moon itself, that is, not the stars and space
  41.    * that make up the background.
  42.    */
  43.     xradius = (fullMoon.right - fullMoon.left) / 2.;
  44.     yradius = (fullMoon.top - fullMoon.bottom) / 2.;
  45.     center.x = fullMoon.left + xradius;
  46.     center.y = fullMoon.bottom + yradius;
  47.     [self setPhase:0.0];
  48.  
  49.     return self;
  50. }
  51.  
  52. - drawSelf :(const NXRect *)rects :(int)rectCount
  53. {
  54.   /* draw the image of the moon */
  55.     [image composite:NX_COPY toPoint:&bounds.origin];
  56.  
  57.   /* now draw the shadow over that part hidden from the sun */
  58.     DrawMoonShadow([self phase], ¢er, xradius, yradius, NX_BLACK);
  59.  
  60.     return self;
  61. }
  62.  
  63. - free
  64. {
  65.     [image free];        /* Free the 1/4 size image on our way out. */
  66.     if (hugeWindow)        /* See if full size window and image exist. */
  67.     [hugeWindow free];    /* This will also free the view and image. */
  68.     return [super free];
  69. }
  70.  
  71. - mouseDown:(NXEvent *)theEvent
  72. {
  73.     NXRect hugeRect = {{0., 0.}, {1152., 912.}};    /* full screen */
  74.  
  75.     if (theEvent->type == NX_MOUSEDOWN) {
  76.     if (theEvent->data.mouse.click > 1) {
  77.         [NXApp getNextEvent:NX_MOUSEUPMASK];    /* wait for mouse up */
  78.         if (hugeWindow == nil) {
  79.         hugeWindow = [[Window alloc] initContent:&hugeRect
  80.               style:NX_PLAINSTYLE backing:NX_RETAINED
  81.               buttonMask:0 defer:YES];
  82.         hugeMoonView = [[HugeMoonView alloc] initFrame:&hugeRect];
  83.         [hugeWindow setContentView:hugeMoonView];
  84.         }
  85.         [hugeWindow makeKeyAndOrderFront:self];
  86.         [hugeMoonView display];            /* Cheese! */
  87.         [NXApp getNextEvent:NX_MOUSEDOWNMASK];  /* absorb mouse down */
  88.         [NXApp getNextEvent:NX_MOUSEUPMASK];    /* and mouse up */
  89.         [hugeWindow orderOut:self];            /* put huge moon away */
  90.     }
  91.     }
  92.     return self;
  93. }
  94.  
  95. - (float)phase
  96. {
  97.     return phase;
  98. }
  99.  
  100. - setPhase :(float)aFloat;
  101. {
  102.     phase = aFloat;
  103.     return self;
  104. }
  105.  
  106. @end
  107.