home *** CD-ROM | disk | FTP | other *** search
/ Altsys Virtuoso 2.0K / virtuoso_20k.iso / DemoApps / Graphics / Multimedia / Movie / Source / MovieApp.update / MovieView.m < prev    next >
Encoding:
Text File  |  1992-10-01  |  1.7 KB  |  76 lines

  1. #import "MovieView.h"
  2. #import "MovieApp.h"
  3. #import <appkit/NXImage.h>
  4. #import <appkit/nextstd.h>
  5. #import <appkit/Panel.h>
  6. #import <appkit/Window.h>
  7. #import <objc/List.h>
  8. #import <streams/streams.h>
  9.  
  10. @implementation MovieView
  11.  
  12. /* creates a new MovieView instance */
  13. + newPath:(const char *)thePath Width:(int)w Height:(int)h NumFrames:(int)nf
  14. {
  15.     self = [super new];
  16.     path = malloc(strlen(thePath));
  17.     strcpy(path, thePath);
  18.     width = w;
  19.     height = h;
  20.     currentFrame = 0;
  21.     numFrames = nf;
  22.     frames = calloc(numFrames, sizeof(id));
  23.     return self;
  24. }
  25.  
  26. /* show a frame, load it if necessary */
  27. - showFrameNumber:(int)frameNumber
  28. {
  29.     NXStream       *theStream;
  30.     NXPoint         zeroPoint = {0, 0};
  31.     char            tempPath[128];
  32.  
  33.     if (frames[frameNumber] == NULL) {
  34.         strcpy(tempPath, path);
  35.         if(filetype == 1) sprintf(&tempPath[strlen(tempPath)], "/%d.tiff", frameNumber);
  36.         if(filetype == 2) sprintf(&tempPath[strlen(tempPath)], "/%d.eps", frameNumber);
  37.         if(filetype == 0){
  38.             NXRunAlertPanel("Error","Unsupported file type!","OK",NULL,NULL);
  39.             [window close];
  40.             return self;
  41.         }
  42.         frames[frameNumber] = [[NXImage alloc] initFromFile:tempPath];
  43.         if (frames[frameNumber] == NULL) {
  44.             NXRunAlertPanel("Error", "Frame %d not found.",
  45.                     "OK", NULL, NULL, frameNumber);
  46.             [window close];
  47.             return self;
  48.         }
  49.     }
  50.     currentFrame = frameNumber;
  51.     [self lockFocus];
  52.     [frames[currentFrame] composite:NX_COPY toPoint:&zeroPoint];
  53.     [self unlockFocus];
  54.     return self;
  55. }
  56.  
  57. /* respond to inquiries */
  58. - (int)numFrames
  59. { return numFrames; }
  60. - (int)currentFrame
  61. { return currentFrame; }
  62.  
  63. /* clean up */
  64. - free
  65. {
  66.     int             i;
  67.     for (i = 0; i < numFrames; i++)
  68.         if (frames[i])
  69.             [frames[i] free];
  70.     free(frames);
  71.     free(path);
  72.     return[super free];
  73. }
  74.  
  75. @end
  76.