home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / Flipper / Source / ImageView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.9 KB  |  146 lines

  1. #import <appkit/Application.h>
  2. #import <appkit/Button.h>
  3. #import "ImageView.h"
  4. #import <appkit/NXImage.h>
  5. #import <appkit/Control.h>
  6. #import <sys/param.h>
  7. #import <libc.h>
  8. #import <dpsclient/dpsclient.h>
  9. #import <dpsclient/wraps.h>
  10.  
  11. void nextImageHandler(DPSTimedEntry teNumber, double now, char *userData)
  12. {
  13.     [(id)userData next:nil];
  14. }
  15.  
  16. @implementation ImageView:View
  17.  
  18. /* INIT/FREE METHODS */
  19.  
  20. - initFrame:(NXRect *)frameRect;
  21. /* Init method for newly created image view. It initializes the scaling
  22.  * factors to normal. 
  23.  */
  24. {
  25.     [super initFrame:frameRect];
  26.     //[self setBackgroundGray:NX_LTGRAY];
  27.     scaleFactor.x = scaleFactor.y = 1.0;
  28.     imageList = [[List alloc] init];
  29.     period = 1;
  30.     // [[periodText setDoubleValue:1.0L] display];
  31.     // [slider takeDoubleValueFrom:periodText];
  32.     te = (DPSTimedEntry) NULL;
  33.     return self;
  34. }
  35.  
  36.    
  37. - free;
  38. /* Free the images on our way out.
  39.  */
  40. {
  41.     [imageList free];
  42.     return [super free];
  43. }
  44.  
  45.  
  46.  
  47. /* PRIVATE METHODS */
  48.  
  49.  
  50. - setListToFiles:(const char *const *) filenames
  51. {
  52.     if ([imageList count] > 0) [imageList freeObjects];
  53.     [self setDrawRotation:0.0];
  54.     scaleFactor.x = scaleFactor.y = 1.0;
  55.     [self scale:scaleFactor.x :scaleFactor.y];
  56.     while (filenames[0]) {
  57.         [self setImageToFile:filenames[0]];
  58.         [imageList addObject:image];
  59.         ++filenames;
  60.     }
  61.     image = [imageList objectAt:0];
  62.     [self display];
  63.     return self;    
  64. }
  65.  
  66. - setImageToFile:(const char *)filename;
  67. /* Find the bitmap image rep for the specified name, sets the scaling
  68.  * and rotation back to "normal" and displays new image.
  69.  */
  70. {   
  71.     NXRect extent;
  72.     
  73.     image = [[NXImage alloc] initFromFile:filename];
  74.     [image setScalable:YES];
  75.     [self getBounds:&extent];
  76.     [image setSize:&(extent.size)];
  77.     return self;
  78. }
  79.  
  80. - drawSelf:(NXRect *)rects :(int)rectCount;
  81. /* Clears the background and has the image draw itself 
  82.  */
  83. {
  84.    NXPoint  ll = {0.0,0.0};
  85.     
  86.    PSsetgray(NX_LTGRAY);
  87.    NXRectFill(&bounds);  /* to be sure to clear background */
  88.    [image composite:NX_COPY toPoint:&ll];
  89.    return self;
  90. }
  91.  
  92. - next:sender
  93. {
  94.     if ([imageList count]) {
  95.         if ([[imageList lastObject] isEqual:image])
  96.             image = [imageList objectAt:0];
  97.         else
  98.             image = [imageList objectAt:[imageList indexOf:image]+1];
  99.         [self display];
  100.     }
  101.     return self;
  102. }
  103.  
  104. - startTimer
  105. {
  106.     [periodText setDoubleValue:(1.0/period)];
  107.     te = DPSAddTimedEntry(period, 
  108.             (DPSTimedEntryProc)nextImageHandler, 
  109.             (void *)self, NX_MODALRESPTHRESHOLD);
  110.     return self;
  111. }
  112.  
  113. - stopTimer
  114. {
  115.      if ( te ) DPSRemoveTimedEntry(te);
  116.      return self;
  117. }
  118.  
  119.  
  120. - animate:sender
  121. {
  122.  
  123.     switch([[sender selectedCell] state]) {
  124.         case 0: /* Shut down animation */
  125.                 animating = NO;
  126.                 [self stopTimer];
  127.                 break;
  128.                 
  129.         case 1: /* Set up animation */
  130.                 animating = YES;
  131.                 [self startTimer];
  132.                 break;
  133.     }
  134.     return self;
  135.     
  136. }
  137.  
  138. - setSpeed:sender
  139. {
  140.     period = 1.0/[sender doubleValue];
  141.     [periodText takeDoubleValueFrom:sender];
  142.     if (animating) [[self stopTimer] startTimer];
  143.     return self;
  144. }
  145.  
  146. @end