home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / MiniExamples / ScrollTiff / TiffDocView.m < prev   
Text File  |  1991-04-21  |  2KB  |  75 lines

  1. /* 
  2.  * TiffDocView.m
  3.  *
  4.  * This file provides the code for the TiffDocView, which is the DocView of
  5.  * the ScrollView in the application's main window.    The TiffDocView must
  6.  * communicate with the image it displays, and be able to redraw itself when
  7.  * the image is scrolled.
  8.  *
  9.  * You may freely copy, distribute, and reuse the code in this example.
  10.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  11.  * fitness for any particular use.
  12.  */
  13.  
  14. #import "TiffDocView.h"
  15. #import  <appkit/NXImage.h>
  16.  
  17. @implementation TiffDocView
  18.     
  19. - drawSelf:(const NXRect *)rects :(int)rectCount
  20. {
  21.     
  22.     /* 
  23.      * "rects" is passed in to drawSelf::.    It's a pointer to an array of
  24.      * NXRects that describe the area of the TiffDocView that needs to be
  25.      * drawn.  In this case, we can use the very same NXRects to describe the
  26.      * area of the image that must be composited in to the TiffDocView,
  27.      * because:
  28.      *
  29.      * 1.) the NXImage and the TiffDocView are in the same coordinate system,
  30.      * and  
  31.      *
  32.      * 2.) we want to render the rect at the same coordinates that it occupies
  33.      * in the source image. 
  34.      *
  35.      * Since we're only expecting one rect to be modified by a scrolling
  36.      * operation, "rects" actually is a pointer to the one we want.
  37.      * 
  38.      * The composite method requires pointers for its arguments, so we leave
  39.      * "rects" as a pointer and take the address of its origin coordinates.
  40.      */
  41.      [docImage composite:NX_SOVER fromRect:rects toPoint: &rects->origin];
  42.      return self;
  43. }
  44.     
  45.     
  46.  
  47. /* Read in image data from a file */
  48.  
  49. - readImageFile:(const char *)imageFile
  50. {
  51.     NXSize            imSize;
  52.  
  53.     /* Remove old NXImage if there is one */
  54.     if (docImage != nil)
  55.     {
  56.            [docImage free];
  57.     }
  58.     
  59.     /* Allocate, initialize, and load a new NXImage */
  60.     docImage = [[NXImage alloc] initFromFile: imageFile];    
  61.     
  62.     /* Find out how big the image is */
  63.     [docImage getSize: &imSize];
  64.     
  65.     /* ...and size the TiffDocView to fit. */
  66.     [self  sizeTo: imSize.width : imSize.height];
  67.     
  68.     /* Invoke drawSelf:, as defined above */
  69.     [self display];
  70.     
  71.     return self;
  72. }
  73.  
  74. @end
  75.